Rev 4718: Add test parameterisation for Dirstate classes. in http://bazaar.launchpad.net/~lifeless/bzr/dirstate2
Robert Collins
robertc at robertcollins.net
Mon Sep 28 23:33:09 BST 2009
At http://bazaar.launchpad.net/~lifeless/bzr/dirstate2
------------------------------------------------------------
revno: 4718
revision-id: robertc at robertcollins.net-20090928223300-wgeoel86utggcmu6
parent: pqm at pqm.ubuntu.com-20090928042152-wt2kv0l6almf1f0f
committer: Robert Collins <robertc at robertcollins.net>
branch nick: dirstate2
timestamp: Tue 2009-09-29 08:33:00 +1000
message:
Add test parameterisation for Dirstate classes.
=== modified file 'bzrlib/tests/test_dirstate.py'
--- a/bzrlib/tests/test_dirstate.py 2009-08-17 03:33:56 +0000
+++ b/bzrlib/tests/test_dirstate.py 2009-09-28 22:33:00 +0000
@@ -50,8 +50,12 @@
basic_tests, tests.condition_isinstance(TestCaseWithDirState))
tests.multiply_tests(dir_reader_tests,
test_osutils.dir_reader_scenarios(), suite)
- suite.addTest(remaining_tests)
- return suite
+ dirstate_implementation_scenarios = [
+ ('dirstate1', {'_dirstate_class':dirstate.DirState}),
+ ]
+ tests.multiply_tests(suite, dirstate_implementation_scenarios,
+ remaining_tests)
+ return remaining_tests
class TestCaseWithDirState(tests.TestCaseWithTransport):
@@ -59,23 +63,24 @@
# Set by load_tests
_dir_reader_class = None
+ _dirstate_class = None
_native_to_unicode = None # Not used yet
def setUp(self):
tests.TestCaseWithTransport.setUp(self)
+ self.setDirReader()
+ def setDirReader(self):
# Save platform specific info and reset it
cur_dir_reader = osutils._selected_dir_reader
-
def restore():
osutils._selected_dir_reader = cur_dir_reader
self.addCleanup(restore)
-
osutils._selected_dir_reader = self._dir_reader_class()
def create_empty_dirstate(self):
"""Return a locked but empty dirstate"""
- state = dirstate.DirState.initialize('dirstate')
+ state = self._dirstate_class.initialize('dirstate')
return state
def create_dirstate_with_root(self):
@@ -163,7 +168,7 @@
dirblocks.append(('', [a_entry, b_entry, c_entry, d_entry]))
dirblocks.append(('a', [e_entry, f_entry]))
dirblocks.append(('b', [g_entry, h_entry]))
- state = dirstate.DirState.initialize('dirstate')
+ state = self._dirstate_class.initialize('dirstate')
state._validate()
try:
state._set_data([], dirblocks)
@@ -197,7 +202,7 @@
finally:
state.unlock()
del state
- state = dirstate.DirState.on_file('dirstate')
+ state = self._dirstate_class.on_file('dirstate')
state.lock_read()
try:
self.assertEqual(expected_result[1], list(state._iter_entries()))
@@ -280,13 +285,13 @@
('f', f_sha, f_len, False, revision_id),
]),
}
- state = dirstate.DirState.from_tree(tree, 'dirstate')
+ state = self._dirstate_class.from_tree(tree, 'dirstate')
try:
state.save()
finally:
state.unlock()
# Use a different object, to make sure nothing is pre-cached in memory.
- state = dirstate.DirState.on_file('dirstate')
+ state = self._dirstate_class.on_file('dirstate')
state.lock_read()
self.addCleanup(state.unlock)
self.assertEqual(dirstate.DirState.NOT_IN_MEMORY,
@@ -327,7 +332,7 @@
# okay as lock as we unlock 'state' first.
state.unlock()
try:
- new_state = dirstate.DirState.from_tree(tree, 'dirstate')
+ new_state = self._dirstate_class.from_tree(tree, 'dirstate')
try:
new_state.save()
finally:
@@ -366,7 +371,7 @@
state.unlock()
try:
- new_state = dirstate.DirState.from_tree(tree, 'dirstate')
+ new_state = self._dirstate_class.from_tree(tree, 'dirstate')
try:
new_state.save()
finally:
@@ -386,7 +391,7 @@
(('', '', tree.get_root_id()), # common details
[('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree
])])
- state = dirstate.DirState.from_tree(tree, 'dirstate')
+ state = self._dirstate_class.from_tree(tree, 'dirstate')
state._validate()
self.check_state_with_reopen(expected_result, state)
@@ -400,7 +405,7 @@
[('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree
('d', '', 0, False, rev_id), # first parent details
])])
- state = dirstate.DirState.from_tree(tree, 'dirstate')
+ state = self._dirstate_class.from_tree(tree, 'dirstate')
self.check_state_with_reopen(expected_result, state)
state.lock_read()
try:
@@ -421,7 +426,7 @@
('d', '', 0, False, rev_id), # first parent details
('d', '', 0, False, rev_id), # second parent details
])])
- state = dirstate.DirState.from_tree(tree, 'dirstate')
+ state = self._dirstate_class.from_tree(tree, 'dirstate')
self.check_state_with_reopen(expected_result, state)
state.lock_read()
try:
@@ -438,7 +443,7 @@
(('', '', tree.get_root_id()), # common details
[('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree
])])
- state = dirstate.DirState.from_tree(tree, 'dirstate')
+ state = self._dirstate_class.from_tree(tree, 'dirstate')
self.check_state_with_reopen(expected_result, state)
def get_tree_with_a_file(self):
@@ -459,7 +464,7 @@
[('f', '', 0, False, dirstate.DirState.NULLSTAT), # current
]),
])
- state = dirstate.DirState.from_tree(tree, 'dirstate')
+ state = self._dirstate_class.from_tree(tree, 'dirstate')
self.check_state_with_reopen(expected_result, state)
def test_1_parents_not_empty_to_dirstate(self):
@@ -480,7 +485,7 @@
rev_id), # first parent
]),
])
- state = dirstate.DirState.from_tree(tree, 'dirstate')
+ state = self._dirstate_class.from_tree(tree, 'dirstate')
self.check_state_with_reopen(expected_result, state)
def test_2_parents_not_empty_to_dirstate(self):
@@ -510,7 +515,7 @@
rev_id2), # second parent
]),
])
- state = dirstate.DirState.from_tree(tree, 'dirstate')
+ state = self._dirstate_class.from_tree(tree, 'dirstate')
self.check_state_with_reopen(expected_result, state)
def test_colliding_fileids(self):
@@ -528,7 +533,7 @@
parents.append((revision_id,
tree.branch.repository.revision_tree(revision_id)))
# now fold these trees into a dirstate
- state = dirstate.DirState.initialize('dirstate')
+ state = self._dirstate_class.initialize('dirstate')
try:
state.set_parent_trees(parents, [])
state._validate()
@@ -540,7 +545,7 @@
def test_construct_with_path(self):
tree = self.make_branch_and_tree('tree')
- state = dirstate.DirState.from_tree(tree, 'dirstate.from_tree')
+ state = self._dirstate_class.from_tree(tree, 'dirstate.from_tree')
# we want to be able to get the lines of the dirstate that we will
# write to disk.
lines = state.get_lines()
@@ -556,13 +561,13 @@
[('d', '', 0, False, dirstate.DirState.NULLSTAT),
])
])
- state = dirstate.DirState.on_file('dirstate')
+ state = self._dirstate_class.on_file('dirstate')
state.lock_write() # check_state_with_reopen will save() and unlock it
self.check_state_with_reopen(expected_result, state)
def test_can_save_clean_on_file(self):
tree = self.make_branch_and_tree('tree')
- state = dirstate.DirState.from_tree(tree, 'dirstate')
+ state = self._dirstate_class.from_tree(tree, 'dirstate')
try:
# doing a save should work here as there have been no changes.
state.save()
@@ -573,7 +578,7 @@
def test_can_save_in_read_lock(self):
self.build_tree(['a-file'])
- state = dirstate.DirState.initialize('dirstate')
+ state = self._dirstate_class.initialize('dirstate')
try:
# No stat and no sha1 sum.
state.add('a-file', 'a-file-id', 'file', None, '')
@@ -582,7 +587,7 @@
state.unlock()
# Now open in readonly mode
- state = dirstate.DirState.on_file('dirstate')
+ state = self._dirstate_class.on_file('dirstate')
state.lock_read()
try:
entry = state._get_entry(0, path_utf8='a-file')
@@ -613,7 +618,7 @@
state.unlock()
# Re-open the file, and ensure that the state has been updated.
- state = dirstate.DirState.on_file('dirstate')
+ state = self._dirstate_class.on_file('dirstate')
state.lock_read()
try:
entry = state._get_entry(0, path_utf8='a-file')
@@ -624,7 +629,7 @@
def test_save_fails_quietly_if_locked(self):
"""If dirstate is locked, save will fail without complaining."""
self.build_tree(['a-file'])
- state = dirstate.DirState.initialize('dirstate')
+ state = self._dirstate_class.initialize('dirstate')
try:
# No stat and no sha1 sum.
state.add('a-file', 'a-file-id', 'file', None, '')
@@ -632,7 +637,7 @@
finally:
state.unlock()
- state = dirstate.DirState.on_file('dirstate')
+ state = self._dirstate_class.on_file('dirstate')
state.lock_read()
try:
entry = state._get_entry(0, path_utf8='a-file')
@@ -647,7 +652,7 @@
# read lock.
# TODO: jam 20070315 Ideally this would be locked by another
# process. To make sure the file is really OS locked.
- state2 = dirstate.DirState.on_file('dirstate')
+ state2 = self._dirstate_class.on_file('dirstate')
state2.lock_read()
try:
# This won't actually write anything, because it couldn't grab
@@ -664,7 +669,7 @@
state.unlock()
# The file on disk should not be modified.
- state = dirstate.DirState.on_file('dirstate')
+ state = self._dirstate_class.on_file('dirstate')
state.lock_read()
try:
entry = state._get_entry(0, path_utf8='a-file')
@@ -674,7 +679,7 @@
def test_save_refuses_if_changes_aborted(self):
self.build_tree(['a-file', 'a-dir/'])
- state = dirstate.DirState.initialize('dirstate')
+ state = self._dirstate_class.initialize('dirstate')
try:
# No stat and no sha1 sum.
state.add('a-file', 'a-file-id', 'file', None, '')
@@ -690,7 +695,7 @@
[('f', '', 0, False, dirstate.DirState.NULLSTAT)])]),
]
- state = dirstate.DirState.on_file('dirstate')
+ state = self._dirstate_class.on_file('dirstate')
state.lock_write()
try:
state._read_dirblocks_if_needed()
@@ -703,7 +708,7 @@
finally:
state.unlock()
- state = dirstate.DirState.on_file('dirstate')
+ state = self._dirstate_class.on_file('dirstate')
state.lock_read()
try:
state._read_dirblocks_if_needed()
@@ -720,9 +725,9 @@
[('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree
])
])
- state = dirstate.DirState.initialize('dirstate')
+ state = self._dirstate_class.initialize('dirstate')
try:
- self.assertIsInstance(state, dirstate.DirState)
+ self.assertIsInstance(state, self._dirstate_class)
lines = state.get_lines()
finally:
state.unlock()
@@ -750,7 +755,7 @@
expected_result = [], [
(('', '', root_id), [
('d', '', 0, False, dirstate.DirState.NULLSTAT)])]
- state = dirstate.DirState.initialize('dirstate')
+ state = self._dirstate_class.initialize('dirstate')
try:
state.set_state_from_inventory(inv)
self.assertEqual(dirstate.DirState.IN_MEMORY_UNMODIFIED,
@@ -852,7 +857,7 @@
('', 'a-b', 'a-b-id', 'd'),
('a-b', 'bar', 'bar-id', 'f'),
]
- state = dirstate.DirState.initialize('dirstate')
+ state = self._dirstate_class.initialize('dirstate')
try:
state.set_state_from_inventory(inv)
values = []
@@ -870,7 +875,7 @@
def test_set_path_id_no_parents(self):
"""The id of a path can be changed trivally with no parents."""
- state = dirstate.DirState.initialize('dirstate')
+ state = self._dirstate_class.initialize('dirstate')
try:
# check precondition to be sure the state does change appropriately.
self.assertEqual(
@@ -886,7 +891,7 @@
state.save()
finally:
state.unlock()
- state = dirstate.DirState.on_file('dirstate')
+ state = self._dirstate_class.on_file('dirstate')
state.lock_read()
try:
state._validate()
@@ -901,7 +906,7 @@
mt.set_root_id('TREE_ROOT')
mt.commit('foo', rev_id='parent-revid')
rt = mt.branch.repository.revision_tree('parent-revid')
- state = dirstate.DirState.initialize('dirstate')
+ state = self._dirstate_class.initialize('dirstate')
state._validate()
try:
state.set_parent_trees([('parent-revid', rt)], ghosts=[])
@@ -925,7 +930,7 @@
finally:
state.unlock()
# now flush & check we get the same
- state = dirstate.DirState.on_file('dirstate')
+ state = self._dirstate_class.on_file('dirstate')
state.lock_read()
try:
state._validate()
@@ -958,7 +963,7 @@
root_id = tree2.get_root_id()
finally:
tree2.unlock()
- state = dirstate.DirState.initialize('dirstate')
+ state = self._dirstate_class.initialize('dirstate')
try:
state.set_path_id('', root_id)
state.set_parent_trees(
@@ -973,7 +978,7 @@
state._validate()
finally:
state.unlock()
- state = dirstate.DirState.on_file('dirstate')
+ state = self._dirstate_class.on_file('dirstate')
state.lock_write()
try:
self.assertEqual([revid1, revid2, 'ghost-rev'],
@@ -1044,7 +1049,7 @@
revid2.encode('utf8'))
])
]
- state = dirstate.DirState.initialize('dirstate')
+ state = self._dirstate_class.initialize('dirstate')
try:
state.set_path_id('', root_id)
state.set_parent_trees(
@@ -1067,7 +1072,7 @@
self.build_tree(['a file'])
stat = os.lstat('a file')
# the 1*20 is the sha1 pretend value.
- state = dirstate.DirState.initialize('dirstate')
+ state = self._dirstate_class.initialize('dirstate')
expected_entries = [
(('', '', 'TREE_ROOT'), [
('d', '', 0, False, dirstate.DirState.NULLSTAT), # current tree
@@ -1084,7 +1089,7 @@
state.save()
finally:
state.unlock()
- state = dirstate.DirState.on_file('dirstate')
+ state = self._dirstate_class.on_file('dirstate')
state.lock_read()
self.addCleanup(state.unlock)
self.assertEqual(expected_entries, list(state._iter_entries()))
@@ -1097,7 +1102,7 @@
removing this copy of the test.
"""
self.build_tree(['unversioned/', 'unversioned/a file'])
- state = dirstate.DirState.initialize('dirstate')
+ state = self._dirstate_class.initialize('dirstate')
self.addCleanup(state.unlock)
self.assertRaises(errors.NotVersionedError, state.add,
'unversioned/a file', 'a-file-id', 'file', None, None)
@@ -1115,7 +1120,7 @@
('d', '', 0, False, dirstate.pack_stat(stat)), # current tree
]),
]
- state = dirstate.DirState.initialize('dirstate')
+ state = self._dirstate_class.initialize('dirstate')
try:
state.add('a dir', 'a dir id', 'directory', stat, None)
# having added it, it should be in the output of iter_entries.
@@ -1124,7 +1129,7 @@
state.save()
finally:
state.unlock()
- state = dirstate.DirState.on_file('dirstate')
+ state = self._dirstate_class.on_file('dirstate')
state.lock_read()
self.addCleanup(state.unlock)
state._validate()
@@ -1146,7 +1151,7 @@
False, dirstate.pack_stat(stat)), # current tree
]),
]
- state = dirstate.DirState.initialize('dirstate')
+ state = self._dirstate_class.initialize('dirstate')
try:
state.add(link_name, 'a link id', 'symlink', stat,
target.encode('UTF-8'))
@@ -1156,7 +1161,7 @@
state.save()
finally:
state.unlock()
- state = dirstate.DirState.on_file('dirstate')
+ state = self._dirstate_class.on_file('dirstate')
state.lock_read()
self.addCleanup(state.unlock)
self.assertEqual(expected_entries, list(state._iter_entries()))
@@ -1186,7 +1191,7 @@
dirstate.pack_stat(filestat)), # current tree details
]),
]
- state = dirstate.DirState.initialize('dirstate')
+ state = self._dirstate_class.initialize('dirstate')
try:
state.add('a dir', 'a dir id', 'directory', dirstat, None)
state.add('a dir/a file', 'a-file-id', 'file', filestat, '1'*20)
@@ -1196,14 +1201,14 @@
state.save()
finally:
state.unlock()
- state = dirstate.DirState.on_file('dirstate')
+ state = self._dirstate_class.on_file('dirstate')
state.lock_read()
self.addCleanup(state.unlock)
self.assertEqual(expected_entries, list(state._iter_entries()))
def test_add_tree_reference(self):
# make a dirstate and add a tree reference
- state = dirstate.DirState.initialize('dirstate')
+ state = self._dirstate_class.initialize('dirstate')
expected_entry = (
('', 'subdir', 'subdir-id'),
[('t', 'subtree-123123', 0, False,
@@ -1229,7 +1234,7 @@
self.assertEqual(entry, expected_entry)
def test_add_forbidden_names(self):
- state = dirstate.DirState.initialize('dirstate')
+ state = self._dirstate_class.initialize('dirstate')
self.addCleanup(state.unlock)
self.assertRaises(errors.BzrError,
state.add, '.', 'ass-id', 'directory', None, None)
@@ -1249,7 +1254,7 @@
tree1.add(['b'], ['b-id'])
root_id = tree1.get_root_id()
inv = tree1.inventory
- state = dirstate.DirState.initialize('dirstate')
+ state = self._dirstate_class.initialize('dirstate')
try:
# Set the initial state with 'b'
state.set_state_from_inventory(inv)
@@ -1304,7 +1309,7 @@
# first: a pointer to the current location
('a', 'dirname/basename', 0, False, ''),
]
- state = dirstate.DirState.initialize('dirstate')
+ state = self._dirstate_class.initialize('dirstate')
try:
self.assertEqual(
'\x00\x00a-root-value\x00'
@@ -1323,7 +1328,7 @@
# second: a pointer to the current location
('a', 'dirname/basename', 0, False, ''),
]
- state = dirstate.DirState.initialize('dirstate')
+ state = self._dirstate_class.initialize('dirstate')
try:
self.assertEqual(
'\x00\x00a-root-value\x00'
@@ -1356,7 +1361,7 @@
('f', 'sha1value', 23, False, packed_stat), # current tree details
]
dirblocks.append(('subdir', [file_entry2]))
- state = dirstate.DirState.initialize('dirstate')
+ state = self._dirstate_class.initialize('dirstate')
try:
state._set_data([], dirblocks)
expected_entries = [root_entries[0], subdir_entry, afile_entry,
@@ -1474,7 +1479,7 @@
finally:
state.unlock()
del state
- state = dirstate.DirState.on_file('dirstate')
+ state = self._dirstate_class.on_file('dirstate')
state.lock_read()
try:
self.assertEqual(dirstate.DirState.NOT_IN_MEMORY,
@@ -1567,7 +1572,7 @@
dirblocks.append(('', [a_entry, b_entry, c_entry, d_entry]))
dirblocks.append(('a', [e_entry, f_entry]))
dirblocks.append(('b', [g_entry, h_entry1, h_entry2, i_entry, j_entry]))
- state = dirstate.DirState.initialize('dirstate')
+ state = self._dirstate_class.initialize('dirstate')
state._validate()
try:
state._set_data(['parent'], dirblocks)
@@ -2081,7 +2086,7 @@
subtree.set_root_id('subtree')
tree.add_reference(subtree)
tree.add('subtree')
- state = dirstate.DirState.from_tree(tree, 'dirstate')
+ state = self._dirstate_class.from_tree(tree, 'dirstate')
key = ('', 'subtree', 'subtree')
expected = ('', [(key,
[('t', '', 0, False, 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')])])
More information about the bazaar-commits
mailing list