~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_dirstate.py

  • Committer: Andrew Bennetts
  • Date: 2010-01-13 23:16:20 UTC
  • mfrom: (4957 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4960.
  • Revision ID: andrew.bennetts@canonical.com-20100113231620-n6in2yjib2v6z03g
MergeĀ lp:bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006, 2007 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
64
64
    def setUp(self):
65
65
        tests.TestCaseWithTransport.setUp(self)
66
66
 
67
 
        self.overrideAttr(osutils,
68
 
                          '_selected_dir_reader', self._dir_reader_class())
 
67
        # Save platform specific info and reset it
 
68
        cur_dir_reader = osutils._selected_dir_reader
 
69
 
 
70
        def restore():
 
71
            osutils._selected_dir_reader = cur_dir_reader
 
72
        self.addCleanup(restore)
 
73
 
 
74
        osutils._selected_dir_reader = self._dir_reader_class()
69
75
 
70
76
    def create_empty_dirstate(self):
71
77
        """Return a locked but empty dirstate"""
867
873
        state = dirstate.DirState.initialize('dirstate')
868
874
        try:
869
875
            # check precondition to be sure the state does change appropriately.
870
 
            root_entry = (('', '', 'TREE_ROOT'), [('d', '', 0, False, 'x'*32)])
871
 
            self.assertEqual([root_entry], list(state._iter_entries()))
872
 
            self.assertEqual(root_entry, state._get_entry(0, path_utf8=''))
873
 
            self.assertEqual(root_entry,
874
 
                             state._get_entry(0, fileid_utf8='TREE_ROOT'))
875
 
            self.assertEqual((None, None),
876
 
                             state._get_entry(0, fileid_utf8='second-root-id'))
877
 
            state.set_path_id('', 'second-root-id')
878
 
            new_root_entry = (('', '', 'second-root-id'),
879
 
                              [('d', '', 0, False, 'x'*32)])
880
 
            expected_rows = [new_root_entry]
 
876
            self.assertEqual(
 
877
                [(('', '', 'TREE_ROOT'), [('d', '', 0, False,
 
878
                   'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')])],
 
879
                list(state._iter_entries()))
 
880
            state.set_path_id('', 'foobarbaz')
 
881
            expected_rows = [
 
882
                (('', '', 'foobarbaz'), [('d', '', 0, False,
 
883
                   'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')])]
881
884
            self.assertEqual(expected_rows, list(state._iter_entries()))
882
 
            self.assertEqual(new_root_entry, state._get_entry(0, path_utf8=''))
883
 
            self.assertEqual(new_root_entry, 
884
 
                             state._get_entry(0, fileid_utf8='second-root-id'))
885
 
            self.assertEqual((None, None),
886
 
                             state._get_entry(0, fileid_utf8='TREE_ROOT'))
887
885
            # should work across save too
888
886
            state.save()
889
887
        finally:
907
905
        state._validate()
908
906
        try:
909
907
            state.set_parent_trees([('parent-revid', rt)], ghosts=[])
910
 
            root_entry = (('', '', 'TREE_ROOT'),
911
 
                          [('d', '', 0, False, 'x'*32),
912
 
                           ('d', '', 0, False, 'parent-revid')])
913
 
            self.assertEqual(root_entry, state._get_entry(0, path_utf8=''))
914
 
            self.assertEqual(root_entry,
915
 
                             state._get_entry(0, fileid_utf8='TREE_ROOT'))
916
 
            self.assertEqual((None, None),
917
 
                             state._get_entry(0, fileid_utf8='Asecond-root-id'))
918
 
            state.set_path_id('', 'Asecond-root-id')
 
908
            state.set_path_id('', 'foobarbaz')
919
909
            state._validate()
920
910
            # now see that it is what we expected
921
 
            old_root_entry = (('', '', 'TREE_ROOT'),
922
 
                              [('a', '', 0, False, ''),
923
 
                               ('d', '', 0, False, 'parent-revid')])
924
 
            new_root_entry = (('', '', 'Asecond-root-id'),
925
 
                              [('d', '', 0, False, ''),
926
 
                               ('a', '', 0, False, '')])
927
 
            expected_rows = [new_root_entry, old_root_entry]
 
911
            expected_rows = [
 
912
                (('', '', 'TREE_ROOT'),
 
913
                    [('a', '', 0, False, ''),
 
914
                     ('d', '', 0, False, 'parent-revid'),
 
915
                     ]),
 
916
                (('', '', 'foobarbaz'),
 
917
                    [('d', '', 0, False, ''),
 
918
                     ('a', '', 0, False, ''),
 
919
                     ]),
 
920
                ]
928
921
            state._validate()
929
922
            self.assertEqual(expected_rows, list(state._iter_entries()))
930
 
            self.assertEqual(new_root_entry, state._get_entry(0, path_utf8=''))
931
 
            self.assertEqual(old_root_entry, state._get_entry(1, path_utf8=''))
932
 
            self.assertEqual((None, None),
933
 
                             state._get_entry(0, fileid_utf8='TREE_ROOT'))
934
 
            self.assertEqual(old_root_entry,
935
 
                             state._get_entry(1, fileid_utf8='TREE_ROOT'))
936
 
            self.assertEqual(new_root_entry,
937
 
                             state._get_entry(0, fileid_utf8='Asecond-root-id'))
938
 
            self.assertEqual((None, None),
939
 
                             state._get_entry(1, fileid_utf8='Asecond-root-id'))
940
923
            # should work across save too
941
924
            state.save()
942
925
        finally: