~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

first cut at merge from integration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
"""UI tests for the test framework."""
17
17
 
18
 
import sys
19
 
 
20
18
import bzrlib
21
 
from bzrlib.errors import ParamikoNotPresent
22
19
from bzrlib.tests import (
23
20
                          TestCase,
24
21
                          TestCaseInTempDir,
25
22
                          TestSkipped,
26
23
                          )
27
 
from bzrlib.tests.blackbox import ExternalBase
28
24
 
29
25
 
30
26
class TestOptions(TestCase):
34
30
    def test_transport_set_to_sftp(self):
35
31
        # test the --transport option has taken effect from within the
36
32
        # test_transport test
37
 
        try:
38
 
            import bzrlib.transport.sftp
39
 
        except ParamikoNotPresent:
40
 
            raise TestSkipped("Paramiko not present")
 
33
        import bzrlib.transport.sftp
41
34
        if TestOptions.current_test != "test_transport_set_to_sftp":
42
35
            return
43
36
        self.assertEqual(bzrlib.transport.sftp.SFTPAbsoluteServer,
54
47
 
55
48
    def test_transport(self):
56
49
        # test that --transport=sftp works
57
 
        try:
58
 
            import bzrlib.transport.sftp
59
 
        except ParamikoNotPresent:
60
 
            raise TestSkipped("Paramiko not present")
 
50
        # FIXME RBC 20060123 this should raise TestSkipped if sftp is not
 
51
        # available.
61
52
        old_transport = bzrlib.tests.default_transport
62
53
        old_root = TestCaseInTempDir.TEST_ROOT
63
54
        TestCaseInTempDir.TEST_ROOT = None
76
67
            bzrlib.tests.default_transport = old_transport
77
68
            TestOptions.current_test = None
78
69
            TestCaseInTempDir.TEST_ROOT = old_root
79
 
 
80
 
    def test_benchmark_runs_benchmark_tests(self):
81
 
        """bzr selftest --benchmark should not run the default test suite."""
82
 
        # We test this by passing a regression test name to --benchmark, which
83
 
        # should result in 0 rests run.
84
 
        out, err = self.run_bzr('selftest', '--benchmark', 'workingtree_implementations')
85
 
        self.assertContainsRe(out, 'Ran 0 tests.*\n\nOK')
86
 
        self.assertEqual(
87
 
            'running tests...\ntests passed\n',
88
 
            err)
89
 
        
90
 
 
91
 
class TestRunBzr(ExternalBase):
92
 
 
93
 
    def run_bzr_captured(self, argv, retcode=0, encoding=None, stdin=None):
94
 
        self.stdin = stdin
95
 
 
96
 
    def test_stdin(self):
97
 
        # test that the stdin keyword to run_bzr is passed through to
98
 
        # run_bzr_captured as-is. We do this by overriding
99
 
        # run_bzr_captured in this class, and then calling run_bzr,
100
 
        # which is a convenience function for run_bzr_captured, so 
101
 
        # should invoke it.
102
 
        self.run_bzr('foo', 'bar', stdin='gam')
103
 
        self.assertEqual('gam', self.stdin)
104
 
        self.run_bzr('foo', 'bar', stdin='zippy')
105
 
        self.assertEqual('zippy', self.stdin)
106
 
 
107
 
 
108
 
class TestRunBzrCaptured(ExternalBase):
109
 
 
110
 
    def apply_redirected(self, stdin=None, stdout=None, stderr=None,
111
 
                         a_callable=None, *args, **kwargs):
112
 
        self.stdin = stdin
113
 
        self.factory_stdin = getattr(bzrlib.ui.ui_factory, "stdin", None)
114
 
        self.factory = bzrlib.ui.ui_factory
115
 
        stdout.write('foo\n')
116
 
        stderr.write('bar\n')
117
 
        return 0
118
 
 
119
 
    def test_stdin(self):
120
 
        # test that the stdin keyword to run_bzr_captured is passed through to
121
 
        # apply_redirected as a StringIO. We do this by overriding
122
 
        # apply_redirected in this class, and then calling run_bzr_captured,
123
 
        # which calls apply_redirected. 
124
 
        self.run_bzr_captured(['foo', 'bar'], stdin='gam')
125
 
        self.assertEqual('gam', self.stdin.read())
126
 
        self.assertTrue(self.stdin is self.factory_stdin)
127
 
        self.run_bzr_captured(['foo', 'bar'], stdin='zippy')
128
 
        self.assertEqual('zippy', self.stdin.read())
129
 
        self.assertTrue(self.stdin is self.factory_stdin)
130
 
 
131
 
    def test_ui_factory(self):
132
 
        # each invocation of self.run_bzr_captured should get its own UI
133
 
        # factory, which is an instance of TestUIFactory, with stdout and
134
 
        # stderr attached to the stdout and stderr of the invoked
135
 
        # run_bzr_captured
136
 
        current_factory = bzrlib.ui.ui_factory
137
 
        self.run_bzr_captured(['foo'])
138
 
        self.failIf(current_factory is self.factory)
139
 
        self.assertNotEqual(sys.stdout, self.factory.stdout)
140
 
        self.assertNotEqual(sys.stderr, self.factory.stderr)
141
 
        self.assertEqual('foo\n', self.factory.stdout.getvalue())
142
 
        self.assertEqual('bar\n', self.factory.stderr.getvalue())
143
 
        self.assertIsInstance(self.factory, bzrlib.tests.blackbox.TestUIFactory)