~amanica/bzr/320119-log_exclusive_lower_bound

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_dirstate.py

  • Committer: Johan Walles
  • Date: 2009-05-06 05:36:28 UTC
  • mfrom: (4332 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4343.
  • Revision ID: johan.walles@gmail.com-20090506053628-tbf1wz4a0m9t684g
MergeĀ fromĀ upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
55
 
 
56
 
47
57
class TestCaseWithDirState(tests.TestCaseWithTransport):
48
58
    """Helper functions for creating DirState objects with various content."""
49
59
 
 
60
    # Set by load_tests
 
61
    _dir_reader_class = None
 
62
    _native_to_unicode = None # Not used yet
 
63
 
 
64
    def setUp(self):
 
65
        tests.TestCaseWithTransport.setUp(self)
 
66
 
 
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()
 
75
 
50
76
    def create_empty_dirstate(self):
51
77
        """Return a locked but empty dirstate"""
52
78
        state = dirstate.DirState.initialize('dirstate')
1106
1132
        state._validate()
1107
1133
        self.assertEqual(expected_entries, list(state._iter_entries()))
1108
1134
 
1109
 
    def test_add_symlink_to_root_no_parents_all_data(self):
 
1135
    def _test_add_symlink_to_root_no_parents_all_data(self, link_name, target):
1110
1136
        # The most trivial addition of a symlink when there are no parents and
1111
1137
        # its in the root and all data about the file is supplied
1112
1138
        # bzr doesn't support fake symlinks on windows, yet.
1113
1139
        self.requireFeature(tests.SymlinkFeature)
1114
 
        os.symlink('target', 'a link')
1115
 
        stat = os.lstat('a link')
 
1140
        os.symlink(target, link_name)
 
1141
        stat = os.lstat(link_name)
1116
1142
        expected_entries = [
1117
1143
            (('', '', 'TREE_ROOT'), [
1118
1144
             ('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree
1119
1145
             ]),
1120
 
            (('', 'a link', 'a link id'), [
1121
 
             ('l', 'target', 6, False, dirstate.pack_stat(stat)), # current tree
 
1146
            (('', link_name.encode('UTF-8'), 'a link id'), [
 
1147
             ('l', target.encode('UTF-8'), stat[6],
 
1148
              False, dirstate.pack_stat(stat)), # current tree
1122
1149
             ]),
1123
1150
            ]
1124
1151
        state = dirstate.DirState.initialize('dirstate')
1125
1152
        try:
1126
 
            state.add('a link', 'a link id', 'symlink', stat, 'target')
 
1153
            state.add(link_name, 'a link id', 'symlink', stat,
 
1154
                      target.encode('UTF-8'))
1127
1155
            # having added it, it should be in the output of iter_entries.
1128
1156
            self.assertEqual(expected_entries, list(state._iter_entries()))
1129
1157
            # saving and reloading should not affect this.
1135
1163
        self.addCleanup(state.unlock)
1136
1164
        self.assertEqual(expected_entries, list(state._iter_entries()))
1137
1165
 
 
1166
    def test_add_symlink_to_root_no_parents_all_data(self):
 
1167
        self._test_add_symlink_to_root_no_parents_all_data('a link', 'target')
 
1168
 
 
1169
    def test_add_symlink_unicode_to_root_no_parents_all_data(self):
 
1170
        self.requireFeature(tests.UnicodeFilenameFeature)
 
1171
        self._test_add_symlink_to_root_no_parents_all_data(
 
1172
            u'\N{Euro Sign}link', u'targ\N{Euro Sign}et')
 
1173
 
1138
1174
    def test_add_directory_and_child_no_parents_all_data(self):
1139
1175
        # after adding a directory, we should be able to add children to it.
1140
1176
        self.build_tree(['a dir/', 'a dir/a file'])
2204
2240
        self.assertIsInstance(tree_data, str)
2205
2241
 
2206
2242
    def test_unicode_symlink(self):
2207
 
        # In general, the code base doesn't support a target that contains
2208
 
        # non-ascii characters. So we just assert tha
2209
 
        inv_entry = inventory.InventoryLink('link-file-id', 'name',
 
2243
        inv_entry = inventory.InventoryLink('link-file-id',
 
2244
                                            u'nam\N{Euro Sign}e',
2210
2245
                                            'link-parent-id')
2211
2246
        inv_entry.revision = 'link-revision-id'
2212
 
        inv_entry.symlink_target = u'link-target'
2213
 
        details = self.assertDetails(('l', 'link-target', 0, False,
2214
 
                                      'link-revision-id'), inv_entry)
 
2247
        target = u'link-targ\N{Euro Sign}t'
 
2248
        inv_entry.symlink_target = target
 
2249
        self.assertDetails(('l', target.encode('UTF-8'), 0, False,
 
2250
                            'link-revision-id'), inv_entry)
2215
2251
 
2216
2252
 
2217
2253
class TestSHA1Provider(tests.TestCaseInTempDir):