~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_workingtree_4.py

  • Committer: John Arbash Meinel
  • Date: 2011-04-08 12:28:05 UTC
  • mfrom: (5771 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5775.
  • Revision ID: john@arbash-meinel.com-20110408122805-qdo9uc2dtc9mzoic
Merge bzr 5771, make sure to have the latest create-file changes, etc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2007-2011 Canonical Ltd
2
2
# Authors:  Robert Collins <robert.collins@canonical.com>
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
597
597
 
598
598
    def get_tree_with_cachable_file_foo(self):
599
599
        tree = self.make_branch_and_tree('.')
600
 
        self.build_tree(['foo'])
 
600
        tree.lock_write()
 
601
        self.addCleanup(tree.unlock)
 
602
        self.build_tree_contents([('foo', 'a bit of content for foo\n')])
601
603
        tree.add(['foo'], ['foo-id'])
602
 
        # a 4 second old timestamp is always hashable - sucks to delay
603
 
        # the test suite, but not testing this is worse.
604
 
        time.sleep(4)
 
604
        tree.current_dirstate()._cutoff_time = time.time() + 60
605
605
        return tree
606
606
 
607
607
    def test_commit_updates_hash_cache(self):
608
608
        tree = self.get_tree_with_cachable_file_foo()
609
609
        revid = tree.commit('a commit')
610
610
        # tree's dirstate should now have a valid stat entry for foo.
611
 
        tree.lock_read()
612
 
        self.addCleanup(tree.unlock)
613
611
        entry = tree._get_entry(path='foo')
614
612
        expected_sha1 = osutils.sha_file_by_name('foo')
615
613
        self.assertEqual(expected_sha1, entry[1][0][1])
 
614
        self.assertEqual(len('a bit of content for foo\n'), entry[1][0][2])
616
615
 
617
616
    def test_observed_sha1_cachable(self):
618
617
        tree = self.get_tree_with_cachable_file_foo()
619
618
        expected_sha1 = osutils.sha_file_by_name('foo')
620
619
        statvalue = os.lstat("foo")
621
 
        tree.lock_write()
622
 
        try:
623
 
            tree._observed_sha1("foo-id", "foo", (expected_sha1, statvalue))
624
 
            self.assertEqual(expected_sha1,
625
 
                tree._get_entry(path="foo")[1][0][1])
626
 
        finally:
627
 
            tree.unlock()
 
620
        tree._observed_sha1("foo-id", "foo", (expected_sha1, statvalue))
 
621
        entry = tree._get_entry(path="foo")
 
622
        entry_state = entry[1][0]
 
623
        self.assertEqual(expected_sha1, entry_state[1])
 
624
        self.assertEqual(statvalue.st_size, entry_state[2])
 
625
        tree.unlock()
 
626
        tree.lock_read()
628
627
        tree = tree.bzrdir.open_workingtree()
629
628
        tree.lock_read()
630
629
        self.addCleanup(tree.unlock)
631
 
        self.assertEqual(expected_sha1, tree._get_entry(path="foo")[1][0][1])
 
630
        entry = tree._get_entry(path="foo")
 
631
        entry_state = entry[1][0]
 
632
        self.assertEqual(expected_sha1, entry_state[1])
 
633
        self.assertEqual(statvalue.st_size, entry_state[2])
632
634
 
633
635
    def test_observed_sha1_new_file(self):
634
636
        tree = self.make_branch_and_tree('.')