~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_chk_map.py

  • Committer: John Arbash Meinel
  • Date: 2009-10-08 16:03:45 UTC
  • mto: This revision was merged to the branch mainline in revision 4771.
  • Revision ID: john@arbash-meinel.com-20091008160345-wnfh9gewhdvi8tbc
Clean up the chk test suite a little bit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
    Node,
33
33
    )
34
34
 
 
35
key_types = (tuple, chk_map._key_type)
35
36
 
36
37
class TestNode(tests.TestCase):
37
38
 
831
832
        # 'ab' and 'ac' nodes
832
833
        chkmap.map(('aad',), 'v')
833
834
        self.assertIsInstance(chkmap._root_node._items['aa'], InternalNode)
834
 
        self.assertIsInstance(chkmap._root_node._items['ab'], (tuple, chk_map._key_type))
835
 
        self.assertIsInstance(chkmap._root_node._items['ac'], (tuple, chk_map._key_type))
 
835
        self.assertIsInstance(chkmap._root_node._items['ab'], key_types)
 
836
        self.assertIsInstance(chkmap._root_node._items['ac'], key_types)
836
837
        # Unmapping 'acd' can notice that 'aa' is an InternalNode and not have
837
838
        # to map in 'ab'
838
839
        chkmap.unmap(('acd',))
839
840
        self.assertIsInstance(chkmap._root_node._items['aa'], InternalNode)
840
 
        self.assertIsInstance(chkmap._root_node._items['ab'], (tuple, chk_map._key_type))
 
841
        self.assertIsInstance(chkmap._root_node._items['ab'], key_types)
841
842
 
842
843
    def test_unmap_without_fitting_doesnt_page_in(self):
843
844
        store = self.get_chk_bytes()
860
861
        chkmap.map(('aaf',), 'v')
861
862
        # At this point, the previous nodes should not be paged in, but the
862
863
        # newly added nodes would be
863
 
        self.assertIsInstance(chkmap._root_node._items['aaa'], (tuple,
864
 
        chk_map._key_type))
865
 
        self.assertIsInstance(chkmap._root_node._items['aab'], (tuple, chk_map._key_type))
 
864
        self.assertIsInstance(chkmap._root_node._items['aaa'], key_types)
 
865
        self.assertIsInstance(chkmap._root_node._items['aab'], key_types)
866
866
        self.assertIsInstance(chkmap._root_node._items['aac'], LeafNode)
867
867
        self.assertIsInstance(chkmap._root_node._items['aad'], LeafNode)
868
868
        self.assertIsInstance(chkmap._root_node._items['aae'], LeafNode)
870
870
        # Now unmapping one of the new nodes will use only the already-paged-in
871
871
        # nodes to determine that we don't need to do more.
872
872
        chkmap.unmap(('aaf',))
873
 
        self.assertIsInstance(chkmap._root_node._items['aaa'], (tuple, chk_map._key_type))
874
 
        self.assertIsInstance(chkmap._root_node._items['aab'], (tuple, chk_map._key_type))
 
873
        self.assertIsInstance(chkmap._root_node._items['aaa'], key_types)
 
874
        self.assertIsInstance(chkmap._root_node._items['aab'], key_types)
875
875
        self.assertIsInstance(chkmap._root_node._items['aac'], LeafNode)
876
876
        self.assertIsInstance(chkmap._root_node._items['aad'], LeafNode)
877
877
        self.assertIsInstance(chkmap._root_node._items['aae'], LeafNode)
898
898
        chkmap.map(('aad',), 'v')
899
899
        # At this point, the previous nodes should not be paged in, but the
900
900
        # newly added node would be
901
 
        self.assertIsInstance(chkmap._root_node._items['aaa'], (tuple,
902
 
        chk_map._key_type))
903
 
        self.assertIsInstance(chkmap._root_node._items['aab'], (tuple,
904
 
        chk_map._key_type))
905
 
        self.assertIsInstance(chkmap._root_node._items['aac'], (tuple,
906
 
        chk_map._key_type))
 
901
        self.assertIsInstance(chkmap._root_node._items['aaa'], key_types)
 
902
        self.assertIsInstance(chkmap._root_node._items['aab'], key_types)
 
903
        self.assertIsInstance(chkmap._root_node._items['aac'], key_types)
907
904
        self.assertIsInstance(chkmap._root_node._items['aad'], LeafNode)
908
905
        # Unmapping the new node will check the existing nodes to see if they
909
906
        # would fit.
941
938
        chkmap.map(('aad',), 'v')
942
939
        # At this point, the previous nodes should not be paged in, but the
943
940
        # newly added node would be
944
 
        self.assertIsInstance(chkmap._root_node._items['aaa'], (tuple,
945
 
        chk_map._key_type))
946
 
        self.assertIsInstance(chkmap._root_node._items['aab'], (tuple,
947
 
        chk_map._key_type))
948
 
        self.assertIsInstance(chkmap._root_node._items['aac'], (tuple,
949
 
        chk_map._key_type))
 
