507
508
self.stream = unittest._WritelnDecorator(stream)
508
509
self.descriptions = descriptions
509
510
self.verbosity = verbosity
510
self.keep_output = keep_output
511
511
self._bench_history = bench_history
512
512
self.use_numbered_dirs = use_numbered_dirs
513
513
self.list_only = list_only
574
574
for feature, count in sorted(result.unsupported.items()):
575
575
self.stream.writeln("Missing feature '%s' skipped %d tests." %
576
576
(feature, count))
577
result.report_cleaning_up()
578
# This is still a little bogus,
579
# but only a little. Folk not using our testrunner will
580
# have to delete their temp directories themselves.
581
test_root = TestCaseWithMemoryTransport.TEST_ROOT
582
if result.wasSuccessful() or not self.keep_output:
583
if test_root is not None:
584
# If LANG=C we probably have created some bogus paths
585
# which rmtree(unicode) will fail to delete
586
# so make sure we are using rmtree(str) to delete everything
587
# except on win32, where rmtree(str) will fail
588
# since it doesn't have the property of byte-stream paths
589
# (they are either ascii or mbcs)
590
if sys.platform == 'win32':
591
# make sure we are using the unicode win32 api
592
test_root = unicode(test_root)
594
test_root = test_root.encode(
595
sys.getfilesystemencoding())
596
_rmtree_temp_dir(test_root)
598
note("Failed tests working directories are in '%s'\n", test_root)
599
TestCaseWithMemoryTransport.TEST_ROOT = None
600
577
result.finished()
1600
1578
file defaults for the transport in tests, nor does it obey the command line
1601
1579
override, so tests that accidentally write to the common directory should
1582
:cvar TEST_ROOT: Directory containing all temporary directories, plus
1583
a .bzr directory that stops us ascending higher into the filesystem.
1605
1586
TEST_ROOT = None
1606
1587
_TEST_NAME = 'test'
1609
1589
def __init__(self, methodName='runTest'):
1610
1590
# allow test parameterisation after test construction and before test
1611
1591
# execution. Variables that the parameteriser sets need to be
1762
1742
def _make_test_root(self):
1763
1743
if TestCaseWithMemoryTransport.TEST_ROOT is not None:
1767
root = u'test%04d.tmp' % i
1771
if e.errno == errno.EEXIST:
1776
# successfully created
1777
TestCaseWithMemoryTransport.TEST_ROOT = osutils.abspath(root)
1745
root = tempfile.mkdtemp(prefix='testbzr-', suffix='.tmp')
1746
TestCaseWithMemoryTransport.TEST_ROOT = root
1779
1748
# make a fake bzr directory there to prevent any tests propagating
1780
1749
# up onto the source directory's real branch
1781
bzrdir.BzrDir.create_standalone_workingtree(
1782
TestCaseWithMemoryTransport.TEST_ROOT)
1750
bzrdir.BzrDir.create_standalone_workingtree(root)
1752
# The same directory is used by all tests, and we're not specifically
1753
# told when all tests are finished. This will do.
1754
atexit.register(_rmtree_temp_dir, root)
1784
1756
def makeAndChdirToTestDir(self):
1785
1757
"""Create a temporary directories for this one test.
1859
1831
All test cases create their own directory within that. If the
1860
1832
tests complete successfully, the directory is removed.
1862
InTempDir is an old alias for FunctionalTestCase.
1834
:ivar test_base_dir: The path of the top-level directory for this
1835
test, which contains a home directory and a work directory.
1837
:ivar test_home_dir: An initially empty directory under test_base_dir
1838
which is used as $HOME for this test.
1840
:ivar test_dir: A directory under test_base_dir used as the current
1841
directory when the test proper is run.
1865
1844
OVERRIDE_PYTHON = 'python'
1879
1858
For TestCaseInTempDir we create a temporary directory based on the test
1880
1859
name and then create two subdirs - test and home under it.
1882
if self.use_numbered_dirs: # strongly recommended on Windows
1883
# due the path length limitation (260 ch.)
1884
candidate_dir = '%s/%dK/%05d' % (self.TEST_ROOT,
1885
int(self.number/1000),
1887
os.makedirs(candidate_dir)
1888
self.test_home_dir = candidate_dir + '/home'
1889
os.mkdir(self.test_home_dir)
1890
self.test_dir = candidate_dir + '/work'
1891
os.mkdir(self.test_dir)
1892
os.chdir(self.test_dir)
1893
# put name of test inside
1894
f = file(candidate_dir + '/name', 'w')
1861
# create a directory within the top level test directory
1862
candidate_dir = tempfile.mkdtemp(dir=self.TEST_ROOT)
1863
# now create test and home directories within this dir
1864
self.test_base_dir = candidate_dir
1865
self.test_home_dir = self.test_base_dir + '/home'
1866
os.mkdir(self.test_home_dir)
1867
self.test_dir = self.test_base_dir + '/work'
1868
os.mkdir(self.test_dir)
1869
os.chdir(self.test_dir)
1870
# put name of test inside
1871
f = file(self.test_base_dir + '/name', 'w')
1895
1873
f.write(self.id())
1899
# shorten the name, to avoid test failures due to path length
1900
short_id = self.id().replace('bzrlib.tests.', '') \
1901
.replace('__main__.', '')[-100:]
1902
# it's possible the same test class is run several times for
1903
# parameterized tests, so make sure the names don't collide.
1907
candidate_dir = '%s/%s.%d' % (self.TEST_ROOT, short_id, i)
1909
candidate_dir = '%s/%s' % (self.TEST_ROOT, short_id)
1910
if os.path.exists(candidate_dir):
1914
os.mkdir(candidate_dir)
1915
self.test_home_dir = candidate_dir + '/home'
1916
os.mkdir(self.test_home_dir)
1917
self.test_dir = candidate_dir + '/work'
1918
os.mkdir(self.test_dir)
1919
os.chdir(self.test_dir)
1876
self.addCleanup(self.deleteTestDir)
1878
def deleteTestDir(self):
1879
_rmtree_temp_dir(self.test_base_dir)
1922
1881
def build_tree(self, shape, line_endings='binary', transport=None):
1923
1882
"""Build a test tree according to a pattern.
2161
2120
def run_suite(suite, name='test', verbose=False, pattern=".*",
2162
stop_on_failure=False, keep_output=False,
2121
stop_on_failure=False,
2163
2122
transport=None, lsprof_timed=None, bench_history=None,
2164
2123
matching_tests_first=None,
2165
2124
numbered_dirs=None,
2243
2200
suite = test_suite_factory()
2244
2201
return run_suite(suite, 'testbzr', verbose=verbose, pattern=pattern,
2245
stop_on_failure=stop_on_failure, keep_output=keep_output,
2202
stop_on_failure=stop_on_failure,
2246
2203
transport=transport,
2247
2204
lsprof_timed=lsprof_timed,
2248
2205
bench_history=bench_history,
2268
2225
'bzrlib.tests.test_atomicfile',
2269
2226
'bzrlib.tests.test_bad_files',
2270
2227
'bzrlib.tests.test_branch',
2228
'bzrlib.tests.test_branchbuilder',
2271
2229
'bzrlib.tests.test_bugtracker',
2272
2230
'bzrlib.tests.test_bundle',
2273
2231
'bzrlib.tests.test_bzrdir',
2280
2238
'bzrlib.tests.test_counted_lock',
2281
2239
'bzrlib.tests.test_decorators',
2282
2240
'bzrlib.tests.test_delta',
2241
'bzrlib.tests.test_deprecated_graph',
2283
2242
'bzrlib.tests.test_diff',
2284
2243
'bzrlib.tests.test_dirstate',
2285
2244
'bzrlib.tests.test_errors',
2299
2258
'bzrlib.tests.test_https_ca_bundle',
2300
2259
'bzrlib.tests.test_identitymap',
2301
2260
'bzrlib.tests.test_ignores',
2261
'bzrlib.tests.test_info',
2302
2262
'bzrlib.tests.test_inv',
2303
2263
'bzrlib.tests.test_knit',
2304
2264
'bzrlib.tests.test_lazy_import',
2339
2299
'bzrlib.tests.test_smart',
2340
2300
'bzrlib.tests.test_smart_add',
2341
2301
'bzrlib.tests.test_smart_transport',
2302
'bzrlib.tests.test_smtp_connection',
2342
2303
'bzrlib.tests.test_source',
2343
2304
'bzrlib.tests.test_ssh_transport',
2344
2305
'bzrlib.tests.test_status',
2420
2381
def _rmtree_temp_dir(dirname):
2382
# If LANG=C we probably have created some bogus paths
2383
# which rmtree(unicode) will fail to delete
2384
# so make sure we are using rmtree(str) to delete everything
2385
# except on win32, where rmtree(str) will fail
2386
# since it doesn't have the property of byte-stream paths
2387
# (they are either ascii or mbcs)
2388
if sys.platform == 'win32':
2389
# make sure we are using the unicode win32 api
2390
dirname = unicode(dirname)
2392
dirname = dirname.encode(sys.getfilesystemencoding())
2422
2394
osutils.rmtree(dirname)
2423
2395
except OSError, e: