~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test__dirstate_helpers.py

  • Committer: Andrew Bennetts
  • Date: 2009-07-27 05:35:00 UTC
  • mfrom: (4570 +trunk)
  • mto: (4634.6.29 2.0)
  • mto: This revision was merged to the branch mainline in revision 4680.
  • Revision ID: andrew.bennetts@canonical.com-20090727053500-q76zsn2dx33jhmj5
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Tests for the compiled dirstate helpers."""
18
18
 
23
23
from bzrlib import (
24
24
    dirstate,
25
25
    errors,
 
26
    osutils,
26
27
    tests,
27
28
    )
28
29
from bzrlib.tests import (
29
 
        SymlinkFeature,
30
 
        )
31
 
from bzrlib.tests import test_dirstate
 
30
    test_dirstate,
 
31
    test_osutils,
 
32
    )
 
33
 
 
34
try:
 
35
    from bzrlib import _dirstate_helpers_pyx
 
36
    has_dirstate_helpers_pyx = True
 
37
except ImportError:
 
38
    has_dirstate_helpers_pyx = False
32
39
 
33
40
 
34
41
class _CompiledDirstateHelpersFeature(tests.Feature):
35
42
    def _probe(self):
36
 
        try:
37
 
            import bzrlib._dirstate_helpers_c
38
 
        except ImportError:
39
 
            return False
40
 
        return True
 
43
        return has_dirstate_helpers_pyx
41
44
 
42
45
    def feature_name(self):
43
 
        return 'bzrlib._dirstate_helpers_c'
44
 
 
 
46
        return 'bzrlib._dirstate_helpers_pyx'
45
47
CompiledDirstateHelpersFeature = _CompiledDirstateHelpersFeature()
46
48
 
47
49
 
 
50
def load_tests(basic_tests, module, loader):
 
51
    # FIXME: we should also parametrize against SHA1Provider !
 
52
    suite = loader.suiteClass()
 
53
    remaining_tests = basic_tests
 
54
 
 
55
    dir_reader_scenarios = test_osutils.dir_reader_scenarios()
 
56
 
 
57
    ue_scenarios = [('dirstate_Python',
 
58
                     {'update_entry': dirstate.py_update_entry})]
 
59
    if has_dirstate_helpers_pyx:
 
60
        pyrex_scenario = ('dirstate_Pyrex',
 
61
                          {'update_entry': _dirstate_helpers_pyx.update_entry})
 
62
        ue_scenarios.append(pyrex_scenario)
 
63
    process_entry_tests, remaining_tests = tests.split_suite_by_condition(
 
64
        remaining_tests, tests.condition_isinstance(TestUpdateEntry))
 
65
    tests.multiply_tests(process_entry_tests,
 
66
                         tests.multiply_scenarios(dir_reader_scenarios,
 
67
                                                  ue_scenarios),
 
68
                         suite)
 
69
 
 
70
    pe_scenarios = [('dirstate_Python',
 
71
                     {'_process_entry': dirstate.ProcessEntryPython})]
 
72
    if has_dirstate_helpers_pyx:
 
73
        pyrex_scenario = (
 
74
            'dirstate_Pyrex',
 
75
            {'_process_entry': _dirstate_helpers_pyx.ProcessEntryC})
 
76
        pe_scenarios.append(pyrex_scenario)
 
77
    process_entry_tests, remaining_tests = tests.split_suite_by_condition(
 
78
        remaining_tests, tests.condition_isinstance(TestProcessEntry))
 
79
    tests.multiply_tests(process_entry_tests,
 
80
                         tests.multiply_scenarios(dir_reader_scenarios,
 
81
                                                  pe_scenarios),
 
82
                         suite)
 
83
 
 
84
    dir_reader_tests, remaining_tests = tests.split_suite_by_condition(
 
85
        remaining_tests, tests.condition_isinstance(
 
86
            test_dirstate.TestCaseWithDirState))
 
87
    tests.multiply_tests(dir_reader_tests, dir_reader_scenarios, suite)
 
88
    suite.addTest(remaining_tests)
 
89
 
 
90
    return suite
 
91
 
 
92
 
48
93
class TestBisectPathMixin(object):
49
94
    """Test that _bisect_path_*() returns the expected values.
50
95
 
201
246
 
202
247
 
203
248
class TestBisectPathLeft(tests.TestCase, TestBisectPathMixin):
204
 
    """Run all Bisect Path tests against _bisect_path_left_py."""
 
249
    """Run all Bisect Path tests against _bisect_path_left."""
205
250
 
206
251
    def get_bisect_path(self):
207
 
        from bzrlib._dirstate_helpers_py import _bisect_path_left_py
208
 
        return _bisect_path_left_py
 
252
        from bzrlib._dirstate_helpers_py import _bisect_path_left
 
253
        return _bisect_path_left
209
254
 
210
255
    def get_bisect(self):
211
256
        return bisect.bisect_left, 0
212
257
 
213
258
 
214
259
class TestCompiledBisectPathLeft(TestBisectPathLeft):
215
 
    """Run all Bisect Path tests against _bisect_path_right_c"""
 
260
    """Run all Bisect Path tests against _bisect_path_lect"""
216
261
 
217
262
    _test_needs_features = [CompiledDirstateHelpersFeature]
218
263
 
219
264
    def get_bisect_path(self):
220
 
        from bzrlib._dirstate_helpers_c import _bisect_path_left_c
221
 
        return _bisect_path_left_c
 
265
        from bzrlib._dirstate_helpers_pyx import _bisect_path_left
 
266
        return _bisect_path_left
222
267
 
223
268
 
224
269
class TestBisectPathRight(tests.TestCase, TestBisectPathMixin):
225
 
    """Run all Bisect Path tests against _bisect_path_right_py"""
 
270
    """Run all Bisect Path tests against _bisect_path_right"""
226
271
 
227
272
    def get_bisect_path(self):
228
 
        from bzrlib._dirstate_helpers_py import _bisect_path_right_py
229
 
        return _bisect_path_right_py
 
273
        from bzrlib._dirstate_helpers_py import _bisect_path_right
 
274
        return _bisect_path_right
230
275
 
231
276
    def get_bisect(self):
232
277
        return bisect.bisect_right, -1
233
278
 
234
279
 
235
280
class TestCompiledBisectPathRight(TestBisectPathRight):
236
 
    """Run all Bisect Path tests against _bisect_path_right_c"""
 
281
    """Run all Bisect Path tests against _bisect_path_right"""
237
282
 
238
283
    _test_needs_features = [CompiledDirstateHelpersFeature]
239
284
 
240
285
    def get_bisect_path(self):
241
 
        from bzrlib._dirstate_helpers_c import _bisect_path_right_c
242
 
        return _bisect_path_right_c
 
286
        from bzrlib._dirstate_helpers_pyx import _bisect_path_right
 
287
        return _bisect_path_right
243
288
 
244
289
 
245
290
class TestBisectDirblock(tests.TestCase):
256
301
 
257
302
    def get_bisect_dirblock(self):
258
303
        """Return an implementation of bisect_dirblock"""
259
 
        from bzrlib._dirstate_helpers_py import bisect_dirblock_py
260
 
        return bisect_dirblock_py
 
304
        from bzrlib._dirstate_helpers_py import bisect_dirblock
 
305
        return bisect_dirblock
261
306
 
262
307
    def assertBisect(self, dirblocks, split_dirblocks, path, *args, **kwargs):
263
308
        """Assert that bisect_split works like bisect_left on the split paths.
350
395
    _test_needs_features = [CompiledDirstateHelpersFeature]
351
396
 
352
397
    def get_bisect_dirblock(self):
353
 
        from bzrlib._dirstate_helpers_c import bisect_dirblock_c
354
 
        return bisect_dirblock_c
 
398
        from bzrlib._dirstate_helpers_pyx import bisect_dirblock
 
399
        return bisect_dirblock
355
400
 
356
401
 
357
402
class TestCmpByDirs(tests.TestCase):
366
411
 
367
412
    def get_cmp_by_dirs(self):
368
413
        """Get a specific implementation of cmp_by_dirs."""
369
 
        from bzrlib._dirstate_helpers_py import cmp_by_dirs_py
370
 
        return cmp_by_dirs_py
 
414
        from bzrlib._dirstate_helpers_py import cmp_by_dirs
 
415
        return cmp_by_dirs
371
416
 
372
417
    def assertCmpByDirs(self, expected, str1, str2):
373
418
        """Compare the two strings, in both directions.
472
517
    _test_needs_features = [CompiledDirstateHelpersFeature]
473
518
 
474
519
    def get_cmp_by_dirs(self):
475
 
        from bzrlib._dirstate_helpers_c import cmp_by_dirs_c
476
 
        return cmp_by_dirs_c
 
520
        from bzrlib._dirstate_helpers_pyx import cmp_by_dirs
 
521
        return cmp_by_dirs
477
522
 
478
523
 
479
524
class TestCmpPathByDirblock(tests.TestCase):
488
533
 
489
534
    def get_cmp_path_by_dirblock(self):
490
535
        """Get a specific implementation of _cmp_path_by_dirblock."""
491
 
        from bzrlib._dirstate_helpers_py import _cmp_path_by_dirblock_py
492
 
        return _cmp_path_by_dirblock_py
 
536
        from bzrlib._dirstate_helpers_py import _cmp_path_by_dirblock
 
537
        return _cmp_path_by_dirblock
493
538
 
494
539
    def assertCmpPathByDirblock(self, paths):
495
540
        """Compare all paths and make sure they evaluate to the correct order.
623
668
    _test_needs_features = [CompiledDirstateHelpersFeature]
624
669
 
625
670
    def get_cmp_by_dirs(self):
626
 
        from bzrlib._dirstate_helpers_c import _cmp_path_by_dirblock_c
627
 
        return _cmp_path_by_dirblock_c
 
671
        from bzrlib._dirstate_helpers_pyx import _cmp_path_by_dirblock
 
672
        return _cmp_path_by_dirblock
628
673
 
629
674
 
630
675
class TestMemRChr(tests.TestCase):
633
678
    _test_needs_features = [CompiledDirstateHelpersFeature]
634
679
 
635
680
    def assertMemRChr(self, expected, s, c):
636
 
        from bzrlib._dirstate_helpers_c import _py_memrchr
 
681
        from bzrlib._dirstate_helpers_pyx import _py_memrchr
637
682
        self.assertEqual(expected, _py_memrchr(s, c))
638
683
 
639
684
    def test_missing(self):
681
726
    """
682
727
 
683
728
    def get_read_dirblocks(self):
684
 
        from bzrlib._dirstate_helpers_py import _read_dirblocks_py
685
 
        return _read_dirblocks_py
 
729
        from bzrlib._dirstate_helpers_py import _read_dirblocks
 
730
        return _read_dirblocks
686
731
 
687
732
    def test_smoketest(self):
688
733
        """Make sure that we can create and read back a simple file."""
717
762
    _test_needs_features = [CompiledDirstateHelpersFeature]
718
763
 
719
764
    def get_read_dirblocks(self):
720
 
        from bzrlib._dirstate_helpers_c import _read_dirblocks_c
721
 
        return _read_dirblocks_c
 
765
        from bzrlib._dirstate_helpers_pyx import _read_dirblocks
 
766
        return _read_dirblocks
722
767
 
723
768
 
724
769
class TestUsingCompiledIfAvailable(tests.TestCase):
725
770
    """Check that any compiled functions that are available are the default.
726
771
 
727
772
    It is possible to have typos, etc in the import line, such that
728
 
    _dirstate_helpers_c is actually available, but the compiled functions are
 
773
    _dirstate_helpers_pyx is actually available, but the compiled functions are
729
774
    not being used.
730
775
    """
