def test_conflict(self): """Test conflict api.""" rev = core.svn_opt_revision_t() rev.kind = core.svn_opt_revision_number rev.value.number = 0 path = self.temper.alloc_empty_dir('-conflict') client.checkout2(self.repos_uri, path, rev, rev, True, True, self.client_ctx) trunk_path = core.svn_dirent_join(path, b'trunk') # Create a conflicting path os.mkdir(core.svn_dirent_local_style(trunk_path)) rev.value.number = 2 client.update4((path,), rev, core.svn_depth_unknown, True, False, False, False, False, self.client_ctx) pool = core.Pool() conflict = client.conflict_get(trunk_path, self.client_ctx, pool) self.assertTrue(isinstance(conflict, client.svn_client_conflict_t)) conflict_opts = client.conflict_tree_get_resolution_options(conflict, self.client_ctx) self.assertTrue(isinstance(conflict_opts, list)) self.assert_all_instances_of(conflict_opts, client.svn_client_conflict_option_t) pool.clear()
def test_update4(self): """Test update and the notify function callbacks""" rev = core.svn_opt_revision_t() rev.kind = core.svn_opt_revision_number rev.value.number = 0 path = self.temper.alloc_empty_dir('-update') self.assertRaises(ValueError, client.checkout2, self.repos_uri, path, None, None, True, True, self.client_ctx) client.checkout2(self.repos_uri, path, rev, rev, True, True, self.client_ctx) def notify_func(path, action, kind, mime_type, content_state, prop_state, rev): self.notified_paths.append(path) self.client_ctx.notify_func = client.svn_swig_py_notify_func self.client_ctx.notify_baton = notify_func rev.value.number = 1 self.notified_paths = [] client.update4((path, ), rev, core.svn_depth_unknown, True, False, False, False, False, self.client_ctx) expected_paths = [ path, os.path.join(path, 'branches'), os.path.join(path, 'tags'), os.path.join(path, 'trunk'), path, path ] # All normal subversion apis process paths in Subversion's canonical format, # which isn't the platform specific format expected_paths = [x.replace(os.path.sep, '/') for x in expected_paths] self.notified_paths.sort() expected_paths.sort() self.assertEquals(self.notified_paths, expected_paths) def notify_func2(notify, pool): self.notified_paths.append(notify.path) self.client_ctx.notify_func2 = client.svn_swig_py_notify_func2 self.client_ctx.notify_baton2 = notify_func2 rev.value.number = 2 self.notified_paths = [] expected_paths = [ path, os.path.join(path, 'trunk', 'README.txt'), os.path.join(path, 'trunk'), path, path ] expected_paths = [x.replace(os.path.sep, '/') for x in expected_paths] client.update4((path, ), rev, core.svn_depth_unknown, True, False, False, False, False, self.client_ctx) self.notified_paths.sort() expected_paths.sort() self.assertEquals(self.notified_paths, expected_paths)
def test_info_file(self): """Test svn_client_info on working copy file and remote files.""" # This test requires a file /trunk/README.txt of size 8 bytes # in the repository. rev = core.svn_opt_revision_t() rev.kind = core.svn_opt_revision_head wc_path = core.svn_path_canonicalize(tempfile.mktemp()) client.checkout2(REPOS_URL, wc_path, rev, rev, True, True, self.client_ctx) adm_access = wc.adm_open3(None, wc_path, True, -1, None) try: # Test 1: Run info -r BASE. We expect the size value to be filled in. rev.kind = core.svn_opt_revision_base readme_path = '%s/trunk/README.txt' % wc_path readme_url = '%s/trunk/README.txt' % REPOS_URL client.info(readme_path, rev, rev, self.info_receiver, False, self.client_ctx) self.assertEqual(self.path, os.path.basename(readme_path)) self.info.assert_valid() self.assertEqual(self.info.working_size, client.SWIG_SVN_INFO_SIZE_UNKNOWN) self.assertEqual(self.info.size, 8) # Test 2: Run info (revision unspecified). We expect the working_size value # to be filled in. rev.kind = core.svn_opt_revision_unspecified client.info(readme_path, rev, rev, self.info_receiver, False, self.client_ctx) self.assertEqual(self.path, readme_path) self.info.assert_valid() self.assertEqual(self.info.size, client.SWIG_SVN_INFO_SIZE_UNKNOWN) # README.txt contains one EOL char, so on Windows it will be expanded from # LF to CRLF hence the working_size will be 9 instead of 8. if os.name == 'nt': self.assertEqual(self.info.working_size, 9) else: self.assertEqual(self.info.working_size, 8) # Test 3: Run info on the repository URL of README.txt. We expect the size # value to be filled in. rev.kind = core.svn_opt_revision_head client.info(readme_url, rev, rev, self.info_receiver, False, self.client_ctx) self.info.assert_valid() self.assertEqual(self.info.working_size, client.SWIG_SVN_INFO_SIZE_UNKNOWN) self.assertEqual(self.info.size, 8) finally: wc.adm_close(adm_access) core.svn_io_remove_dir(wc_path)
def test_checkout(self): """Test svn_client_checkout2.""" rev = core.svn_opt_revision_t() rev.kind = core.svn_opt_revision_head path = self.temper.alloc_empty_dir("-checkout") self.assertRaises(ValueError, client.checkout2, self.repos_uri, path, None, None, True, True, self.client_ctx) client.checkout2(self.repos_uri, path, rev, rev, True, True, self.client_ctx)
def test_url_from_path(self): """Test svn_client_url_from_path for a file:// URL""" self.assertEquals(client.url_from_path(self.repos_uri), self.repos_uri) rev = core.svn_opt_revision_t() rev.kind = core.svn_opt_revision_head path = self.temper.alloc_empty_dir("-url_from_path") client.checkout2(self.repos_uri, path, rev, rev, True, True, self.client_ctx) self.assertEquals(client.url_from_path(path), self.repos_uri)
def test_url_from_path(self): """Test svn_client_url_from_path for a file:// URL""" self.assertEquals(client.url_from_path(REPOS_URL), REPOS_URL) rev = core.svn_opt_revision_t() rev.kind = core.svn_opt_revision_head path = tempfile.mktemp('-url_from_path') client.checkout2(REPOS_URL, path, rev, rev, True, True, self.client_ctx) self.assertEquals(client.url_from_path(path), REPOS_URL)
def test_checkout(self): """Test svn_client_checkout2.""" rev = core.svn_opt_revision_t() rev.kind = core.svn_opt_revision_head path = tempfile.mktemp('-checkout') self.assertRaises(ValueError, client.checkout2, REPOS_URL, path, None, None, True, True, self.client_ctx) client.checkout2(REPOS_URL, path, rev, rev, True, True, self.client_ctx)
def test_url_from_path(self): """Test svn_client_url_from_path for a file:// URL""" self.assertEqual(client.url_from_path(self.repos_uri), self.repos_uri) rev = core.svn_opt_revision_t() rev.kind = core.svn_opt_revision_head path = self.temper.alloc_empty_dir('-url_from_path') client.checkout2(self.repos_uri, path, rev, rev, True, True, self.client_ctx) self.assertEqual(client.url_from_path(path), self.repos_uri)
def test_checkout(self): """Test svn_client_checkout2.""" rev = core.svn_opt_revision_t() rev.kind = core.svn_opt_revision_head path = self.temper.alloc_empty_dir('-checkout') self.assertRaises(ValueError, client.checkout2, self.repos_uri, path, None, None, True, True, self.client_ctx) client.checkout2(self.repos_uri, path, rev, rev, True, True, self.client_ctx)
def test_shelf(self): """Test shelf api.""" rev = core.svn_opt_revision_t() rev.kind = core.svn_opt_revision_number rev.value.number = 2 path = self.temper.alloc_empty_dir('-shelf') client.checkout2(self.repos_uri, path, rev, rev, True, True, self.client_ctx) pool = core.Pool() shelf = client._shelf_open_or_create(b"test1", path, self.client_ctx, pool) self.assertTrue(isinstance(shelf, client.svn_client__shelf_t)) new_subpath = core.svn_relpath_join(b'trunk', b'new-shelf-test.txt') new_path = core.svn_dirent_join(path, new_subpath) with open(core.svn_dirent_local_style(new_path), "wb") as fp: fp.write("A new text file\n".encode('utf8')) client.add5(new_path, core.svn_depth_unknown, False, False, False, True, self.client_ctx, pool) statused_paths = [] def shelf_status(path, status, pool): statused_paths.append(path) shelf_version = client._shelf_save_new_version3( shelf, (new_path, ), core.svn_depth_unknown, None, shelf_status, None, pool) self.assertTrue( isinstance(shelf_version, client.svn_client__shelf_version_t)) all_versions = client._shelf_get_all_versions(shelf, pool, pool) self.assertEqual(1, len(all_versions)) self.assertTrue( isinstance(all_versions[0], client.svn_client__shelf_version_t)) self.assertEqual(shelf_version.version_number, all_versions[0].version_number) self.assertIn(new_subpath, statused_paths) client._shelf_close(shelf, pool) pool.clear()
def test_update4(self): """Test update and the notify function callbacks""" rev = core.svn_opt_revision_t() rev.kind = core.svn_opt_revision_number rev.value.number = 0 path = self.temper.alloc_empty_dir("-update") self.assertRaises(ValueError, client.checkout2, self.repos_uri, path, None, None, True, True, self.client_ctx) client.checkout2(self.repos_uri, path, rev, rev, True, True, self.client_ctx) def notify_func(path, action, kind, mime_type, content_state, prop_state, rev): self.notified_paths.append(path) self.client_ctx.notify_func = client.svn_swig_py_notify_func self.client_ctx.notify_baton = notify_func rev.value.number = 1 self.notified_paths = [] client.update4((path,), rev, core.svn_depth_unknown, True, False, False, False, False, self.client_ctx) expected_paths = [ path, os.path.join(path, "branches"), os.path.join(path, "tags"), os.path.join(path, "trunk"), path, path, ] # All normal subversion apis process paths in Subversion's canonical format, # which isn't the platform specific format expected_paths = [x.replace(os.path.sep, "/") for x in expected_paths] self.notified_paths.sort() expected_paths.sort() self.assertEquals(self.notified_paths, expected_paths) def notify_func2(notify, pool): self.notified_paths.append(notify.path) self.client_ctx.notify_func2 = client.svn_swig_py_notify_func2 self.client_ctx.notify_baton2 = notify_func2 rev.value.number = 2 self.notified_paths = [] expected_paths = [path, os.path.join(path, "trunk", "README.txt"), os.path.join(path, "trunk"), path, path] expected_paths = [x.replace(os.path.sep, "/") for x in expected_paths] client.update4((path,), rev, core.svn_depth_unknown, True, False, False, False, False, self.client_ctx) self.notified_paths.sort() expected_paths.sort() self.assertEquals(self.notified_paths, expected_paths)
def test_uuid_from_path(self): """Test svn_client_uuid_from_path.""" rev = core.svn_opt_revision_t() rev.kind = core.svn_opt_revision_head path = self.temper.alloc_empty_dir("-uuid_from_path") client.checkout2(self.repos_uri, path, rev, rev, True, True, self.client_ctx) wc_adm = wc.adm_open3(None, path, False, 0, None) self.assertEquals( client.uuid_from_path(path, wc_adm, self.client_ctx), client.uuid_from_url(self.repos_uri, self.client_ctx) ) self.assert_(isinstance(client.uuid_from_path(path, wc_adm, self.client_ctx), basestring))
def test_uuid_from_path(self): """Test svn_client_uuid_from_path.""" rev = core.svn_opt_revision_t() rev.kind = core.svn_opt_revision_head path = self.temper.alloc_empty_dir('-uuid_from_path') client.checkout2(self.repos_uri, path, rev, rev, True, True, self.client_ctx) wc_adm = wc.adm_open3(None, path, False, 0, None) self.assertEqual(client.uuid_from_path(path, wc_adm, self.client_ctx), client.uuid_from_url(self.repos_uri, self.client_ctx)) self.assertTrue(isinstance(client.uuid_from_path(path, wc_adm, self.client_ctx), bytes))
def test_uuid_from_path(self): """Test svn_client_uuid_from_path.""" rev = core.svn_opt_revision_t() rev.kind = core.svn_opt_revision_head path = tempfile.mktemp('uuid_from_path') client.checkout2(REPOS_URL, path, rev, rev, True, True, self.client_ctx) wc_adm = wc.adm_open3(None, path, False, 0, None) self.assertEquals(client.uuid_from_path(path, wc_adm, self.client_ctx), client.uuid_from_url(REPOS_URL, self.client_ctx)) self.assert_(isinstance(client.uuid_from_path(path, wc_adm, self.client_ctx), types.StringTypes))
def setUp(self): """Load a Subversion repository""" self.temper = utils.Temper() # Isolate each test from the others with a fresh repository. (self.repos, _, self.repos_uri) = self.temper.alloc_known_repo( 'trac/versioncontrol/tests/svnrepos.dump', suffix='-wc-repo') self.fs = repos.fs(self.repos) self.path = self.temper.alloc_empty_dir(suffix='-wc-wc') client_ctx = client.create_context() rev = core.svn_opt_revision_t() rev.kind = core.svn_opt_revision_head client.checkout2(self.repos_uri, self.path, rev, rev, True, True, client_ctx) self.wc = wc.adm_open3(None, self.path, True, -1, None)
def setUp(self): """Load a Subversion repository""" # Isolate each test from the others with a fresh repository. # Eventually, we should move this into a shared TestCase base # class that all test cases in this directory can use. SubversionRepositoryTestSetup().setUp() # Open repository directly for cross-checking self.repos = repos.open(REPOS_PATH) self.fs = repos.fs(self.repos) self.path = core.svn_path_canonicalize(tempfile.mktemp()) client_ctx = client.create_context() rev = core.svn_opt_revision_t() rev.kind = core.svn_opt_revision_head client.checkout2(REPOS_URL, self.path, rev, rev, True, True, client_ctx) self.wc = wc.adm_open3(None, self.path, True, -1, None)