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()
1601
1578
file defaults for the transport in tests, nor does it obey the command line
1602
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.
1606
1586
TEST_ROOT = None
1607
1587
_TEST_NAME = 'test'
1610
1589
def __init__(self, methodName='runTest'):
1611
1590
# allow test parameterisation after test construction and before test
1612
1591
# execution. Variables that the parameteriser sets need to be
1763
1742
def _make_test_root(self):
1764
1743
if TestCaseWithMemoryTransport.TEST_ROOT is not None:
1768
root = u'test%04d.tmp' % i
1772
if e.errno == errno.EEXIST:
1777
# successfully created
1778
TestCaseWithMemoryTransport.TEST_ROOT = osutils.abspath(root)
1745
root = tempfile.mkdtemp(prefix='testbzr-', suffix='.tmp')
1746
TestCaseWithMemoryTransport.TEST_ROOT = root
1780
1748
# make a fake bzr directory there to prevent any tests propagating
1781
1749
# up onto the source directory's real branch
1782
bzrdir.BzrDir.create_standalone_workingtree(
1783
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)
1785
1756
def makeAndChdirToTestDir(self):
1786
1757
"""Create a temporary directories for this one test.
1860
1831
All test cases create their own directory within that. If the
1861
1832
tests complete successfully, the directory is removed.
1863
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.
1866
1844
OVERRIDE_PYTHON = 'python'
1880
1858
For TestCaseInTempDir we create a temporary directory based on the test
1881
1859
name and then create two subdirs - test and home under it.
1883
if self.use_numbered_dirs: # strongly recommended on Windows
1884
# due the path length limitation (260 ch.)
1885
candidate_dir = '%s/%dK/%05d' % (self.TEST_ROOT,
1886
int(self.number/1000),
1888
os.makedirs(candidate_dir)
1889
self.test_home_dir = candidate_dir + '/home'
1890
os.mkdir(self.test_home_dir)
1891
self.test_dir = candidate_dir + '/work'
1892
os.mkdir(self.test_dir)
1893
os.chdir(self.test_dir)
1894
# put name of test inside
1895
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')
1896
1873
f.write(self.id())
1900
# shorten the name, to avoid test failures due to path length
1901
short_id = self.id().replace('bzrlib.tests.', '') \
1902
.replace('__main__.', '')[-100:]
1903
# it's possible the same test class is run several times for
1904
# parameterized tests, so make sure the names don't collide.
1908
candidate_dir = '%s/%s.%d' % (self.TEST_ROOT, short_id, i)
1910
candidate_dir = '%s/%s' % (self.TEST_ROOT, short_id)
1911
if os.path.exists(candidate_dir):
1915
os.mkdir(candidate_dir)
1916
self.test_home_dir = candidate_dir + '/home'
1917
os.mkdir(self.test_home_dir)
1918
self.test_dir = candidate_dir + '/work'
1919
os.mkdir(self.test_dir)
1920
os.chdir(self.test_dir)
1876
self.addCleanup(self.deleteTestDir)
1878
def deleteTestDir(self):
1879
_rmtree_temp_dir(self.test_base_dir)
1923
1881
def build_tree(self, shape, line_endings='binary', transport=None):
1924
1882
"""Build a test tree according to a pattern.
2162
2120
def run_suite(suite, name='test', verbose=False, pattern=".*",
2163
stop_on_failure=False, keep_output=False,
2121
stop_on_failure=False,
2164
2122
transport=None, lsprof_timed=None, bench_history=None,
2165
2123
matching_tests_first=None,
2166
2124
numbered_dirs=None,
2244
2200
suite = test_suite_factory()
2245
2201
return run_suite(suite, 'testbzr', verbose=verbose, pattern=pattern,
2246
stop_on_failure=stop_on_failure, keep_output=keep_output,
2202
stop_on_failure=stop_on_failure,
2247
2203
transport=transport,
2248
2204
lsprof_timed=lsprof_timed,
2249
2205
bench_history=bench_history,
2423
2379
def _rmtree_temp_dir(dirname):
2380
# If LANG=C we probably have created some bogus paths
2381
# which rmtree(unicode) will fail to delete
2382
# so make sure we are using rmtree(str) to delete everything
2383
# except on win32, where rmtree(str) will fail
2384
# since it doesn't have the property of byte-stream paths
2385
# (they are either ascii or mbcs)
2386
if sys.platform == 'win32':
2387
# make sure we are using the unicode win32 api
2388
dirname = unicode(dirname)
2390
dirname = dirname.encode(sys.getfilesystemencoding())
2425
2392
osutils.rmtree(dirname)
2426
2393
except OSError, e: