~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_dirstate.py

  • Committer: John Arbash Meinel
  • Date: 2011-04-20 15:06:17 UTC
  • mto: This revision was merged to the branch mainline in revision 5836.
  • Revision ID: john@arbash-meinel.com-20110420150617-i41caxgemg32tq1r
Start adding tests that _worth_saving_limit works as expected.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1343
1343
            tree1.unlock()
1344
1344
 
1345
1345
 
 
1346
class TestDirStateHashUpdates(TestCaseWithDirState):
 
1347
 
 
1348
    def do_update_entry(self, state, path):
 
1349
        entry = state._get_entry(0, path_utf8=path)
 
1350
        stat = os.lstat(path)
 
1351
        return dirstate.update_entry(state, entry, os.path.abspath(path), stat)
 
1352
 
 
1353
    def test_worth_saving_limit_avoids_writing(self):
 
1354
        state = self.create_complex_dirstate()
 
1355
        state.save()
 
1356
        state.unlock()
 
1357
        self.build_tree(['c', 'd'])
 
1358
        state = InstrumentedDirState.on_file('dirstate',
 
1359
                                             worth_saving_limit=2)
 
1360
        state.lock_write()
 
1361
        self.addCleanup(state.unlock)
 
1362
        state._read_dirblocks_if_needed()
 
1363
        state.adjust_time(+20) # Allow things to be cached
 
1364
        self.assertEqual(dirstate.DirState.IN_MEMORY_UNMODIFIED,
 
1365
                         state._dirblock_state)
 
1366
        f = open('dirstate', 'rb')
 
1367
        try:
 
1368
            content = f.read()
 
1369
        finally:
 
1370
            f.close()
 
1371
        self.do_update_entry(state, 'c')
 
1372
        self.assertEqual(1, len(state._known_hash_changes))
 
1373
        self.assertEqual(dirstate.DirState.IN_MEMORY_HASH_MODIFIED,
 
1374
                         state._dirblock_state)
 
1375
        state.save()
 
1376
        # It should not have set the state to IN_MEMORY_UNMODIFIED because the
 
1377
        # hash values haven't been written out.
 
1378
        self.assertEqual(dirstate.DirState.IN_MEMORY_HASH_MODIFIED,
 
1379
                         state._dirblock_state)
 
1380
        self.assertFileEqual(content, 'dirstate')
 
1381
        self.assertEqual(dirstate.DirState.IN_MEMORY_HASH_MODIFIED,
 
1382
                         state._dirblock_state)
 
1383
        self.do_update_entry(state, 'd')
 
1384
        self.assertEqual(2, len(state._known_hash_changes))
 
1385
        state.save()
 
1386
        self.assertEqual(dirstate.DirState.IN_MEMORY_UNMODIFIED,
 
1387
                         state._dirblock_state)
 
1388
        self.assertEqual(0, len(state._known_hash_changes))
 
1389
 
1346
1390
class TestGetLines(TestCaseWithDirState):
1347
1391
 
1348
1392
    def test_get_line_with_2_rows(self):
1741
1785
class InstrumentedDirState(dirstate.DirState):
1742
1786
    """An DirState with instrumented sha1 functionality."""
1743
1787
 
1744
 
    def __init__(self, path, sha1_provider):
1745
 
        super(InstrumentedDirState, self).__init__(path, sha1_provider)
 
1788
    def __init__(self, path, sha1_provider, worth_saving_limit=0):
 
1789
        super(InstrumentedDirState, self).__init__(path, sha1_provider,
 
1790
            worth_saving_limit=worth_saving_limit)
1746
1791
        self._time_offset = 0
1747
1792
        self._log = []
1748
1793
        # member is dynamically set in DirState.__init__ to turn on trace