107
107
filename = u'hell\u00d8'
108
108
self.build_tree_contents([(filename, 'contents of hello')])
109
self.failUnlessExists(filename)
109
self.assertPathExists(filename)
112
112
class TestClassesAvailable(tests.TestCase):
510
510
self.assertRaises(AssertionError, self.assertEqualStat,
511
511
os.lstat("foo"), os.lstat("longname"))
513
def test_failUnlessExists(self):
514
"""Deprecated failUnlessExists and failIfExists"""
515
self.applyDeprecated(
516
deprecated_in((2, 4)),
517
self.failUnlessExists, '.')
518
self.build_tree(['foo/', 'foo/bar'])
519
self.applyDeprecated(
520
deprecated_in((2, 4)),
521
self.failUnlessExists, 'foo/bar')
522
self.applyDeprecated(
523
deprecated_in((2, 4)),
524
self.failIfExists, 'foo/foo')
526
def test_assertPathExists(self):
527
self.assertPathExists('.')
528
self.build_tree(['foo/', 'foo/bar'])
529
self.assertPathExists('foo/bar')
530
self.assertPathDoesNotExist('foo/foo')
514
533
class TestTestCaseWithMemoryTransport(tests.TestCaseWithMemoryTransport):
549
568
tree = self.make_branch_and_memory_tree('dir')
550
569
# Guard against regression into MemoryTransport leaking
551
570
# files to disk instead of keeping them in memory.
552
self.failIf(osutils.lexists('dir'))
571
self.assertFalse(osutils.lexists('dir'))
553
572
self.assertIsInstance(tree, memorytree.MemoryTree)
555
574
def test_make_branch_and_memory_tree_with_format(self):
559
578
tree = self.make_branch_and_memory_tree('dir', format=format)
560
579
# Guard against regression into MemoryTransport leaking
561
580
# files to disk instead of keeping them in memory.
562
self.failIf(osutils.lexists('dir'))
581
self.assertFalse(osutils.lexists('dir'))
563
582
self.assertIsInstance(tree, memorytree.MemoryTree)
564
583
self.assertEqual(format.repository_format.__class__,
565
584
tree.branch.repository._format.__class__)
569
588
self.assertIsInstance(builder, branchbuilder.BranchBuilder)
570
589
# Guard against regression into MemoryTransport leaking
571
590
# files to disk instead of keeping them in memory.
572
self.failIf(osutils.lexists('dir'))
591
self.assertFalse(osutils.lexists('dir'))
574
593
def test_make_branch_builder_with_format(self):
575
594
# Use a repo layout that doesn't conform to a 'named' layout, to ensure
581
600
the_branch = builder.get_branch()
582
601
# Guard against regression into MemoryTransport leaking
583
602
# files to disk instead of keeping them in memory.
584
self.failIf(osutils.lexists('dir'))
603
self.assertFalse(osutils.lexists('dir'))
585
604
self.assertEqual(format.repository_format.__class__,
586
605
the_branch.repository._format.__class__)
587
606
self.assertEqual(repo_format.get_format_string(),
593
612
the_branch = builder.get_branch()
594
613
# Guard against regression into MemoryTransport leaking
595
614
# files to disk instead of keeping them in memory.
596
self.failIf(osutils.lexists('dir'))
615
self.assertFalse(osutils.lexists('dir'))
597
616
dir_format = bzrdir.format_registry.make_bzrdir('knit')
598
617
self.assertEqual(dir_format.repository_format.__class__,
599
618
the_branch.repository._format.__class__)
632
651
url2 = self.get_readonly_url('foo/bar')
633
652
t = transport.get_transport(url)
634
653
t2 = transport.get_transport(url2)
635
self.failUnless(isinstance(t, ReadonlyTransportDecorator))
636
self.failUnless(isinstance(t2, ReadonlyTransportDecorator))
654
self.assertIsInstance(t, ReadonlyTransportDecorator)
655
self.assertIsInstance(t2, ReadonlyTransportDecorator)
637
656
self.assertEqual(t2.base[:-1], t.abspath('foo/bar'))
639
658
def test_get_readonly_url_http(self):
647
666
# the transport returned may be any HttpTransportBase subclass
648
667
t = transport.get_transport(url)
649
668
t2 = transport.get_transport(url2)
650
self.failUnless(isinstance(t, HttpTransportBase))
651
self.failUnless(isinstance(t2, HttpTransportBase))
669
self.assertIsInstance(t, HttpTransportBase)
670
self.assertIsInstance(t2, HttpTransportBase)
652
671
self.assertEqual(t2.base[:-1], t.abspath('foo/bar'))
654
673
def test_is_directory(self):
662
681
def test_make_branch_builder(self):
663
682
builder = self.make_branch_builder('dir')
664
683
rev_id = builder.build_commit()
665
self.failUnlessExists('dir')
684
self.assertPathExists('dir')
666
685
a_dir = bzrdir.BzrDir.open('dir')
667
686
self.assertRaises(errors.NoWorkingTree, a_dir.open_workingtree)
668
687
a_branch = a_dir.open_branch()
684
703
self.assertIsInstance(result_bzrdir.transport,
685
704
memory.MemoryTransport)
686
705
# should not be on disk, should only be in memory
687
self.failIfExists('subdir')
706
self.assertPathDoesNotExist('subdir')
690
709
class TestChrootedTest(tests.ChrootedTestCase):
749
768
self.check_timing(ShortDelayTestCase('test_short_delay'),
752
def _patch_get_bzr_source_tree(self):
753
# Reading from the actual source tree breaks isolation, but we don't
754
# want to assume that thats *all* that would happen.
755
self.overrideAttr(bzrlib.version, '_get_bzr_source_tree', lambda: None)
757
def test_assigned_benchmark_file_stores_date(self):
758
self._patch_get_bzr_source_tree()
760
result = bzrlib.tests.TextTestResult(self._log_file,
765
output_string = output.getvalue()
766
# if you are wondering about the regexp please read the comment in
767
# test_bench_history (bzrlib.tests.test_selftest.TestRunner)
768
# XXX: what comment? -- Andrew Bennetts
769
self.assertContainsRe(output_string, "--date [0-9.]+")
771
def test_benchhistory_records_test_times(self):
772
self._patch_get_bzr_source_tree()
773
result_stream = StringIO()
774
result = bzrlib.tests.TextTestResult(
778
bench_history=result_stream
781
# we want profile a call and check that its test duration is recorded
782
# make a new test instance that when run will generate a benchmark
783
example_test_case = TestTestResult("_time_hello_world_encoding")
784
# execute the test, which should succeed and record times
785
example_test_case.run(result)
786
lines = result_stream.getvalue().splitlines()
787
self.assertEqual(2, len(lines))
788
self.assertContainsRe(lines[1],
789
" *[0-9]+ms bzrlib.tests.test_selftest.TestTestResult"
790
"._time_hello_world_encoding")
792
771
def _time_hello_world_encoding(self):
793
772
"""Profile two sleep calls
1216
def _patch_get_bzr_source_tree(self):
1217
# Reading from the actual source tree breaks isolation, but we don't
1218
# want to assume that thats *all* that would happen.
1219
self._get_source_tree_calls = []
1221
self._get_source_tree_calls.append("called")
1223
self.overrideAttr(bzrlib.version, '_get_bzr_source_tree', new_get)
1225
def test_bench_history(self):
1226
# tests that the running the benchmark passes bench_history into
1227
# the test result object. We can tell that happens if
1228
# _get_bzr_source_tree is called.
1229
self._patch_get_bzr_source_tree()
1230
test = TestRunner('dummy_test')
1232
runner = tests.TextTestRunner(stream=self._log_file,
1233
bench_history=output)
1234
result = self.run_test_runner(runner, test)
1235
output_string = output.getvalue()
1236
self.assertContainsRe(output_string, "--date [0-9.]+")
1237
self.assertLength(1, self._get_source_tree_calls)
1239
1195
def test_verbose_test_count(self):
1240
1196
"""A verbose test run reports the right test count at the start"""
1241
1197
suite = TestUtil.TestSuite([
1486
1442
# Note this test won't fail with hooks that the core library doesn't
1487
1443
# use - but it trigger with a plugin that adds hooks, so its still a
1488
1444
# useful warning in that case.
1489
self.assertEqual(bzrlib.branch.BranchHooks(),
1490
bzrlib.branch.Branch.hooks)
1491
self.assertEqual(bzrlib.smart.server.SmartServerHooks(),
1445
self.assertEqual(bzrlib.branch.BranchHooks(), bzrlib.branch.Branch.hooks)
1447
bzrlib.smart.server.SmartServerHooks(),
1492
1448
bzrlib.smart.server.SmartTCPServer.hooks)
1493
self.assertEqual(bzrlib.commands.CommandHooks(),
1494
bzrlib.commands.Command.hooks)
1450
bzrlib.commands.CommandHooks(), bzrlib.commands.Command.hooks)
1496
1452
def test__gather_lsprof_in_benchmarks(self):
1497
1453
"""When _gather_lsprof_in_benchmarks is on, accumulate profile data.
2361
2317
# stdout and stderr of the invoked run_bzr
2362
2318
current_factory = bzrlib.ui.ui_factory
2363
2319
self.run_bzr(['foo'])
2364
self.failIf(current_factory is self.factory)
2320
self.assertFalse(current_factory is self.factory)
2365
2321
self.assertNotEqual(sys.stdout, self.factory.stdout)
2366
2322
self.assertNotEqual(sys.stderr, self.factory.stderr)
2367
2323
self.assertEqual('foo\n', self.factory.stdout.getvalue())
2549
2505
self.assertEqual([], command[2:])
2551
2507
def test_set_env(self):
2552
self.failIf('EXISTANT_ENV_VAR' in os.environ)
2508
self.assertFalse('EXISTANT_ENV_VAR' in os.environ)
2553
2509
# set in the child
2554
2510
def check_environment():
2555
2511
self.assertEqual('set variable', os.environ['EXISTANT_ENV_VAR'])
2562
2518
def test_run_bzr_subprocess_env_del(self):
2563
2519
"""run_bzr_subprocess can remove environment variables too."""
2564
self.failIf('EXISTANT_ENV_VAR' in os.environ)
2520
self.assertFalse('EXISTANT_ENV_VAR' in os.environ)
2565
2521
def check_environment():
2566
2522
self.assertFalse('EXISTANT_ENV_VAR' in os.environ)
2567
2523
os.environ['EXISTANT_ENV_VAR'] = 'set variable'
2573
2529
del os.environ['EXISTANT_ENV_VAR']
2575
2531
def test_env_del_missing(self):
2576
self.failIf('NON_EXISTANT_ENV_VAR' in os.environ)
2532
self.assertFalse('NON_EXISTANT_ENV_VAR' in os.environ)
2577
2533
def check_environment():
2578
2534
self.assertFalse('NON_EXISTANT_ENV_VAR' in os.environ)
2579
2535
self.check_popen_state = check_environment
3405
3361
class TestEnvironHandling(tests.TestCase):
3407
3363
def test_overrideEnv_None_called_twice_doesnt_leak(self):
3408
self.failIf('MYVAR' in os.environ)
3364
self.assertFalse('MYVAR' in os.environ)
3409
3365
self.overrideEnv('MYVAR', '42')
3410
3366
# We use an embedded test to make sure we fix the _captureVar bug
3411
3367
class Test(tests.TestCase):