941
        self.assertIsInstance(chkmap._root_node._items['aaa'], key_types)
 
942
        self.assertIsInstance(chkmap._root_node._items['aab'], key_types)
 
943
        self.assertIsInstance(chkmap._root_node._items['aac'], key_types)
950
944
        self.assertIsInstance(chkmap._root_node._items['aad'], LeafNode)
951
945
        # Now clear the page cache, and only include 2 of the children in the
952
946
        # cache
961
955
        # Unmapping the new node will check the nodes from the page cache
962
956
        # first, and not have to read in 'aaa'
963
957
        chkmap.unmap(('aad',))
964
 
        self.assertIsInstance(chkmap._root_node._items['aaa'], (tuple,
965
 
        chk_map._key_type))
 
958
        self.assertIsInstance(chkmap._root_node._items['aaa'], key_types)
966
959
        self.assertIsInstance(chkmap._root_node._items['aab'], LeafNode)
967
960
        self.assertIsInstance(chkmap._root_node._items['aac'], LeafNode)
968
961
 
982
975
        chkmap.map(('aaf',), 'val')
983
976
        # At this point, the previous nodes should not be paged in, but the
984
977
        # newly added node would be
985
 
        self.assertIsInstance(chkmap._root_node._items['aaa'], (tuple,
986
 
        chk_map._key_type))
987
 
        self.assertIsInstance(chkmap._root_node._items['aab'], (tuple,
988
 
        chk_map._key_type))
989
 
        self.assertIsInstance(chkmap._root_node._items['aac'], (tuple,
990
 
        chk_map._key_type))
 
978
        self.assertIsInstance(chkmap._root_node._items['aaa'], key_types)
 
979
        self.assertIsInstance(chkmap._root_node._items['aab'], key_types)
 
980
        self.assertIsInstance(chkmap._root_node._items['aac'], key_types)
991
981
        self.assertIsInstance(chkmap._root_node._items['aad'], LeafNode)
992
982
        self.assertIsInstance(chkmap._root_node._items['aae'], LeafNode)
993
983
        self.assertIsInstance(chkmap._root_node._items['aaf'], LeafNode)
995
985
        # Unmapping a new node will see the other nodes that are already in
996
986
        # memory, and not need to page in anything else
997
987
        chkmap.unmap(('aad',))
998
 
        self.assertIsInstance(chkmap._root_node._items['aaa'], (tuple,
999
 
        chk_map._key_type))
1000
 
        self.assertIsInstance(chkmap._root_node._items['aab'], (tuple,
1001
 
        chk_map._key_type))
1002
 
        self.assertIsInstance(chkmap._root_node._items['aac'], (tuple,
1003
 
        chk_map._key_type))
 
988
        self.assertIsInstance(chkmap._root_node._items['aaa'], key_types)
 
989
        self.assertIsInstance(chkmap._root_node._items['aab'], key_types)
 
990
        self.assertIsInstance(chkmap._root_node._items['aac'], key_types)
1004
991
        self.assertIsInstance(chkmap._root_node._items['aae'], LeafNode)
1005
992
        self.assertIsInstance(chkmap._root_node._items['aaf'], LeafNode)
1006
993
 
1045
1032
            {('a',): 'content here', ('b',): 'more content'},
1046
1033
            chk_bytes=basis._store, maximum_size=10)
1047
1034
        list(target.iter_changes(basis))
1048
 
        self.assertIsInstance(target._root_node, (tuple, chk_map._key_type))
1049
 
        self.assertIsInstance(basis._root_node, (tuple, chk_map._key_type))
 
1035
        self.assertIsInstance(target._root_node, key_types)
 
1036
        self.assertIsInstance(basis._root_node, key_types)
1050
1037
 
1051
1038
    def test_iter_changes_ab_ab_changed_values_shown(self):
1052
1039
        basis = self._get_map({('a',): 'content here', ('b',): 'more content'},
1946
1933
        # Ensure test validity: nothing paged in below the root.
1947
1934
        self.assertEqual(2,
1948
1935
            len([value for value in node._items.values()
1949
 
                if type(value) in (tuple, chk_map._key_type)]))
 
1936
                if type(value) in key_types]))
1950
1937
        # now, mapping to k3 should add a k3 leaf
1951
1938
        prefix, nodes = node.map(None, ('k3',), 'quux')
1952
1939
        self.assertEqual("k", prefix)
1985
1972
        # Ensure test validity: nothing paged in below the root.
1986
1973
        self.assertEqual(2,
1987
1974
            len([value for value in node._items.values()
1988
 
                if type(value) in (tuple, chk_map._key_type)]))
 
1975
                if type(value) in key_types]))
1989
1976
        # now, mapping to k23 causes k22 ('k2' in node) to split into k22 and
1990
1977
        # k23, which for simplicity in the current implementation generates
1991
1978
        # a new internal node between node, and k22/k23.