~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/__init__.py

  • Committer: Martin Pool
  • Date: 2005-08-30 05:30:43 UTC
  • Revision ID: mbp@sourcefrog.net-20050830053042-58932432ee958d1e
- make get_parent() be a method of Branch; add simple tests for it

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import tempfile
21
21
import os
22
22
import sys
23
 
import errno
24
23
import subprocess
25
 
import shutil
26
24
 
27
 
import testsweet
 
25
from testsweet import run_suite
28
26
import bzrlib.commands
29
27
 
30
28
import bzrlib.trace
76
74
        
77
75
        self._log_file_name = name
78
76
 
 
77
        
79
78
    def tearDown(self):
80
79
        logging.getLogger('').removeHandler(self._log_hdlr)
81
80
        bzrlib.trace.enable_default_logging()
83
82
        self._log_file.close()
84
83
        unittest.TestCase.tearDown(self)
85
84
 
 
85
 
86
86
    def log(self, *args):
87
87
        logging.debug(*args)
88
88
 
105
105
                                       bzrlib.commands.run_bzr, args)
106
106
        self.assertEquals(result, retcode)
107
107
        
108
 
        
109
108
    def check_inventory_shape(self, inv, shape):
110
109
        """
111
110
        Compare an inventory to a list of expected names.
138
137
        if stdin is None:
139
138
            stdin = StringIO("")
140
139
        if stdout is None:
141
 
            if hasattr(self, "_log_file"):
142
 
                stdout = self._log_file
143
 
            else:
144
 
                stdout = StringIO()
 
140
            stdout = self._log_file
145
141
        if stderr is None:
146
 
            if hasattr(self, "_log_file"):
147
 
                stderr = self._log_file
148
 
            else:
149
 
                stderr = StringIO()
 
142
            stderr = self._log_file
150
143
        real_stdin = sys.stdin
151
144
        real_stdout = sys.stdout
152
145
        real_stderr = sys.stderr
 
146
        result = None
153
147
        try:
154
148
            sys.stdout = stdout
155
149
            sys.stderr = stderr
156
150
            sys.stdin = stdin
157
 
            return a_callable(*args, **kwargs)
 
151
            result = a_callable(*args, **kwargs)
158
152
        finally:
159
153
            sys.stdout = real_stdout
160
154
            sys.stderr = real_stderr
161
155
            sys.stdin = real_stdin
 
156
        return result
162
157
 
163
158
 
164
159
BzrTestBase = TestCase
190
185
            self.fail("contents of %s not as expected")
191
186
 
192
187
    def _make_test_root(self):
 
188
        import os
 
189
        import shutil
 
190
        import tempfile
 
191
        
193
192
        if TestCaseInTempDir.TEST_ROOT is not None:
194
193
            return
195
 
        i = 0
196
 
        while True:
197
 
            root = 'test%04d.tmp' % i
198
 
            try:
199
 
                os.mkdir(root)
200
 
            except OSError, e:
201
 
                if e.errno == errno.EEXIST:
202
 
                    i += 1
203
 
                    continue
204
 
                else:
205
 
                    raise
206
 
            # successfully created
207
 
            TestCaseInTempDir.TEST_ROOT = os.path.abspath(root)
208
 
            break
 
194
        TestCaseInTempDir.TEST_ROOT = os.path.abspath(
 
195
                                 tempfile.mkdtemp(suffix='.tmp',
 
196
                                                  prefix=self._TEST_NAME + '-',
 
197
                                                  dir=os.curdir))
 
198
    
209
199
        # make a fake bzr directory there to prevent any tests propagating
210
200
        # up onto the source directory's real branch
211
201
        os.mkdir(os.path.join(TestCaseInTempDir.TEST_ROOT, '.bzr'))
299
289
 
300
290
 
301
291
def selftest(verbose=False, pattern=".*"):
302
 
    return testsweet.run_suite(test_suite(), 'testbzr', verbose=verbose, pattern=pattern)
 
292
    return run_suite(test_suite(), 'testbzr', verbose=verbose, pattern=pattern)
303
293
 
304
294
 
305
295
def test_suite():
322
312
                   'bzrlib.selftest.versioning',
323
313
                   'bzrlib.selftest.whitebox',
324
314
                   'bzrlib.selftest.testmerge3',
325
 
                   'bzrlib.selftest.testmerge',
326
315
                   'bzrlib.selftest.testhashcache',
327
316
                   'bzrlib.selftest.teststatus',
328
317
                   'bzrlib.selftest.testlog',
329
318
                   'bzrlib.selftest.blackbox',
330
319
                   'bzrlib.selftest.testrevisionnamespaces',
331
320
                   'bzrlib.selftest.testbranch',
332
 
                   'bzrlib.selftest.testremotebranch',
333
321
                   'bzrlib.selftest.testrevision',
334
322
                   'bzrlib.selftest.test_merge_core',
335
323
                   'bzrlib.selftest.test_smart_add',
336
324
                   'bzrlib.selftest.testdiff',
337
 
                   'bzrlib.selftest.test_xml',
338
 
                   'bzrlib.fetch',
339
 
                   'bzrlib.selftest.teststore',
340
 
                   'bzrlib.selftest.testgraph',
 
325
                   'bzrlib.fetch'
341
326
                   ]
342
327
 
343
328
    for m in (bzrlib.store, bzrlib.inventory, bzrlib.branch,