~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_dirstate.py

merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
16
16
 
17
17
"""Tests of the dirstate functionality being built for WorkingTreeFormat4."""
18
18
 
19
 
import bisect
20
19
import os
21
20
 
22
21
from bzrlib import (
29
28
    tests,
30
29
    )
31
30
from bzrlib.tests import test_osutils
 
31
from bzrlib.tests.scenarios import load_tests_apply_scenarios
32
32
 
33
33
 
34
34
# TODO:
44
44
# set_path_id  setting id when state is in memory modified
45
45
 
46
46
 
47
 
def load_tests(basic_tests, module, loader):
48
 
    suite = loader.suiteClass()
49
 
    dir_reader_tests, remaining_tests = tests.split_suite_by_condition(
50
 
        basic_tests, tests.condition_isinstance(TestCaseWithDirState))
51
 
    tests.multiply_tests(dir_reader_tests,
52
 
                         test_osutils.dir_reader_scenarios(), suite)
53
 
    suite.addTest(remaining_tests)
54
 
    return suite
 
47
load_tests = load_tests_apply_scenarios
55
48
 
56
49
 
57
50
class TestCaseWithDirState(tests.TestCaseWithTransport):
58
51
    """Helper functions for creating DirState objects with various content."""
59
52
 
 
53
    scenarios = test_osutils.dir_reader_scenarios()
 
54
 
60
55
    # Set by load_tests
61
56
    _dir_reader_class = None
62
57
    _native_to_unicode = None # Not used yet
730
725
 
731
726
class TestDirStateManipulations(TestCaseWithDirState):
732
727
 
 
728
    def make_minimal_tree(self):
 
729
        tree1 = self.make_branch_and_memory_tree('tree1')
 
730
        tree1.lock_write()
 
731
        self.addCleanup(tree1.unlock)
 
732
        tree1.add('')
 
733
        revid1 = tree1.commit('foo')
 
734
        return tree1, revid1
 
735
 
733
736
    def test_update_minimal_updates_id_index(self):
734
737
        state = self.create_dirstate_with_root_and_subdir()
735
738
        self.addCleanup(state.unlock)
748
751
 
749
752
    def test_set_state_from_inventory_no_content_no_parents(self):
750
753
        # setting the current inventory is a slow but important api to support.
751
 
        tree1 = self.make_branch_and_memory_tree('tree1')
752
 
        tree1.lock_write()
753
 
        try:
754
 
            tree1.add('')
755
 
            revid1 = tree1.commit('foo').encode('utf8')
756
 
            root_id = tree1.get_root_id()
757
 
            inv = tree1.inventory
758
 
        finally:
759
 
            tree1.unlock()
 
754
        tree1, revid1 = self.make_minimal_tree()
 
755
        inv = tree1.inventory
 
756
        root_id = inv.path2id('')
760
757
        expected_result = [], [
761
758
            (('', '', root_id), [
762
759
             ('d', '', 0, False, dirstate.DirState.NULLSTAT)])]
774
771
            # This will unlock it
775
772
            self.check_state_with_reopen(expected_result, state)
776
773
 
 
774
    def test_set_state_from_scratch_no_parents(self):
 
775
        tree1, revid1 = self.make_minimal_tree()
 
776
        inv = tree1.inventory
 
777
        root_id = inv.path2id('')
 
778
        expected_result = [], [
 
779
            (('', '', root_id), [
 
780
             ('d', '', 0, False, dirstate.DirState.NULLSTAT)])]
 
781
        state = dirstate.DirState.initialize('dirstate')
 
782
        try:
 
783
            state.set_state_from_scratch(inv, [], [])
 
784
            self.assertEqual(dirstate.DirState.IN_MEMORY_MODIFIED,
 
785
                             state._header_state)
 
786
            self.assertEqual(dirstate.DirState.IN_MEMORY_MODIFIED,
 
787
                             state._dirblock_state)
 
788
        except:
 
789
            state.unlock()
 
790
            raise
 
791
        else:
 
792
            # This will unlock it
 
793
            self.check_state_with_reopen(expected_result, state)
 
794
 
 
795
    def test_set_state_from_scratch_identical_parent(self):
 
796
        tree1, revid1 = self.make_minimal_tree()
 
797
        inv = tree1.inventory
 
798
        root_id = inv.path2id('')
 
799
        rev_tree1 = tree1.branch.repository.revision_tree(revid1)
 
800
        d_entry = ('d', '', 0, False, dirstate.DirState.NULLSTAT)
 
801
        parent_entry = ('d', '', 0, False, revid1)
 
802
        expected_result = [revid1], [
 
803
            (('', '', root_id), [d_entry, parent_entry])]
 
804
        state = dirstate.DirState.initialize('dirstate')
 
805
        try:
 
806
            state.set_state_from_scratch(inv, [(revid1, rev_tree1)], [])
 
807
            self.assertEqual(dirstate.DirState.IN_MEMORY_MODIFIED,
 
808
                             state._header_state)
 
809
            self.assertEqual(dirstate.DirState.IN_MEMORY_MODIFIED,
 
810
                             state._dirblock_state)
 
811
        except:
 
812
            state.unlock()
 
813
            raise
 
814
        else:
 
815
            # This will unlock it
 
816
            self.check_state_with_reopen(expected_result, state)
 
817
 
777
818
    def test_set_state_from_inventory_preserves_hashcache(self):
778
819
        # https://bugs.launchpad.net/bzr/+bug/146176
779
820
        # set_state_from_inventory should preserve the stat and hash value for