509
510
self.stream = unittest._WritelnDecorator(stream)
510
511
self.descriptions = descriptions
511
512
self.verbosity = verbosity
512
self.keep_output = keep_output
513
513
self._bench_history = bench_history
514
514
self.use_numbered_dirs = use_numbered_dirs
515
515
self.list_only = list_only
576
576
for feature, count in sorted(result.unsupported.items()):
577
577
self.stream.writeln("Missing feature '%s' skipped %d tests." %
578
578
(feature, count))
579
result.report_cleaning_up()
580
# This is still a little bogus,
581
# but only a little. Folk not using our testrunner will
582
# have to delete their temp directories themselves.
583
test_root = TestCaseWithMemoryTransport.TEST_ROOT
584
if result.wasSuccessful() or not self.keep_output:
585
if test_root is not None:
586
# If LANG=C we probably have created some bogus paths
587
# which rmtree(unicode) will fail to delete
588
# so make sure we are using rmtree(str) to delete everything
589
# except on win32, where rmtree(str) will fail
590
# since it doesn't have the property of byte-stream paths
591
# (they are either ascii or mbcs)
592
if sys.platform == 'win32':
593
# make sure we are using the unicode win32 api
594
test_root = unicode(test_root)
596
test_root = test_root.encode(
597
sys.getfilesystemencoding())
598
_rmtree_temp_dir(test_root)
600
note("Failed tests working directories are in '%s'\n", test_root)
601
TestCaseWithMemoryTransport.TEST_ROOT = None
602
579
result.finished()
1603
1580
file defaults for the transport in tests, nor does it obey the command line
1604
1581
override, so tests that accidentally write to the common directory should
1584
:cvar TEST_ROOT: Directory containing all temporary directories, plus
1585
a .bzr directory that stops us ascending higher into the filesystem.
1608
1588
TEST_ROOT = None
1609
1589
_TEST_NAME = 'test'
1612
1591
def __init__(self, methodName='runTest'):
1613
1592
# allow test parameterisation after test construction and before test
1614
1593
# execution. Variables that the parameteriser sets need to be
1765
1744
def _make_test_root(self):
1766
1745
if TestCaseWithMemoryTransport.TEST_ROOT is not None:
1770
root = u'test%04d.tmp' % i
1774
if e.errno == errno.EEXIST:
1779
# successfully created
1780
TestCaseWithMemoryTransport.TEST_ROOT = osutils.abspath(root)
1747
root = tempfile.mkdtemp(prefix='testbzr-', suffix='.tmp')
1748
TestCaseWithMemoryTransport.TEST_ROOT = root
1782
1750
# make a fake bzr directory there to prevent any tests propagating
1783
1751
# up onto the source directory's real branch
1784
bzrdir.BzrDir.create_standalone_workingtree(
1785
TestCaseWithMemoryTransport.TEST_ROOT)
1752
bzrdir.BzrDir.create_standalone_workingtree(root)
1754
# The same directory is used by all tests, and we're not specifically
1755
# told when all tests are finished. This will do.
1756
atexit.register(_rmtree_temp_dir, root)
1787
1758
def makeAndChdirToTestDir(self):
1788
1759
"""Create a temporary directories for this one test.
1862
1833
All test cases create their own directory within that. If the
1863
1834
tests complete successfully, the directory is removed.
1865
InTempDir is an old alias for FunctionalTestCase.
1836
:ivar test_base_dir: The path of the top-level directory for this
1837
test, which contains a home directory and a work directory.
1839
:ivar test_home_dir: An initially empty directory under test_base_dir
1840
which is used as $HOME for this test.
1842
:ivar test_dir: A directory under test_base_dir used as the current
1843
directory when the test proper is run.
1868
1846
OVERRIDE_PYTHON = 'python'
1882
1860
For TestCaseInTempDir we create a temporary directory based on the test
1883
1861
name and then create two subdirs - test and home under it.
1885
if self.use_numbered_dirs: # strongly recommended on Windows
1886
# due the path length limitation (260 ch.)
1887
candidate_dir = '%s/%dK/%05d' % (self.TEST_ROOT,
1888
int(self.number/1000),
1890
os.makedirs(candidate_dir)
1891
self.test_home_dir = candidate_dir + '/home'
1892
os.mkdir(self.test_home_dir)
1893
self.test_dir = candidate_dir + '/work'
1894
os.mkdir(self.test_dir)
1895
os.chdir(self.test_dir)
1896
# put name of test inside
1897
f = file(candidate_dir + '/name', 'w')
1863
# create a directory within the top level test directory
1864
candidate_dir = tempfile.mkdtemp(dir=self.TEST_ROOT)
1865
# now create test and home directories within this dir
1866
self.test_base_dir = candidate_dir
1867
self.test_home_dir = self.test_base_dir + '/home'
1868
os.mkdir(self.test_home_dir)
1869
self.test_dir = self.test_base_dir + '/work'
1870
os.mkdir(self.test_dir)
1871
os.chdir(self.test_dir)
1872
# put name of test inside
1873
f = file(self.test_base_dir + '/name', 'w')
1898
1875
f.write(self.id())
1902
# shorten the name, to avoid test failures due to path length
1903
short_id = self.id().replace('bzrlib.tests.', '') \
1904
.replace('__main__.', '')[-100:]
1905
# it's possible the same test class is run several times for
1906
# parameterized tests, so make sure the names don't collide.
1910
candidate_dir = '%s/%s.%d' % (self.TEST_ROOT, short_id, i)
1912
candidate_dir = '%s/%s' % (self.TEST_ROOT, short_id)
1913
if os.path.exists(candidate_dir):
1917
os.mkdir(candidate_dir)
1918
self.test_home_dir = candidate_dir + '/home'
1919
os.mkdir(self.test_home_dir)
1920
self.test_dir = candidate_dir + '/work'
1921
os.mkdir(self.test_dir)
1922
os.chdir(self.test_dir)
1878
self.addCleanup(self.deleteTestDir)
1880
def deleteTestDir(self):
1881
_rmtree_temp_dir(self.test_base_dir)
1925
1883
def build_tree(self, shape, line_endings='binary', transport=None):
1926
1884
"""Build a test tree according to a pattern.
2164
2122
def run_suite(suite, name='test', verbose=False, pattern=".*",
2165
stop_on_failure=False, keep_output=False,
2123
stop_on_failure=False,
2166
2124
transport=None, lsprof_timed=None, bench_history=None,
2167
2125
matching_tests_first=None,
2168
2126
numbered_dirs=None,
2246
2202
suite = test_suite_factory()
2247
2203
return run_suite(suite, 'testbzr', verbose=verbose, pattern=pattern,
2248
stop_on_failure=stop_on_failure, keep_output=keep_output,
2204
stop_on_failure=stop_on_failure,
2249
2205
transport=transport,
2250
2206
lsprof_timed=lsprof_timed,
2251
2207
bench_history=bench_history,
2284
2240
'bzrlib.tests.test_counted_lock',
2285
2241
'bzrlib.tests.test_decorators',
2286
2242
'bzrlib.tests.test_delta',
2243
'bzrlib.tests.test_deprecated_graph',
2287
2244
'bzrlib.tests.test_diff',
2288
2245
'bzrlib.tests.test_dirstate',
2289
2246
'bzrlib.tests.test_errors',
2303
2260
'bzrlib.tests.test_https_ca_bundle',
2304
2261
'bzrlib.tests.test_identitymap',
2305
2262
'bzrlib.tests.test_ignores',
2263
'bzrlib.tests.test_info',
2306
2264
'bzrlib.tests.test_inv',
2307
2265
'bzrlib.tests.test_knit',
2308
2266
'bzrlib.tests.test_lazy_import',
2310
2268
'bzrlib.tests.test_lockdir',
2311
2269
'bzrlib.tests.test_lockable_files',
2312
2270
'bzrlib.tests.test_log',
2271
'bzrlib.tests.test_lsprof',
2313
2272
'bzrlib.tests.test_memorytree',
2314
2273
'bzrlib.tests.test_merge',
2315
2274
'bzrlib.tests.test_merge3',
2423
2382
def _rmtree_temp_dir(dirname):
2383
# If LANG=C we probably have created some bogus paths
2384
# which rmtree(unicode) will fail to delete
2385
# so make sure we are using rmtree(str) to delete everything
2386
# except on win32, where rmtree(str) will fail
2387
# since it doesn't have the property of byte-stream paths
2388
# (they are either ascii or mbcs)
2389
if sys.platform == 'win32':
2390
# make sure we are using the unicode win32 api
2391
dirname = unicode(dirname)
2393
dirname = dirname.encode(sys.getfilesystemencoding())
2425
2395
osutils.rmtree(dirname)
2426
2396
except OSError, e: