Rev 4265: Modernize dirstate helpers tests parametrization. in file:///home/vila/src/bzr/bugs/355454-unicode-warning/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Fri Apr 17 13:42:51 BST 2009
At file:///home/vila/src/bzr/bugs/355454-unicode-warning/
------------------------------------------------------------
revno: 4265
revision-id: v.ladeuil+lp at free.fr-20090417124250-vb9zcpl3rgfu0uop
parent: v.ladeuil+lp at free.fr-20090417085831-vg404ie0lsc1kpgw
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 355454-unicode-warning
timestamp: Fri 2009-04-17 14:42:50 +0200
message:
Modernize dirstate helpers tests parametrization.
* bzrlib/tests/test__dirstate_helpers.py:
(load_tests): Add parametrized tests for C/Python dirstate helpers
on top dir readers ones.
(TestUpdateEntry): Use parametrization facilities and load_tests
instead of inheritance.
(TestUpdateEntry.test_sha1provider_sha1_used): Ouch ! Direct use
of dirstate.update_entry, while correct now, wasn't respecting the
parametrization before (set_update_entry wasn't called).
(TestProcessEntry): Use parametrization facilities and load_tests
instead of inheritance.
-------------- next part --------------
=== modified file 'bzrlib/tests/test__dirstate_helpers.py'
--- a/bzrlib/tests/test__dirstate_helpers.py 2009-04-16 14:13:57 +0000
+++ b/bzrlib/tests/test__dirstate_helpers.py 2009-04-17 12:42:50 +0000
@@ -31,33 +31,64 @@
test_osutils,
)
+try:
+ from bzrlib import _dirstate_helpers_c
+ has_dirstate_helpers_c = True
+except ImportError:
+ has_dirstate_helpers_c = False
+
+
+class _CompiledDirstateHelpersFeature(tests.Feature):
+ def _probe(self):
+ return has_dirstate_helpers_c
+
+ def feature_name(self):
+ return 'bzrlib._dirstate_helpers_c'
+CompiledDirstateHelpersFeature = _CompiledDirstateHelpersFeature()
+
def load_tests(basic_tests, module, loader):
- # FIXME: we should also parametrize agsinst C/Python
+ # FIXME: we should also parametrize agsinst Sha1Providers !
suite = loader.suiteClass()
+ remaining_tests = basic_tests
+
+ dir_reader_scenarios = test_osutils.dir_reader_scenarios()
+
+ ue_scenarios = [('dirstate_Python',
+ {'update_entry': dirstate.py_update_entry})]
+ if has_dirstate_helpers_c:
+ c_scenario = ('dirstate_C',
+ {'update_entry': _dirstate_helpers_c.update_entry})
+ ue_scenarios.append(c_scenario)
+ process_entry_tests, remaining_tests = tests.split_suite_by_condition(
+ remaining_tests, tests.condition_isinstance(TestUpdateEntry))
+ tests.multiply_tests(process_entry_tests,
+ tests.multiply_scenarios(dir_reader_scenarios,
+ ue_scenarios),
+ suite)
+
+ pe_scenarios = [('dirstate_Python',
+ {'_process_entry': dirstate.ProcessEntryPython})]
+ if has_dirstate_helpers_c:
+ c_scenario = ('dirstate_C',
+ {'_process_entry': _dirstate_helpers_c.ProcessEntryC})
+ pe_scenarios.append(c_scenario)
+ process_entry_tests, remaining_tests = tests.split_suite_by_condition(
+ remaining_tests, tests.condition_isinstance(TestProcessEntry))
+ tests.multiply_tests(process_entry_tests,
+ tests.multiply_scenarios(dir_reader_scenarios,
+ pe_scenarios),
+ suite)
+
dir_reader_tests, remaining_tests = tests.split_suite_by_condition(
- basic_tests, tests.condition_isinstance(
+ remaining_tests, tests.condition_isinstance(
test_dirstate.TestCaseWithDirState))
- tests.multiply_tests(dir_reader_tests,
- test_osutils.dir_reader_scenarios(), suite)
+ tests.multiply_tests(dir_reader_tests, dir_reader_scenarios, suite)
suite.addTest(remaining_tests)
+
return suite
-class _CompiledDirstateHelpersFeature(tests.Feature):
- def _probe(self):
- try:
- import bzrlib._dirstate_helpers_c
- except ImportError:
- return False
- return True
-
- def feature_name(self):
- return 'bzrlib._dirstate_helpers_c'
-
-CompiledDirstateHelpersFeature = _CompiledDirstateHelpersFeature()
-
-
class TestBisectPathMixin(object):
"""Test that _bisect_path_*() returns the expected values.
@@ -802,18 +833,25 @@
class TestUpdateEntry(test_dirstate.TestCaseWithDirState):
"""Test the DirState.update_entry functions"""
+ # Set by load_tests
+ update_entry = None
+
+ def setUp(self):
+ super(TestUpdateEntry, self).setUp()
+ orig = dirstate.update_entry
+ def cleanup():
+ dirstate.update_entry = orig
+ self.addCleanup(cleanup)
+ dirstate.update_entry = self.update_entry
+
def get_state_with_a(self):
"""Create a DirState tracking a single object named 'a'"""
state = test_dirstate.InstrumentedDirState.initialize('dirstate')
self.addCleanup(state.unlock)
state.add('a', 'a-id', 'file', None, '')
entry = state._get_entry(0, path_utf8='a')
- self.set_update_entry()
return state, entry
- def set_update_entry(self):
- self.update_entry = dirstate.py_update_entry
-
def test_observed_sha1_cachable(self):
state, entry = self.get_state_with_a()
atime = time.time() - 10
@@ -1034,7 +1072,6 @@
state._dirblock_state)
def test_update_entry_tree_reference(self):
- self.set_update_entry()
state = test_dirstate.InstrumentedDirState.initialize('dirstate')
self.addCleanup(state.unlock)
state.add('r', 'r-id', 'tree-reference', None, '')
@@ -1076,6 +1113,7 @@
return packed_stat
+ # FIXME: Add unicode version
def create_and_test_symlink(self, state, entry):
"""Create a symlink at 'a' and verify the state finds it.
@@ -1178,8 +1216,8 @@
self.assertEqual([('f', '', 14, True, dirstate.DirState.NULLSTAT)],
entry[1])
- # Make the disk object look old enough to cache (but it won't cache the sha
- # as it is a new file).
+ # Make the disk object look old enough to cache (but it won't cache the
+ # sha as it is a new file).
state.adjust_time(+20)
digest = 'b50e5406bb5e153ebbeb20268fcf37c87e1ecfb6'
self.update_entry(state, entry, abspath='a', stat_value=stat_value)
@@ -1206,8 +1244,8 @@
entry = state._get_entry(0, path_utf8='a file')
state._sha_cutoff_time()
state._cutoff_time += 10
- sha1 = dirstate.update_entry(state, entry, 'tree/a file',
- os.lstat('tree/a file'))
+ sha1 = self.update_entry(state, entry, 'tree/a file',
+ os.lstat('tree/a file'))
self.assertEqual(expected_sha, sha1)
def test_sha1provider_stat_and_sha1_used(self):
@@ -1218,8 +1256,8 @@
state._sha1_provider = UppercaseSHA1Provider()
# If we used the standard provider, it would look like nothing has
# changed
- file_ids_changed = [change[0] for change
- in tree.iter_changes(tree.basis_tree())]
+ file_ids_changed = [change[0] for change
+ in tree.iter_changes(tree.basis_tree())]
self.assertEqual(['a-file-id'], file_ids_changed)
@@ -1240,29 +1278,18 @@
return statvalue, sha1
-class TestCompiledUpdateEntry(TestUpdateEntry):
- """Test the pyrex implementation of _read_dirblocks"""
-
- _test_needs_features = [CompiledDirstateHelpersFeature]
-
- def set_update_entry(self):
- from bzrlib._dirstate_helpers_c import update_entry
- self.update_entry = update_entry
-
-
-class TestProcessEntryPython(test_dirstate.TestCaseWithDirState):
+class TestProcessEntry(test_dirstate.TestCaseWithDirState):
+
+ # Set by load_tests
+ _process_entry = None
def setUp(self):
- super(TestProcessEntryPython, self).setUp()
- self.setup_process_entry()
-
- def setup_process_entry(self):
- from bzrlib import dirstate
+ super(TestProcessEntry, self).setUp()
orig = dirstate._process_entry
def cleanup():
dirstate._process_entry = orig
self.addCleanup(cleanup)
- dirstate._process_entry = dirstate.ProcessEntryPython
+ dirstate._process_entry = self._process_entry
def assertChangedFileIds(self, expected, tree):
tree.lock_read()
@@ -1292,15 +1319,3 @@
state._sha1_provider = UppercaseSHA1Provider()
self.assertChangedFileIds(['file-id'], tree)
-
-class TestProcessEntryC(TestProcessEntryPython):
- _test_needs_features = [CompiledDirstateHelpersFeature]
-
- def setup_process_entry(self):
- from bzrlib import _dirstate_helpers_c
- orig = dirstate._process_entry
- def cleanup():
- dirstate._process_entry = orig
- self.addCleanup(cleanup)
- dirstate._process_entry = _dirstate_helpers_c.ProcessEntryC
-
More information about the bazaar-commits
mailing list