731
776
 
732
777
    def test_bisect_dirblock(self):
733
778
        if CompiledDirstateHelpersFeature.available():
734
 
            from bzrlib._dirstate_helpers_c import bisect_dirblock_c
735
 
            self.assertIs(bisect_dirblock_c, dirstate.bisect_dirblock)
 
779
            from bzrlib._dirstate_helpers_pyx import bisect_dirblock
736
780
        else:
737
 
            from bzrlib._dirstate_helpers_py import bisect_dirblock_py
738
 
            self.assertIs(bisect_dirblock_py, dirstate.bisect_dirblock)
 
781
            from bzrlib._dirstate_helpers_py import bisect_dirblock
 
782
        self.assertIs(bisect_dirblock, dirstate.bisect_dirblock)
739
783
 
740
784
    def test__bisect_path_left(self):
741
785
        if CompiledDirstateHelpersFeature.available():
742
 
            from bzrlib._dirstate_helpers_c import _bisect_path_left_c
743
 
            self.assertIs(_bisect_path_left_c, dirstate._bisect_path_left)
 
786
            from bzrlib._dirstate_helpers_pyx import _bisect_path_left
744
787
        else:
745
 
            from bzrlib._dirstate_helpers_py import _bisect_path_left_py
746
 
            self.assertIs(_bisect_path_left_py, dirstate._bisect_path_left)
 
788
            from bzrlib._dirstate_helpers_py import _bisect_path_left
 
789
        self.assertIs(_bisect_path_left, dirstate._bisect_path_left)
747
790
 
748
791
    def test__bisect_path_right(self):
749
792
        if CompiledDirstateHelpersFeature.available():
750
 
            from bzrlib._dirstate_helpers_c import _bisect_path_right_c
751
 
            self.assertIs(_bisect_path_right_c, dirstate._bisect_path_right)
 
793
            from bzrlib._dirstate_helpers_pyx import _bisect_path_right
752
794
        else:
753
 
            from bzrlib._dirstate_helpers_py import _bisect_path_right_py
754
 
            self.assertIs(_bisect_path_right_py, dirstate._bisect_path_right)
 
795
            from bzrlib._dirstate_helpers_py import _bisect_path_right
 
796
        self.assertIs(_bisect_path_right, dirstate._bisect_path_right)
755
797
 
756
798
    def test_cmp_by_dirs(self):
757
799
        if CompiledDirstateHelpersFeature.available():
758
 
            from bzrlib._dirstate_helpers_c import cmp_by_dirs_c
759
 
            self.assertIs(cmp_by_dirs_c, dirstate.cmp_by_dirs)
 
800
            from bzrlib._dirstate_helpers_pyx import cmp_by_dirs
760
801
        else:
761
 
            from bzrlib._dirstate_helpers_py import cmp_by_dirs_py
762
 
            self.assertIs(cmp_by_dirs_py, dirstate.cmp_by_dirs)
 
802
            from bzrlib._dirstate_helpers_py import cmp_by_dirs
 
803
        self.assertIs(cmp_by_dirs, dirstate.cmp_by_dirs)
763
804
 
764
805
    def test__read_dirblocks(self):
765
806
        if CompiledDirstateHelpersFeature.available():
766
 
            from bzrlib._dirstate_helpers_c import _read_dirblocks_c
767
 
            self.assertIs(_read_dirblocks_c, dirstate._read_dirblocks)
 
807
            from bzrlib._dirstate_helpers_pyx import _read_dirblocks
768
808
        else:
769
 
            from bzrlib._dirstate_helpers_py import _read_dirblocks_py
770
 
            self.assertIs(_read_dirblocks_py, dirstate._read_dirblocks)
 
