diff options
Diffstat (limited to 'subversion/bindings/swig/python/tests/wc.py')
-rw-r--r-- | subversion/bindings/swig/python/tests/wc.py | 209 |
1 files changed, 114 insertions, 95 deletions
diff --git a/subversion/bindings/swig/python/tests/wc.py b/subversion/bindings/swig/python/tests/wc.py index 07f7ded..b6806d2 100644 --- a/subversion/bindings/swig/python/tests/wc.py +++ b/subversion/bindings/swig/python/tests/wc.py @@ -19,12 +19,7 @@ # # from sys import version_info # For Python version check -if version_info[0] >= 3: - # Python >=3.0 - from io import StringIO -else: - # Python <3.0 - from cStringIO import StringIO +from io import BytesIO import unittest, os, tempfile, setup_path, binascii import svn.diff from svn import core, repos, wc, client @@ -61,10 +56,10 @@ class SubversionWorkingCopyTestCase(unittest.TestCase): wc.entry(self.path, self.wc, True) def test_lock(self): - readme_path = '%s/trunk/README.txt' % self.path + readme_path = b'%s/trunk/README.txt' % self.path lock = core.svn_lock_create(core.Pool()) - lock.token = 'http://svnbook.org/nightly/en/svn.advanced.locking.html' + lock.token = b'http://svnbook.org/nightly/en/svn.advanced.locking.html' wc.add_lock(readme_path, lock, self.wc) self.assertEqual(True, wc.adm_locked(self.wc)) @@ -78,23 +73,23 @@ class SubversionWorkingCopyTestCase(unittest.TestCase): self.assertEqual(self.path, wc.adm_access_path(self.wc)) def test_is_adm_dir(self): - self.assert_(wc.is_adm_dir(".svn")) - self.failIf(wc.is_adm_dir(".foosvn")) + self.assertTrue(wc.is_adm_dir(b".svn")) + self.assertFalse(wc.is_adm_dir(b".foosvn")) def test_get_adm_dir(self): - self.assert_(isinstance(wc.get_adm_dir(), basestring)) + self.assertTrue(isinstance(wc.get_adm_dir(), bytes)) def test_set_adm_dir(self): - self.assertRaises(SubversionException, wc.set_adm_dir, ".foobar") - self.assert_(wc.is_adm_dir(".svn")) - self.failIf(wc.is_adm_dir("_svn")) - self.failIf(wc.is_adm_dir(".foobar")) - wc.set_adm_dir("_svn") - self.assert_(wc.is_adm_dir("_svn")) - self.assertEqual("_svn", wc.get_adm_dir()) - wc.set_adm_dir(".svn") - self.failIf(wc.is_adm_dir("_svn")) - self.assertEqual(".svn", wc.get_adm_dir()) + self.assertRaises(SubversionException, wc.set_adm_dir, b".foobar") + self.assertTrue(wc.is_adm_dir(b".svn")) + self.assertFalse(wc.is_adm_dir(b"_svn")) + self.assertFalse(wc.is_adm_dir(b".foobar")) + wc.set_adm_dir(b"_svn") + self.assertTrue(wc.is_adm_dir(b"_svn")) + self.assertEqual(b"_svn", wc.get_adm_dir()) + wc.set_adm_dir(b".svn") + self.assertFalse(wc.is_adm_dir(b"_svn")) + self.assertEqual(b".svn", wc.get_adm_dir()) def test_init_traversal_info(self): wc.init_traversal_info() @@ -127,8 +122,8 @@ class SubversionWorkingCopyTestCase(unittest.TestCase): pass # Remove trunk/README.txt - readme_path = '%s/trunk/README.txt' % self.path - self.assert_(os.path.exists(readme_path)) + readme_path = b'%s/trunk/README.txt' % self.path + self.assertTrue(os.path.exists(readme_path)) os.remove(readme_path) # Restore trunk/README.txt using crawl_revision2 @@ -138,8 +133,8 @@ class SubversionWorkingCopyTestCase(unittest.TestCase): True, True, False, notify, info) # Check that the report finished - self.assert_(reporter.finished_report) - self.assertEqual([''], set_paths) + self.assertTrue(reporter.finished_report) + self.assertEqual([b''], set_paths) self.assertEqual(1, len(infos)) # Check content of infos object @@ -152,7 +147,7 @@ class SubversionWorkingCopyTestCase(unittest.TestCase): wc.create_notify(self.path, wc.notify_add) def test_check_wc(self): - self.assert_(wc.check_wc(self.path) > 0) + self.assertTrue(wc.check_wc(self.path) > 0) def test_get_ancestry(self): self.assertEqual([self.repos_uri, 12], @@ -164,7 +159,6 @@ class SubversionWorkingCopyTestCase(unittest.TestCase): def test_status_editor(self): paths = [] def status_func(target, status): - self.assert_(target.startswith(self.path)) paths.append(target) (anchor_access, target_access, @@ -181,54 +175,79 @@ class SubversionWorkingCopyTestCase(unittest.TestCase): None, # traversal_info ) editor.close_edit(edit_baton) - self.assert_(len(paths) > 0) + self.assertTrue(len(paths) > 0) + for target in paths: + self.assertTrue(target.startswith(self.path)) + + def test_status_editor_callback_exception(self): + """test case for status_editor call back not to be crashed by Python exception""" + def status_func(target, status): + # Note: exception with in this call back doesn't propagate to + # the caller + raise AssertionError('intentional exception') + + (anchor_access, target_access, + target) = wc.adm_open_anchor(self.path, False, -1, None) + (editor, edit_baton, set_locks_baton, + edit_revision) = wc.get_status_editor2(anchor_access, + target, + None, # SvnConfig + True, # recursive + True, # get_all + False, # no_ignore + status_func, + None, # cancel_func + None, # traversal_info + ) + editor.close_edit(edit_baton) def test_is_normal_prop(self): - self.failIf(wc.is_normal_prop('svn:wc:foo:bar')) - self.failIf(wc.is_normal_prop('svn:entry:foo:bar')) - self.assert_(wc.is_normal_prop('svn:foo:bar')) - self.assert_(wc.is_normal_prop('foreign:foo:bar')) + self.assertFalse(wc.is_normal_prop(b'svn:wc:foo:bar')) + self.assertFalse(wc.is_normal_prop(b'svn:entry:foo:bar')) + self.assertTrue(wc.is_normal_prop(b'svn:foo:bar')) + self.assertTrue(wc.is_normal_prop(b'foreign:foo:bar')) def test_is_wc_prop(self): - self.assert_(wc.is_wc_prop('svn:wc:foo:bar')) - self.failIf(wc.is_wc_prop('svn:entry:foo:bar')) - self.failIf(wc.is_wc_prop('svn:foo:bar')) - self.failIf(wc.is_wc_prop('foreign:foo:bar')) + self.assertTrue(wc.is_wc_prop(b'svn:wc:foo:bar')) + self.assertFalse(wc.is_wc_prop(b'svn:entry:foo:bar')) + self.assertFalse(wc.is_wc_prop(b'svn:foo:bar')) + self.assertFalse(wc.is_wc_prop(b'foreign:foo:bar')) def test_is_entry_prop(self): - self.assert_(wc.is_entry_prop('svn:entry:foo:bar')) - self.failIf(wc.is_entry_prop('svn:wc:foo:bar')) - self.failIf(wc.is_entry_prop('svn:foo:bar')) - self.failIf(wc.is_entry_prop('foreign:foo:bar')) + self.assertTrue(wc.is_entry_prop(b'svn:entry:foo:bar')) + self.assertFalse(wc.is_entry_prop(b'svn:wc:foo:bar')) + self.assertFalse(wc.is_entry_prop(b'svn:foo:bar')) + self.assertFalse(wc.is_entry_prop(b'foreign:foo:bar')) def test_get_prop_diffs(self): - wc.prop_set("foreign:foo", "bla", self.path, self.wc) - self.assertEquals([{"foreign:foo": "bla"}, {}], + wc.prop_set(b"foreign:foo", b"bla", self.path, self.wc) + self.assertEqual([{b"foreign:foo": b"bla"}, {}], wc.get_prop_diffs(self.path, self.wc)) def test_get_pristine_copy_path(self): - path_to_file = '%s/trunk/README.txt' % self.path + path_to_file = b'%s/trunk/README.txt' % self.path path_to_text_base = wc.get_pristine_copy_path(path_to_file) - text_base = open(path_to_text_base).read() + with open(path_to_text_base, 'rb') as fp: + text_base = fp.read() # TODO: This test should modify the working file first, to ensure the # path isn't just the path to the working file. - self.assertEqual(text_base, 'A test.\n') + self.assertEqual(text_base, b'A test.\n') def test_entries_read(self): entries = wc.entries_read(self.wc, True) - keys = list(entries.keys()) + keys = core._as_list(entries.keys()) keys.sort() - self.assertEqual(['', 'branches', 'tags', 'trunk'], keys) + self.assertEqual([b'', b'branches', b'tags', b'trunk'], keys) def test_get_ignores(self): - self.assert_(isinstance(wc.get_ignores(None, self.wc), list)) + self.assertTrue(isinstance(wc.get_ignores(None, self.wc), list)) def test_commit(self): # Replace README.txt's contents, using binary mode so we know the # exact contents even on Windows, and therefore the MD5 checksum. - readme_path = '%s/trunk/README.txt' % self.path + readme_path = b'%s/trunk/README.txt' % self.path fp = open(readme_path, 'wb') - fp.write('hello\n') + fp.write(b'hello\n') fp.close() # Setup ra_ctx. @@ -240,7 +259,7 @@ class SubversionWorkingCopyTestCase(unittest.TestCase): commit_info = [None] def commit_cb(_commit_info, pool): commit_info[0] = _commit_info - (editor, edit_baton) = ra.get_commit_editor2(ra_ctx, 'log message', + (editor, edit_baton) = ra.get_commit_editor2(ra_ctx, b'log message', commit_cb, None, False) @@ -254,7 +273,7 @@ class SubversionWorkingCopyTestCase(unittest.TestCase): False, editor, baton, pool) return baton try: - delta.path_driver(editor, edit_baton, -1, ['trunk/README.txt'], + delta.path_driver(editor, edit_baton, -1, [b'trunk/README.txt'], driver_cb) editor.close_edit(edit_baton) except: @@ -269,9 +288,9 @@ class SubversionWorkingCopyTestCase(unittest.TestCase): (commit_info,) = commit_info # Assert the commit. - self.assertEquals(binascii.b2a_hex(checksum), - 'b1946ac92492d2347c6235b4d2611184') - self.assertEquals(commit_info.revision, 13) + self.assertEqual(binascii.b2a_hex(checksum), + b'b1946ac92492d2347c6235b4d2611184') + self.assertEqual(commit_info.revision, 13) # Bump working copy state. wc.process_committed4(readme_path, @@ -282,10 +301,10 @@ class SubversionWorkingCopyTestCase(unittest.TestCase): # Assert bumped state. entry = wc.entry(readme_path, self.wc, False) - self.assertEquals(entry.revision, commit_info.revision) - self.assertEquals(entry.schedule, wc.schedule_normal) - self.assertEquals(entry.cmt_rev, commit_info.revision) - self.assertEquals(entry.cmt_date, + self.assertEqual(entry.revision, commit_info.revision) + self.assertEqual(entry.schedule, wc.schedule_normal) + self.assertEqual(entry.cmt_rev, commit_info.revision) + self.assertEqual(entry.cmt_date, core.svn_time_from_cstring(commit_info.date)) def test_diff_editor4(self): @@ -294,14 +313,14 @@ class SubversionWorkingCopyTestCase(unittest.TestCase): url = self.repos_uri # cause file_changed: Replace README.txt's contents. - readme_path = '%s/trunk/README.txt' % self.path - fp = open(readme_path, 'w') - fp.write('hello\n') + readme_path = b'%s/trunk/README.txt' % self.path + fp = open(readme_path, 'wb') + fp.write(b'hello\n') fp.close() # cause file_added: Create readme3. - readme3_path = '%s/trunk/readme3' % self.path - fp = open(readme3_path, 'w') - fp.write('hello\n') + readme3_path = b'%s/trunk/readme3' % self.path + fp = open(readme3_path, 'wb') + fp.write(b'hello\n') fp.close() wc.add2(readme3_path, wc.adm_probe_retrieve(self.wc, @@ -311,7 +330,7 @@ class SubversionWorkingCopyTestCase(unittest.TestCase): None, # notify_func pool) # cause file_deleted: Delete README2.txt. - readme2_path = '%s/trunk/README2.txt' % self.path + readme2_path = b'%s/trunk/README2.txt' % self.path wc.delete3(readme2_path, wc.adm_probe_retrieve(self.wc, os.path.dirname(readme2_path), pool), @@ -320,8 +339,8 @@ class SubversionWorkingCopyTestCase(unittest.TestCase): False, # keep_local pool) # cause dir_props_changed: ps testprop testval dir1/dir2 - dir2_path = '%s/trunk/dir1/dir2' % self.path - wc.prop_set2('testprop', 'testval', dir2_path, + dir2_path = b'%s/trunk/dir1/dir2' % self.path + wc.prop_set2(b'testprop', b'testval', dir2_path, wc.adm_probe_retrieve(self.wc, os.path.dirname(dir2_path), pool), False, # skip_checks @@ -331,7 +350,7 @@ class SubversionWorkingCopyTestCase(unittest.TestCase): # Save prop changes. got_prop_changes = [] def props_changed(path, propchanges): - for (name, value) in propchanges.items(): + for (name, value) in core._as_list(propchanges.items()): (kind, _) = core.svn_property_kind(name) if kind != core.svn_prop_regular_kind: continue @@ -342,16 +361,16 @@ class SubversionWorkingCopyTestCase(unittest.TestCase): def write_diff(path, left, right): options = svn.diff.file_options_create() diff = svn.diff.file_diff_2(left, right, options, pool) - original_header = modified_header = '' - encoding = 'utf8' + original_header = modified_header = b'' + encoding = b'utf8' relative_to_dir = None - sio = StringIO() - svn.diff.file_output_unified3(sio, diff, + bio = BytesIO() + svn.diff.file_output_unified3(bio, diff, left, right, original_header, modified_header, encoding, relative_to_dir, options.show_c_function, pool) - got_diffs[path[len(self.path) + 1:]] = sio.getvalue().splitlines() + got_diffs[path[len(self.path) + 1:]] = bio.getvalue().splitlines() # Diff callbacks that call props_changed and write_diff. contentstate = propstate = state = wc.notify_state_unknown @@ -383,7 +402,7 @@ class SubversionWorkingCopyTestCase(unittest.TestCase): # Setup wc diff editor. (editor, edit_baton) = wc.get_diff_editor4( - self.wc, '', diff_callbacks, depth, + self.wc, b'', diff_callbacks, depth, False, # ignore_ancestry False, # use_text_base False, # reverse_order @@ -400,39 +419,39 @@ class SubversionWorkingCopyTestCase(unittest.TestCase): (reporter, report_baton) = ra.do_diff3( ra_ctx, head, # versus_url revision - '', # diff_target + b'', # diff_target depth, False, # ignore_ancestry True, # text_deltas url, # versus_url editor, edit_baton, pool) # Report wc state (pretty plain). - reporter.set_path(report_baton, '', head, depth, + reporter.set_path(report_baton, b'', head, depth, False, # start_empty None, # lock_token pool) reporter.finish_report(report_baton, pool) # Assert we got the right diff. - expected_prop_changes = [('trunk/dir1/dir2', - 'testprop', 'testval')] + expected_prop_changes = [(b'trunk/dir1/dir2', + b'testprop', b'testval')] expected_diffs = { - 'trunk/readme3': - ['--- ', - '+++ ', - '@@ -0,0 +1 @@', - '+hello'], - 'trunk/README.txt': - ['--- ', - '+++ ', - '@@ -1 +1 @@', - '-A test.', - '+hello'], - 'trunk/README2.txt': - ['--- ', - '+++ ', - '@@ -1 +0,0 @@', - '-A test.'], + b'trunk/readme3': + [b'--- ', + b'+++ ', + b'@@ -0,0 +1 @@', + b'+hello'], + b'trunk/README.txt': + [b'--- ', + b'+++ ', + b'@@ -1 +1 @@', + b'-A test.', + b'+hello'], + b'trunk/README2.txt': + [b'--- ', + b'+++ ', + b'@@ -1 +0,0 @@', + b'-A test.'], } self.assertEqual(got_prop_changes, expected_prop_changes) self.assertEqual(got_diffs, expected_diffs) |