~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_dirstate.py

  • Committer: Matt Nordhoff
  • Date: 2009-04-04 02:50:01 UTC
  • mfrom: (4253 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4256.
  • Revision ID: mnordhoff@mattnordhoff.com-20090404025001-z1403k0tatmc8l91
Merge bzr.dev, fixing conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Tests of the dirstate functionality being built for WorkingTreeFormat4."""
18
18
 
30
30
from bzrlib.tests import (
31
31
        SymlinkFeature,
32
32
        TestCase,
 
33
        TestCaseInTempDir,
33
34
        TestCaseWithTransport,
34
35
        )
35
36
 
639
640
                state2.unlock()
640
641
        finally:
641
642
            state.unlock()
642
 
        
 
643
 
643
644
        # The file on disk should not be modified.
644
645
        state = dirstate.DirState.on_file('dirstate')
645
646
        state.lock_read()
745
746
        # https://bugs.launchpad.net/bzr/+bug/146176
746
747
        # set_state_from_inventory should preserve the stat and hash value for
747
748
        # workingtree files that are not changed by the inventory.
748
 
       
 
749
 
749
750
        tree = self.make_branch_and_tree('.')
750
751
        # depends on the default format using dirstate...
751
752
        tree.lock_write()
752
753
        try:
753
 
            # make a dirstate with some valid hashcache data 
 
754
            # make a dirstate with some valid hashcache data
754
755
            # file on disk, but that's not needed for this test
755
756
            foo_contents = 'contents of foo'
756
757
            self.build_tree_contents([('foo', foo_contents)])
776
777
                (('', 'foo', 'foo-id',),
777
778
                 [('f', foo_sha, foo_size, False, foo_packed)]),
778
779
                tree._dirstate._get_entry(0, 'foo-id'))
779
 
           
 
780
 
780
781
            # extract the inventory, and add something to it
781
782
            inv = tree._get_inventory()
782
783
            # should see the file we poked in...
1455
1456
        There is one parent tree, which has the same shape with the following variations:
1456
1457
        b/g in the parent is gone.
1457
1458
        b/h in the parent has a different id
1458
 
        b/i is new in the parent 
 
1459
        b/i is new in the parent
1459
1460
        c is renamed to b/j in the parent
1460
1461
 
1461
1462
        :return: The dirstate, still write-locked.
1616
1617
class InstrumentedDirState(dirstate.DirState):
1617
1618
    """An DirState with instrumented sha1 functionality."""
1618
1619
 
1619
 
    def __init__(self, path):
1620
 
        super(InstrumentedDirState, self).__init__(path)
 
1620
    def __init__(self, path, sha1_provider):
 
1621
        super(InstrumentedDirState, self).__init__(path, sha1_provider)
1621
1622
        self._time_offset = 0
1622
1623
        self._log = []
1623
1624
        # member is dynamically set in DirState.__init__ to turn on trace
 
1625
        self._sha1_provider = sha1_provider
1624
1626
        self._sha1_file = self._sha1_file_and_log
1625
1627
 
1626
1628
    def _sha_cutoff_time(self):
1629
1631
 
1630
1632
    def _sha1_file_and_log(self, abspath):
1631
1633
        self._log.append(('sha1', abspath))
1632
 
        return osutils.sha_file_by_name(abspath)
 
1634
        return self._sha1_provider.sha1(abspath)
1633
1635
 
1634
1636
    def _read_link(self, abspath, old_link):
1635
1637
        self._log.append(('read_link', abspath, old_link))
1666
1668
        self.st_ino = ino
1667
1669
        self.st_mode = mode
1668
1670
 
 
1671
    @staticmethod
 
1672
    def from_stat(st):
 
1673
        return _FakeStat(st.st_size, st.st_mtime, st.st_ctime, st.st_dev,
 
1674
            st.st_ino, st.st_mode)
 
1675
 
1669
1676
 
1670
1677
class TestPackStat(TestCaseWithTransport):
1671
1678
 
2214
2221
 
2215
2222
    def test_unicode_symlink(self):
2216
2223
        # In general, the code base doesn't support a target that contains
2217
 
        # non-ascii characters. So we just assert tha 
 
2224
        # non-ascii characters. So we just assert tha
2218
2225
        inv_entry = inventory.InventoryLink('link-file-id', 'name',
2219
2226
                                            'link-parent-id')
2220
2227
        inv_entry.revision = 'link-revision-id'
2221
2228
        inv_entry.symlink_target = u'link-target'
2222
2229
        details = self.assertDetails(('l', 'link-target', 0, False,
2223
2230
                                      'link-revision-id'), inv_entry)
 
2231
 
 
2232
 
 
2233
class TestSHA1Provider(TestCaseInTempDir):
 
2234
 
 
2235
    def test_sha1provider_is_an_interface(self):
 
2236
        p = dirstate.SHA1Provider()
 
2237
        self.assertRaises(NotImplementedError, p.sha1, "foo")
 
2238
        self.assertRaises(NotImplementedError, p.stat_and_sha1, "foo")
 
2239
 
 
2240
    def test_defaultsha1provider_sha1(self):
 
2241
        text = 'test\r\nwith\nall\rpossible line endings\r\n'
 
2242
        self.build_tree_contents([('foo', text)])
 
2243
        expected_sha = osutils.sha_string(text)
 
2244
        p = dirstate.DefaultSHA1Provider()
 
2245
        self.assertEqual(expected_sha, p.sha1('foo'))
 
2246
 
 
2247
    def test_defaultsha1provider_stat_and_sha1(self):
 
2248
        text = 'test\r\nwith\nall\rpossible line endings\r\n'
 
2249
        self.build_tree_contents([('foo', text)])
 
2250
        expected_sha = osutils.sha_string(text)
 
2251
        p = dirstate.DefaultSHA1Provider()
 
2252
        statvalue, sha1 = p.stat_and_sha1('foo')
 
2253
        self.assertTrue(len(statvalue) >= 10)
 
2254
        self.assertEqual(len(text), statvalue.st_size)
 
2255
        self.assertEqual(expected_sha, sha1)