~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_dirstate.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-04-16 01:09:56 UTC
  • mfrom: (5784.1.4 760435-less-fail)
  • Revision ID: pqm@pqm.ubuntu.com-20110416010956-5wrpm136qq2hz5f3
(mbp) rename and deprecate failUnlessExists and failIfExists (Martin Pool)

Show diffs side-by-side

added added

removed removed

Lines of Context:
527
527
 
528
528
class TestDirStateOnFile(TestCaseWithDirState):
529
529
 
530
 
    def create_updated_dirstate(self):
531
 
        self.build_tree(['a-file'])
532
 
        tree = self.make_branch_and_tree('.')
533
 
        tree.add(['a-file'], ['a-id'])
534
 
        tree.commit('add a-file')
535
 
        # Save and unlock the state, re-open it in readonly mode
536
 
        state = dirstate.DirState.from_tree(tree, 'dirstate')
537
 
        state.save()
538
 
        state.unlock()
539
 
        state = dirstate.DirState.on_file('dirstate')
540
 
        state.lock_read()
541
 
        return state
542
 
 
543
530
    def test_construct_with_path(self):
544
531
        tree = self.make_branch_and_tree('tree')
545
532
        state = dirstate.DirState.from_tree(tree, 'dirstate.from_tree')
574
561
            state.unlock()
575
562
 
576
563
    def test_can_save_in_read_lock(self):
577
 
        state = self.create_updated_dirstate()
 
564
        self.build_tree(['a-file'])
 
565
        state = dirstate.DirState.initialize('dirstate')
 
566
        try:
 
567
            # No stat and no sha1 sum.
 
568
            state.add('a-file', 'a-file-id', 'file', None, '')
 
569
            state.save()
 
570
        finally:
 
571
            state.unlock()
 
572
 
 
573
        # Now open in readonly mode
 
574
        state = dirstate.DirState.on_file('dirstate')
 
575
        state.lock_read()
578
576
        try:
579
577
            entry = state._get_entry(0, path_utf8='a-file')
580
578
            # The current size should be 0 (default)
581
579
            self.assertEqual(0, entry[1][0][2])
582
580
            # We should have a real entry.
583
581
            self.assertNotEqual((None, None), entry)
584
 
            # Set the cutoff-time into the future, so things look cacheable
 
582
            # Make sure everything is old enough
585
583
            state._sha_cutoff_time()
586
 
            state._cutoff_time += 10.0
587
 
            st = os.lstat('a-file')
588
 
            sha1sum = dirstate.update_entry(state, entry, 'a-file', st)
589
 
            # We updated the current sha1sum because the file is cacheable
590
 
            self.assertEqual('ecc5374e9ed82ad3ea3b4d452ea995a5fd3e70e3',
591
 
                             sha1sum)
 
584
            state._cutoff_time += 10
 
585
            # Change the file length
 
586
            self.build_tree_contents([('a-file', 'shorter')])
 
587
            sha1sum = dirstate.update_entry(state, entry, 'a-file',
 
588
                os.lstat('a-file'))
 
589
            # new file, no cached sha:
 
590
            self.assertEqual(None, sha1sum)
592
591
 
593
592
            # The dirblock has been updated
594
 
            self.assertEqual(st.st_size, entry[1][0][2])
 
593
            self.assertEqual(7, entry[1][0][2])
595
594
            self.assertEqual(dirstate.DirState.IN_MEMORY_MODIFIED,
596
595
                             state._dirblock_state)
597
596
 
607
606
        state.lock_read()
608
607
        try:
609
608
            entry = state._get_entry(0, path_utf8='a-file')
610
 
            self.assertEqual(st.st_size, entry[1][0][2])
 
609
            self.assertEqual(7, entry[1][0][2])
611
610
        finally:
612
611
            state.unlock()
613
612
 
614
613
    def test_save_fails_quietly_if_locked(self):
615
614
        """If dirstate is locked, save will fail without complaining."""
616
 
        state = self.create_updated_dirstate()
 
615
        self.build_tree(['a-file'])
 
616
        state = dirstate.DirState.initialize('dirstate')
 
617
        try:
 
618
            # No stat and no sha1 sum.
 
619
            state.add('a-file', 'a-file-id', 'file', None, '')
 
620
            state.save()
 
621
        finally:
 
622
            state.unlock()
 
623
 
 
624
        state = dirstate.DirState.on_file('dirstate')
 
625
        state.lock_read()
617
626
        try:
618
627
            entry = state._get_entry(0, path_utf8='a-file')
619
 
            # No cached sha1 yet.
620
 
            self.assertEqual('', entry[1][0][1])
621
 
            # Set the cutoff-time into the future, so things look cacheable
622
 
            state._sha_cutoff_time()
623
 
            state._cutoff_time += 10.0
624
 
            st = os.lstat('a-file')
625
 
            sha1sum = dirstate.update_entry(state, entry, 'a-file', st)
626
 
            self.assertEqual('ecc5374e9ed82ad3ea3b4d452ea995a5fd3e70e3',
627
 
                             sha1sum)
 
628
            sha1sum = dirstate.update_entry(state, entry, 'a-file',
 
629
                os.lstat('a-file'))
 
630
            # No sha - too new
 
631
            self.assertEqual(None, sha1sum)
628
632
            self.assertEqual(dirstate.DirState.IN_MEMORY_MODIFIED,
629
633
                             state._dirblock_state)
630
634