809
            from bzrlib._dirstate_helpers_py import _read_dirblocks
 
810
        self.assertIs(_read_dirblocks, dirstate._read_dirblocks)
771
811
 
772
812
    def test_update_entry(self):
773
813
        if CompiledDirstateHelpersFeature.available():
774
 
            from bzrlib._dirstate_helpers_c import update_entry
775
 
            self.assertIs(update_entry, dirstate.update_entry)
 
814
            from bzrlib._dirstate_helpers_pyx import update_entry
776
815
        else:
777
 
            from bzrlib.dirstate import py_update_entry
778
 
            self.assertIs(py_update_entry, dirstate.py_update_entry)
 
816
            from bzrlib.dirstate import update_entry
 
817
        self.assertIs(update_entry, dirstate.update_entry)
779
818
 
780
819
    def test_process_entry(self):
781
820
        if CompiledDirstateHelpersFeature.available():
782
 
            from bzrlib._dirstate_helpers_c import ProcessEntryC
 
821
            from bzrlib._dirstate_helpers_pyx import ProcessEntryC
783
822
            self.assertIs(ProcessEntryC, dirstate._process_entry)
784
823
        else:
785
824
            from bzrlib.dirstate import ProcessEntryPython
789
828
class TestUpdateEntry(test_dirstate.TestCaseWithDirState):
790
829
    """Test the DirState.update_entry functions"""
791
830
 
 
831
    # Set by load_tests
 
832
    update_entry = None
 
833
 
 
834
    def setUp(self):
 
835
        super(TestUpdateEntry, self).setUp()
 
836
        orig = dirstate.update_entry
 
837
        def cleanup():
 
838
            dirstate.update_entry = orig
 
839
        self.addCleanup(cleanup)
 
840
        dirstate.update_entry = self.update_entry
 
841
 
792
842
    def get_state_with_a(self):
793
843
        """Create a DirState tracking a single object named 'a'"""
794
844
        state = test_dirstate.InstrumentedDirState.initialize('dirstate')
795
845
        self.addCleanup(state.unlock)
796
846
        state.add('a', 'a-id', 'file', None, '')
797
847
        entry = state._get_entry(0, path_utf8='a')
798
 
        self.set_update_entry()
799
848
        return state, entry
800
849
 
801
 
    def set_update_entry(self):
802
 
        self.update_entry = dirstate.py_update_entry
803
 
 
804
850
    def test_observed_sha1_cachable(self):
805
851
        state, entry = self.get_state_with_a()
806
852
        atime = time.time() - 10
920
966
 
921
967
    def test_update_entry_symlink(self):
922
968
        """Update entry should read symlinks."""
923
 
        self.requireFeature(SymlinkFeature)
 
969
        self.requireFeature(tests.SymlinkFeature)
924
970
        state, entry = self.get_state_with_a()
925
971
        state.save()
