~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_selftest.py

  • Committer: Robert Collins
  • Date: 2009-08-23 23:20:33 UTC
  • mto: This revision was merged to the branch mainline in revision 4640.
  • Revision ID: robertc@robertcollins.net-20090823232033-bz1c16hevpt5hkem
Fix selftest tests for --transport to test each layer precisely.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
 
44
44
class TestOptions(TestCase):
45
45
 
46
 
    current_test = None
47
 
 
48
46
    def test_transport_set_to_sftp(self):
49
 
        # test the --transport option has taken effect from within the
50
 
        # test_transport test
 
47
        # Test that we can pass a transport to the selftest core - sftp
 
48
        # version.
51
49
        try:
52
50
            import bzrlib.transport.sftp
53
51
        except ParamikoNotPresent:
54
52
            raise TestSkipped("Paramiko not present")
55
 
        if TestOptions.current_test != "test_transport_set_to_sftp":
56
 
            return
 
53
        params = self.get_params_passed_to_core('selftest --transport=sftp')
57
54
        self.assertEqual(bzrlib.transport.sftp.SFTPAbsoluteServer,
58
 
                         bzrlib.tests.default_transport)
 
55
            params[1]["transport"])
59
56
 
60
57
    def test_transport_set_to_memory(self):
61
 
        # test the --transport option has taken effect from within the
62
 
        # test_transport test
 
58
        # Test that we can pass a transport to the selftest core - memory
 
59
        # version.
63
60
        import bzrlib.transport.memory
64
 
        if TestOptions.current_test != "test_transport_set_to_memory":
65
 
            return
 
61
        params = self.get_params_passed_to_core('selftest --transport=memory')
66
62
        self.assertEqual(bzrlib.transport.memory.MemoryServer,
67
 
                         bzrlib.tests.default_transport)
68
 
 
69
 
    def test_transport(self):
70
 
        # test that --transport=sftp works
71
 
        try:
72
 
            import bzrlib.transport.sftp
73
 
        except ParamikoNotPresent:
74
 
            raise TestSkipped("Paramiko not present")
75
 
        old_transport = bzrlib.tests.default_transport
76
 
        old_root = TestCaseWithMemoryTransport.TEST_ROOT
77
 
        TestCaseWithMemoryTransport.TEST_ROOT = None
78
 
        try:
79
 
            TestOptions.current_test = "test_transport_set_to_sftp"
80
 
            stdout = self.run_bzr(
81
 
                'selftest --transport=sftp test_transport_set_to_sftp')[0]
82
 
            self.assertContainsRe(stdout, 'Ran 1 test')
83
 
            self.assertEqual(old_transport, bzrlib.tests.default_transport)
84
 
 
85
 
            TestOptions.current_test = "test_transport_set_to_memory"
86
 
            stdout = self.run_bzr(
87
 
                'selftest --transport=memory test_transport_set_to_memory')[0]
88
 
            self.assertContainsRe(stdout, 'Ran 1 test')
89
 
            self.assertEqual(old_transport, bzrlib.tests.default_transport)
 
63
            params[1]["transport"])
 
64
 
 
65
    def get_params_passed_to_core(self, cmdline):
 
66
        params = []
 
67
        def selftest(*args, **kwargs):
 
68
            """Capture the arguments selftest was run with."""
 
69
            params.append((args, kwargs))
 
70
            return True
 
71
        # Yes this prevents using threads to run the test suite in parallel,
 
72
        # however we don't have a clean dependency injector for commands, 
 
73
        # and even if we did - we'd still be testing that the glue is wired
 
74
        # up correctly. XXX: TODO: Solve this testing problem.
 
75
        original_selftest = tests.selftest
 
76
        tests.selftest = selftest
 
77
        try:
 
78
            self.run_bzr(cmdline)
 
79
            return params[0]
90
80
        finally:
91
 
            bzrlib.tests.default_transport = old_transport
92
 
            TestOptions.current_test = None
93
 
            TestCaseWithMemoryTransport.TEST_ROOT = old_root
 
81
            tests.selftest = original_selftest
 
82
 
 
83
    def test_parameters_passed_to_core(self):
 
84
        params = self.get_params_passed_to_core('selftest --list-only')
 
85
        self.assertTrue("list_only" in params[1])
 
86
        params = self.get_params_passed_to_core('selftest --list-only selftest')
 
87
        self.assertTrue("list_only" in params[1])
 
88
        params = self.get_params_passed_to_core(['selftest', '--list-only',
 
89
            '--exclude', 'selftest'])
 
90
        self.assertTrue("list_only" in params[1])
 
91
        params = self.get_params_passed_to_core(['selftest', '--list-only',
 
92
            'selftest', '--randomize', 'now'])
 
93
        self.assertSubset(["list_only", "random_seed"], params[1])
94
94
 
95
95
    def test_subunit(self):
96
96
        """Passing --subunit results in subunit output."""
537
537
        finally:
538
538
            tests.selftest = original_selftest
539
539
 
540
 
    def test_parameters_passed_to_core(self):
541
 
        params = []
542
 
        def selftest(*args, **kwargs):
543
 
            """Capture the arguments selftest was run with."""
544
 
            params.append((args, kwargs))
545
 
            return True
546
 
        # Yes this prevents using threads to run the test suite in parallel,
547
 
        # however we don't have a clean dependency injector for commands, 
548
 
        # and even if we did - we'd still be testing that the glue is wired
549
 
        # up correctly. XXX: TODO: Solve this testing problem.
550
 
        original_selftest = tests.selftest
551
 
        tests.selftest = selftest
552
 
        try:
553
 
            self.run_bzr('selftest --list-only')
554
 
            self.run_bzr('selftest --list-only selftest')
555
 
            self.run_bzr(['selftest', '--list-only', '--exclude', 'selftest'])
556
 
            self.run_bzr(['selftest', '--list-only', 'selftest',
557
 
                '--randomize', 'now'])
558
 
            # list_only should have been passed in each invocation.
559
 
            self.assertTrue("list_only" in params[0][1])
560
 
            self.assertTrue("list_only" in params[1][1])
561
 
            self.assertTrue("list_only" in params[2][1])
562
 
            self.assertSubset(["list_only", "random_seed"], params[2][1])
563
 
        finally:
564
 
            tests.selftest = original_selftest
565
 
 
566
540
 
567
541
class TestSelftestWithIdList(TestCaseInTempDir):
568
542