def setUpClass(self): SvnClientTestSetups.setUpClass() client = SvnClient(self.local_path) client.checkout(self.local_url) # after setting up "local" repo, change files and make some changes subprocess.check_call("rm deleted-fs.txt", shell=True, cwd=self.local_path) subprocess.check_call("svn rm deleted.txt", shell=True, cwd=self.local_path) f = io.open(os.path.join(self.local_path, "modified.txt"), 'a') f.write('0123456789abcdef') f.close() f = io.open(os.path.join(self.local_path, "modified-fs.txt"), 'a') f.write('0123456789abcdef') f.close() f = io.open(os.path.join(self.local_path, "added-fs.txt"), 'w') f.write('0123456789abcdef') f.close() f = io.open(os.path.join(self.local_path, "added.txt"), 'w') f.write('0123456789abcdef') f.close() subprocess.check_call("svn add added.txt", shell=True, cwd=self.local_path)
def test_get_branches(self): client = SvnClient(self.local_path) self.assertEqual(['foo'], client.get_branches()) # slyly create some empty branches subprocess.check_call("mkdir %s" % os.path.normpath("branches/foo2"), shell=True, cwd=self.init_path) subprocess.check_call("mkdir %s" % os.path.normpath("branches/bar"), shell=True, cwd=self.init_path) subprocess.check_call("svn add branches/foo2", shell=True, cwd=self.init_path) subprocess.check_call("svn add branches/bar", shell=True, cwd=self.init_path) subprocess.check_call("svn commit -m newbranches", shell=True, cwd=self.init_path) self.assertEqual([], client.get_branches(local_only=True)) self.assertEqual(['bar', 'foo', 'foo2'], client.get_branches()) # checkout branch foo local_path2 = os.path.join(self.root_directory, "local_foo") client = SvnClient(local_path2) client.checkout(self.local_root_url + '/branches/foo') self.assertEqual(['foo'], client.get_branches(local_only=True))
def test_get_remote_branch_version(self): url = self.branch_url client = SvnClient(self.local_path) client.checkout(url) self.assertEqual(client.get_remote_version(fetch=True), self.local_version_foo_branch) self.assertEqual(client.get_remote_version(fetch=False), None)
def test_get_branches_non_canonical(self): remote_path = os.path.join(self.root_directory, "remote_nc") init_path = os.path.join(self.root_directory, "init_nc") local_path = os.path.join(self.root_directory, "local_nc") # create a "remote" repo subprocess.check_call("svnadmin create %s" % remote_path, shell=True, cwd=self.root_directory) local_root_url = _get_file_uri(remote_path) local_url = local_root_url + "/footest" # create an "init" repo to populate remote repo subprocess.check_call("svn checkout %s %s" % (local_root_url, init_path), shell=True, cwd=self.root_directory) for cmd in [ "mkdir footest", "mkdir %s" % os.path.normpath("footest/foosub") ]: subprocess.check_call(cmd, shell=True, cwd=init_path) _touch(os.path.join(init_path, "footest/foosub/fixed.txt")) for cmd in ["svn add footest", "svn commit -m initial"]: subprocess.check_call(cmd, shell=True, cwd=init_path) client = SvnClient(local_path) client.checkout(local_url) self.assertEqual([], client.get_branches())
def test_checkout_dir_exists(self): url = self.local_url client = SvnClient(self.local_path) self.assertFalse(client.path_exists()) os.makedirs(self.local_path) self.assertTrue(client.checkout(url)) # non-empty self.assertFalse(client.checkout(url))
def test_get_affected_files(self): client = SvnClient(self.local_path) client.checkout(self.local_url) log = client.get_log(limit=1)[0] affected = client.get_affected_files(log['id']) self.assertEqual(sorted(['deleted-fs.txt', 'deleted.txt']), sorted(affected))
def test_get_log_defaults(self): client = SvnClient(self.local_path) client.checkout(self.local_url) log = client.get_log() self.assertEquals(3, len(log)) self.assertEquals('modified', log[0]['message']) for key in ['id', 'author', 'date', 'message']: self.assertTrue(log[0][key] is not None, key) # svn logs don't have email, but key should be in dict self.assertTrue(log[0]['email'] is None)
def test_get_url_by_reading(self): client = SvnClient(self.local_path) client.checkout(self.local_url) self.assertTrue(client.path_exists()) self.assertTrue(client.detect_presence()) self.assertEqual(self.local_url, client.get_url()) #self.assertEqual(client.get_version(), self.local_version) self.assertEqual(client.get_version("PREV"), "-r2") self.assertEqual(client.get_version("2"), "-r2") self.assertEqual(client.get_version("-r2"), "-r2") # test invalid cient and repo without url client = SvnClient(os.path.join(self.remote_path, 'foo')) self.assertEqual(None, client.get_url())
def test_get_branches(self): client = SvnClient(self.local_path) self.assertEqual(['foo'], client.get_branches()) # slyly create some empty branches subprocess.check_call("mkdir -p branches/foo2", shell=True, cwd=self.init_path) subprocess.check_call("mkdir -p branches/bar", shell=True, cwd=self.init_path) subprocess.check_call("svn add branches/foo2", shell=True, cwd=self.init_path) subprocess.check_call("svn add branches/bar", shell=True, cwd=self.init_path) subprocess.check_call("svn commit -m newbranches", shell=True, cwd=self.init_path) self.assertEqual([], client.get_branches(local_only=True)) self.assertEqual(['bar', 'foo', 'foo2'], client.get_branches()) # checkout branch foo local_path2 = os.path.join(self.root_directory, "local_foo") client = SvnClient(local_path2) client.checkout(self.local_root_url + '/branches/foo') self.assertEqual(['foo'], client.get_branches(local_only=True))
def test_get_branches_non_canonical(self): remote_path = os.path.join(self.root_directory, "remote_nc") init_path = os.path.join(self.root_directory, "init_nc") local_path = os.path.join(self.root_directory, "local_nc") # create a "remote" repo subprocess.check_call("svnadmin create %s" % remote_path, shell=True, cwd=self.root_directory) local_root_url = "file://localhost/" + remote_path local_url = local_root_url + "/footest" # create an "init" repo to populate remote repo subprocess.check_call("svn checkout %s %s" % (local_root_url, init_path), shell=True, cwd=self.root_directory) for cmd in [ "mkdir footest", "mkdir footest/foosub", "touch footest/foosub/fixed.txt", "svn add footest", "svn commit -m initial"]: subprocess.check_call(cmd, shell=True, cwd=init_path) client = SvnClient(local_path) client.checkout(local_url) self.assertEqual([], client.get_branches())
def test_checkout(self): url = self.local_url client = SvnClient(self.local_path) self.assertFalse(client.path_exists()) self.assertFalse(client.detect_presence()) self.assertFalse(client.detect_presence()) self.assertTrue(client.checkout(url)) self.assertTrue(client.path_exists()) self.assertTrue(client.detect_presence()) self.assertEqual(client.get_path(), self.local_path) self.assertEqual(client.get_url(), url)
def test_checkout_emptyversion(self): url = self.local_url client = SvnClient(self.local_path) self.assertFalse(client.path_exists()) self.assertFalse(client.detect_presence()) self.assertFalse(client.detect_presence()) self.assertTrue(client.checkout(url, version='')) self.assertTrue(client.path_exists()) self.assertTrue(client.detect_presence()) self.assertEqual(client.get_path(), self.local_path) self.assertEqual(client.get_url(), url) self.assertTrue(client.update(None)) self.assertTrue(client.update(""))
def test_checkout_specific_version_and_update_short(self): "using just a number as version" url = self.local_url version = "3" client = SvnClient(self.local_path) self.assertFalse(client.path_exists()) self.assertFalse(client.detect_presence()) self.assertTrue(client.checkout(url, version)) self.assertTrue(client.path_exists()) self.assertTrue(client.detect_presence()) self.assertEqual(client.get_version(), "-r3") new_version = '2' self.assertTrue(client.update(new_version)) self.assertEqual(client.get_version(), "-r2")
def test_checkout(self): from vcstools.svn import SvnClient directory = tempfile.mkdtemp() self.directories["checkout_test"] = directory local_path = os.path.join(directory, "ros") url = self.readonly_url client = SvnClient(local_path) self.assertFalse(client.path_exists()) self.assertFalse(client.detect_presence()) self.assertFalse(client.detect_presence()) self.assertTrue(client.checkout(url)) self.assertTrue(client.path_exists()) self.assertTrue(client.detect_presence()) self.assertEqual(client.get_path(), local_path) self.assertEqual(client.get_url(), url)
def setUp(self): from vcstools.svn import SvnClient directory = tempfile.mkdtemp() self.directories = dict(setUp=directory) remote_path = os.path.join(directory, "remote") init_path = os.path.join(directory, "remote") # create a "remote" repo subprocess.check_call(["svnadmin", "create", remote_path], cwd=directory) self.readonly_url = "file://localhost"+remote_path # create an "init" repo to feed remote repo subprocess.check_call(["svn", "checkout", self.readonly_url, init_path], cwd=directory) subprocess.check_call(["touch", "fixed.txt"], cwd=init_path) subprocess.check_call(["svn", "add", "fixed.txt"], cwd=init_path) subprocess.check_call(["svn", "commit", "-m", "initial"], cwd=init_path) self.readonly_version_init = "-r1" # files to be modified in "local" repo subprocess.check_call(["touch", "modified.txt"], cwd=init_path) subprocess.check_call(["touch", "modified-fs.txt"], cwd=init_path) subprocess.check_call(["svn", "add", "modified.txt", "modified-fs.txt"], cwd=init_path) subprocess.check_call(["svn", "commit", "-m", "initial"], cwd=init_path) self.readonly_version_second = "-r2" subprocess.check_call(["touch", "deleted.txt"], cwd=init_path) subprocess.check_call(["touch", "deleted-fs.txt"], cwd=init_path) subprocess.check_call(["svn", "add", "deleted.txt", "deleted-fs.txt"], cwd=init_path) subprocess.check_call(["svn", "commit", "-m", "modified"], cwd=init_path) self.readonly_version = "-r3" self.readonly_path = os.path.join(directory, "readonly") client = SvnClient(self.readonly_path) self.assertTrue(client.checkout(self.readonly_url, self.readonly_version))
def test_checkout_specific_version_and_update(self): from vcstools.svn import SvnClient directory = tempfile.mkdtemp() subdir = "checkout_specific_version_test" self.directories[subdir] = directory local_path = os.path.join(directory, "ros") url = self.readonly_url version = "-r3" client = SvnClient(local_path) self.assertFalse(client.path_exists()) self.assertFalse(client.detect_presence()) self.assertFalse(client.detect_presence()) self.assertTrue(client.checkout(url, version)) self.assertTrue(client.path_exists()) self.assertTrue(client.detect_presence()) self.assertEqual(client.get_path(), local_path) self.assertEqual(client.get_url(), url) self.assertEqual(client.get_version(), version) new_version = '-r2' self.assertTrue(client.update(new_version)) self.assertEqual(client.get_version(), new_version) self.assertEqual(client.get_version("PREV"), "-r1")
def test_get_log_path(self): client = SvnClient(self.local_path) client.checkout(self.local_url) log = client.get_log(relpath='fixed.txt') self.assertEquals('initial', log[0]['message'])
def test_get_log_limit(self): client = SvnClient(self.local_path) client.checkout(self.local_url) log = client.get_log(limit=1) self.assertEquals(1, len(log)) self.assertEquals('modified', log[0]['message'])
def setUpClass(self): SvnClientTestSetups.setUpClass() client = SvnClient(self.local_path) client.checkout(self.local_url)
def setUpClass(self): SvnClientTestSetups.setUpClass() client = SvnClient(self.local_path) client.checkout(self.local_url) self.basepath_export = os.path.join(self.root_directory, 'export')