/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_workingtree_4.py

Merge with bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
"""Tests for WorkingTreeFormat4"""
19
19
 
20
20
import os
 
21
import time
21
22
 
22
23
from bzrlib import (
23
24
    bzrdir,
577
578
        self.assertEqual([], changes)
578
579
        self.assertEqual(['', 'versioned', 'versioned2'], returned)
579
580
 
 
581
    def get_tree_with_cachable_file_foo(self):
 
582
        tree = self.make_branch_and_tree('.')
 
583
        self.build_tree(['foo'])
 
584
        tree.add(['foo'], ['foo-id'])
 
585
        # a 4 second old timestamp is always hashable - sucks to delay 
 
586
        # the test suite, but not testing this is worse.
 
587
        time.sleep(4)
 
588
        return tree
 
589
 
 
590
    def test_commit_updates_hash_cache(self):
 
591
        tree = self.get_tree_with_cachable_file_foo()
 
592
        revid = tree.commit('a commit')
 
593
        # tree's dirstate should now have a valid stat entry for foo.
 
594
        tree.lock_read()
 
595
        entry = tree._get_entry(path='foo')
 
596
        expected_sha1 = osutils.sha_file_by_name('foo')
 
597
        self.assertEqual(expected_sha1, entry[1][0][1])
 
598
 
 
599
    def test_observed_sha1_cachable(self):
 
600
        tree = self.get_tree_with_cachable_file_foo()
 
601
        expected_sha1 = osutils.sha_file_by_name('foo')
 
602
        statvalue = os.lstat("foo")
 
603
        tree.lock_write()
 
604
        try:
 
605
            tree._observed_sha1("foo-id", "foo", (expected_sha1, statvalue))
 
606
            self.assertEqual(expected_sha1,
 
607
                tree._get_entry(path="foo")[1][0][1])
 
608
        finally:
 
609
            tree.unlock()
 
610
        tree = tree.bzrdir.open_workingtree()
 
611
        tree.lock_read()
 
612
        self.addCleanup(tree.unlock)
 
613
        self.assertEqual(expected_sha1, tree._get_entry(path="foo")[1][0][1])
 
614
 
 
615
    def test_observed_sha1_new_file(self):
 
616
        tree = self.make_branch_and_tree('.')
 
617
        self.build_tree(['foo'])
 
618
        tree.add(['foo'], ['foo-id'])
 
619
        tree.lock_read()
 
620
        try:
 
621
            current_sha1 = tree._get_entry(path="foo")[1][0][1]
 
622
        finally:
 
623
            tree.unlock()
 
624
        tree.lock_write()
 
625
        try:
 
626
            tree._observed_sha1("foo-id", "foo",
 
627
                (osutils.sha_file_by_name('foo'), os.lstat("foo")))
 
628
            # Must not have changed
 
629
            self.assertEqual(current_sha1,
 
630
                tree._get_entry(path="foo")[1][0][1])
 
631
        finally:
 
632
            tree.unlock()
 
633
 
 
634
    def test_get_file_with_stat_id_only(self):
 
635
        # Explicit test to ensure we get a lstat value from WT4 trees.
 
636
        tree = self.make_branch_and_tree('.')
 
637
        self.build_tree(['foo'])
 
638
        tree.add(['foo'], ['foo-id'])
 
639
        tree.lock_read()
 
640
        self.addCleanup(tree.unlock)
 
641
        file_obj, statvalue = tree.get_file_with_stat('foo-id')
 
642
        expected = os.lstat('foo')
 
643
        self.assertEqualStat(expected, statvalue)
 
644
        self.assertEqual(["contents of foo\n"], file_obj.readlines())
 
645
 
580
646
 
581
647
class TestCorruptDirstate(TestCaseWithTransport):
582
648
    """Tests for how we handle when the dirstate has been corrupted."""