1 # Copyright (c) 2010-2011 Testtools authors. See LICENSE for details.
3 """Tests for the distutils test command logic."""
5 from distutils
.dist
import Distribution
7 from testtools
.compat
import (
12 from testtools
.helpers
import try_import
13 fixtures
= try_import('fixtures')
16 from testtools
import TestCase
17 from testtools
.distutilscmd
import TestCommand
18 from testtools
.matchers
import MatchesRegex
22 class SampleTestFixture(fixtures
.Fixture
):
23 """Creates testtools.runexample temporarily."""
26 self
.package
= fixtures
.PythonPackage(
27 'runexample', [('__init__.py', _b("""
28 from testtools import TestCase
30 class TestFoo(TestCase):
36 from unittest import TestLoader
37 return TestLoader().loadTestsFromName(__name__)
41 super(SampleTestFixture
, self
).setUp()
42 self
.useFixture(self
.package
)
43 testtools
.__path
__.append(self
.package
.base
)
44 self
.addCleanup(testtools
.__path
__.remove
, self
.package
.base
)
47 class TestCommandTest(TestCase
):
50 super(TestCommandTest
, self
).setUp()
52 self
.skipTest("Need fixtures")
54 def test_test_module(self
):
55 self
.useFixture(SampleTestFixture())
56 stdout
= self
.useFixture(fixtures
.StringStream('stdout'))
58 dist
.script_name
= 'setup.py'
59 dist
.script_args
= ['test']
60 dist
.cmdclass
= {'test': TestCommand
}
61 dist
.command_options
= {
62 'test': {'test_module': ('command line', 'testtools.runexample')}}
63 cmd
= dist
.reinitialize_command('test')
64 with fixtures
.MonkeyPatch('sys.stdout', stdout
.stream
):
65 dist
.run_command('test')
67 stdout
.getDetails()['stdout'].as_text(),
68 MatchesRegex(_u("""Tests running...
70 Ran 2 tests in \\d.\\d\\d\\ds
74 def test_test_suite(self
):
75 self
.useFixture(SampleTestFixture())
76 stdout
= self
.useFixture(fixtures
.StringStream('stdout'))
78 dist
.script_name
= 'setup.py'
79 dist
.script_args
= ['test']
80 dist
.cmdclass
= {'test': TestCommand
}
81 dist
.command_options
= {
84 'command line', 'testtools.runexample.test_suite')}}
85 cmd
= dist
.reinitialize_command('test')
86 with fixtures
.MonkeyPatch('sys.stdout', stdout
.stream
):
87 dist
.run_command('test')
89 stdout
.getDetails()['stdout'].as_text(),
90 MatchesRegex(_u("""Tests running...
92 Ran 2 tests in \\d.\\d\\d\\ds
98 from unittest
import TestLoader
99 return TestLoader().loadTestsFromName(__name__
)