s4:dsdb/drepl: update the source_dsa_obj/invocation_id in repsFrom
[Samba/gebeck_regimport.git] / lib / testtools / testtools / tests / test_distutilscmd.py
blob59762dfd688778d5e2071cd19c8a8fef75d3988f
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 (
8 _b,
9 _u,
10 BytesIO,
12 from testtools.helpers import try_import
13 fixtures = try_import('fixtures')
15 import testtools
16 from testtools import TestCase
17 from testtools.distutilscmd import TestCommand
18 from testtools.matchers import MatchesRegex
21 if fixtures:
22 class SampleTestFixture(fixtures.Fixture):
23 """Creates testtools.runexample temporarily."""
25 def __init__(self):
26 self.package = fixtures.PythonPackage(
27 'runexample', [('__init__.py', _b("""
28 from testtools import TestCase
30 class TestFoo(TestCase):
31 def test_bar(self):
32 pass
33 def test_quux(self):
34 pass
35 def test_suite():
36 from unittest import TestLoader
37 return TestLoader().loadTestsFromName(__name__)
38 """))])
40 def setUp(self):
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):
49 def setUp(self):
50 super(TestCommandTest, self).setUp()
51 if fixtures is None:
52 self.skipTest("Need fixtures")
54 def test_test_module(self):
55 self.useFixture(SampleTestFixture())
56 stdout = self.useFixture(fixtures.StringStream('stdout'))
57 dist = Distribution()
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')
66 self.assertThat(
67 stdout.getDetails()['stdout'].as_text(),
68 MatchesRegex(_u("""Tests running...
70 Ran 2 tests in \\d.\\d\\d\\ds
72 """)))
74 def test_test_suite(self):
75 self.useFixture(SampleTestFixture())
76 stdout = self.useFixture(fixtures.StringStream('stdout'))
77 dist = Distribution()
78 dist.script_name = 'setup.py'
79 dist.script_args = ['test']
80 dist.cmdclass = {'test': TestCommand}
81 dist.command_options = {
82 'test': {
83 'test_suite': (
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')
88 self.assertThat(
89 stdout.getDetails()['stdout'].as_text(),
90 MatchesRegex(_u("""Tests running...
92 Ran 2 tests in \\d.\\d\\d\\ds
94 """)))
97 def test_suite():
98 from unittest import TestLoader
99 return TestLoader().loadTestsFromName(__name__)