926
972
        self.assertEqual(dirstate.DirState.IN_MEMORY_UNMODIFIED,
1020
1066
        self.assertEqual(dirstate.DirState.IN_MEMORY_UNMODIFIED,
1021
1067
                         state._dirblock_state)
1022
1068
 
 
1069
    def test_update_entry_tree_reference(self):
 
1070
        state = test_dirstate.InstrumentedDirState.initialize('dirstate')
 
1071
        self.addCleanup(state.unlock)
 
1072
        state.add('r', 'r-id', 'tree-reference', None, '')
 
1073
        self.build_tree(['r/'])
 
1074
        entry = state._get_entry(0, path_utf8='r')
 
1075
        self.do_update_entry(state, entry, 'r')
 
1076
        entry = state._get_entry(0, path_utf8='r')
 
1077
        self.assertEqual('t', entry[1][0][0])
 
1078
 
1023
1079
    def create_and_test_file(self, state, entry):
1024
1080
        """Create a file at 'a' and verify the state finds it during update.
1025
1081
 
1052
1108
 
1053
1109
        return packed_stat
1054
1110
 
 
1111
    # FIXME: Add unicode version
1055
1112
    def create_and_test_symlink(self, state, entry):
1056
1113
        """Create a symlink at 'a' and verify the state finds it.
1057
1114
 
1086
1143
 
1087
1144
    def test_update_file_to_symlink(self):
1088
1145
        """File becomes a symlink"""
1089
 
        self.requireFeature(SymlinkFeature)
 
1146
        self.requireFeature(tests.SymlinkFeature)
1090
1147
        state, entry = self.get_state_with_a()
1091
1148
        # The file sha1 won't be cached unless the file is old
1092
1149
        state.adjust_time(+10)
1105
1162
 
1106
1163
    def test_update_dir_to_symlink(self):
1107
1164
        """Directory becomes a symlink"""
1108
 
        self.requireFeature(SymlinkFeature)
 
1165
        self.requireFeature(tests.SymlinkFeature)
1109
1166
        state, entry = self.get_state_with_a()
1110
1167
        # The symlink target won't be cached if it isn't old
1111
1168
        state.adjust_time(+10)
1115
1172
 
1116
1173
    def test_update_symlink_to_file(self):
1117
1174
        """Symlink becomes a file"""
1118
 
        self.requireFeature(SymlinkFeature)
 
1175
        self.requireFeature(tests.SymlinkFeature)
1119
1176
        state, entry = self.get_state_with_a()
1120
1177
        # The symlink and file info won't be cached unless old
1121
1178
        state.adjust_time(+10)
1125
1182
 
1126
1183
    def test_update_symlink_to_dir(self):
1127
1184
        """Symlink becomes a directory"""
1128
 
        self.requireFeature(SymlinkFeature)
 
1185
        self.requireFeature(tests.SymlinkFeature)
1129
1186
        state, entry = self.get_state_with_a()
1130
1187
        # The symlink target won't be cached if it isn't old
1131
1188
        state.adjust_time(+10)
1154
1211
        self.assertEqual([('f', '', 14, True, dirstate.DirState.NULLSTAT)],
1155
1212
                         entry[1])
1156
1213
 
1157
 
        # Make the disk object look old enough to cache (but it won't cache the sha
1158
 
        # as it is a new file).
 
1214
        # Make the disk object look old enough to cache (but it won't cache the
 
1215
        # sha as it is a new file).
1159
1216
        state.adjust_time(+20)
1160
1217
        digest = 'b50e5406bb5e153ebbeb20268fcf37c87e1ecfb6'
1161
1218
        self.update_entry(state, entry, abspath='a', stat_value=stat_value)
1162
1219
        self.assertEqual([('f', '', 14, True, dirstate.DirState.NULLSTAT)],
1163
1220
            entry[1])
1164
1221
 
1165
 
 
1166
 
class TestCompiledUpdateEntry(TestUpdateEntry):
1167
 
    """Test the pyrex implementation of _read_dirblocks"""
1168
 
 
1169
 
    _test_needs_features = [CompiledDirstateHelpersFeature]
1170
 
 
1171
 
    def set_update_entry(self):
1172
 
        from bzrlib._dirstate_helpers_c import update_entry
1173
 
        self.update_entry = update_entry
 
1222
    def _prepare_tree(self):
 
1223
        # Create a tree
 
1224
        text = 'Hello World\n'
 
1225
        tree = self.make_branch_and_tree('tree')
 
1226
        self.build_tree_contents([('tree/a file', text)])
 
1227
        tree.add('a file', 'a-file-id')
 
1228
        # Note: dirstate does not sha prior to the first commit
 
1229
        # so commit now in order for the test to work
 
1230
        tree.commit('first')
 
1231
        return tree, text
 
1232
 
 
1233
    def test_sha1provider_sha1_used(self):
 
1234
        tree, text = self._prepare_tree()
 
1235
        state = dirstate.DirState.from_tree(tree, 'dirstate',
 
1236
            UppercaseSHA1Provider())
 
1237
        self.addCleanup(state.unlock)
 
1238
        expected_sha = osutils.sha_string(text.upper() + "foo")
 
1239
        entry = state._get_entry(0, path_utf8='a file')
 
1240
        state._sha_cutoff_time()
 
1241
        state._cutoff_time += 10
 
1242
        sha1 = self.update_entry(state, entry, 'tree/a file',
 
1243
                                 os.lstat('tree/a file'))
 
1244
        self.assertEqual(expected_sha, sha1)
 
1245
 
 
1246
    def test_sha1provider_stat_and_sha1_used(self):
 
1247
        tree, text = self._prepare_tree()
 
1248
        tree.lock_write()
 
1249
        self.addCleanup(tree.unlock)
 
1250
        state = tree._current_dirstate()
 
1251
        state._sha1_provider = UppercaseSHA1Provider()
 
1252
        # If we used the standard provider, it would look like nothing has
 
1253
        # changed
 
1254
        file_ids_changed = [change[0] for change
 
1255
                            in tree.iter_changes(tree.basis_tree())]
 
1256
        self.assertEqual(['a-file-id'], file_ids_changed)
 
1257
 
 
1258
 
 
1259
class UppercaseSHA1Provider(dirstate.SHA1Provider):
 
1260
    """A custom SHA1Provider."""
 
1261
 
 
1262
    def sha1(self, abspath):
 
1263
        return self.stat_and_sha1(abspath)[1]
 
1264
 
 
1265
    def stat_and_sha1(self, abspath):
 
1266
        file_obj = file(abspath, 'rb')
 
1267
        try:
 
1268
            statvalue = os.fstat(file_obj.fileno())
 
1269
            text = ''.join(file_obj.readlines())
 
1270
            sha1 = osutils.sha_string(text.upper() + "foo")
 
1271
        finally:
 
1272
            file_obj.close()
 
1273
        return statvalue, sha1
 
1274
 
 
1275
 
 
1276
class TestProcessEntry(test_dirstate.TestCaseWithDirState):
 
1277
 
 
1278
    # Set by load_tests
 
1279
    _process_entry = None
 
1280
 
 
1281
    def setUp(self):
 
1282
        super(TestProcessEntry, self).setUp()
 
1283
        orig = dirstate._process_entry
 
1284
        def cleanup():
 
1285
            dirstate._process_entry = orig
 
1286
        self.addCleanup(cleanup)
 
1287
        dirstate._process_entry = self._process_entry
 
1288
 
 
1289
    def assertChangedFileIds(self, expected, tree):
 
1290
        tree.lock_read()
 
1291
        try:
 
1292
            file_ids = [info[0] for info
 
1293
                        in tree.iter_changes(tree.basis_tree())]
 
1294
        finally:
 
1295
            tree.unlock()
 
1296
        self.assertEqual(sorted(expected), sorted(file_ids))
 
1297
 
 
1298
    def test_simple_changes(self):
 
1299
        tree = self.make_branch_and_tree('tree')
 
1300
        self.build_tree(['tree/file'])
 
1301
        tree.add(['file'], ['file-id'])
 
1302
        self.assertChangedFileIds([tree.get_root_id(), 'file-id'], tree)
 
1303
        tree.commit('one')
 
1304
        self.assertChangedFileIds([], tree)
 
1305
 
 
1306
    def test_sha1provider_stat_and_sha1_used(self):
 
1307
        tree = self.make_branch_and_tree('tree')
 
1308
        self.build_tree(['tree/file'])
 
1309
        tree.add(['file'], ['file-id'])
 
1310
        tree.commit('one')
 
1311
        tree.lock_write()
 
1312
        self.addCleanup(tree.unlock)
 
1313
        state = tree._current_dirstate()
 
1314
        state._sha1_provider = UppercaseSHA1Provider()
 
1315
        self.assertChangedFileIds(['file-id'], tree)
 
1316