def setUpClass(cls): cls.repo_name = 'test_repo' cls.server_root = tempfile.mkdtemp() cls.checkout_root = tempfile.mkdtemp() cls.repo_url = 'file://{server_root}/{repo_name}'.format( server_root=cls.server_root, repo_name=cls.repo_name) cls.repo_working_directory = os.path.join(cls.checkout_root, cls.repo_name) run_shell_command( 'svnadmin create {repo_name}'.format(repo_name=cls.repo_name), cwd=cls.server_root) run_shell_command('svn co "{repo_url}"'.format(repo_url=cls.repo_url), cwd=cls.checkout_root)
def setUpClass(cls): cls.server_root = tempfile.mkdtemp() cls.source_root = tempfile.mkdtemp() perms = stat.S_ISVTX | (stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH) | \ (stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP) | \ (stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) os.chmod(cls.server_root, perms) os.mkdir(os.path.join(cls.server_root, 'test')) cls.env = {'CVSROOT': cls.server_root} run_shell_command('cvs init', cwd=cls.server_root, env=cls.env) cls.repo_working_directory = os.path.join(cls.source_root, 'test') repo = os.mkdir(cls.repo_working_directory) run_shell_command('cvs co test', cwd=cls.source_root, env=cls.env)
def test_get_remove_files(self): test_file_path = os.path.join(self.repo_working_directory, 'r.txt') with open(test_file_path, 'w') as test_file: test_file.write('r') run_shell_command('cvs add r.txt', cwd=self.repo_working_directory, env=self.env) run_shell_command( 'cvs commit -m "{commit}"'.format(commit=self.generate_logmsg()), cwd=self.repo_working_directory, env=self.env) os.remove(test_file_path) run_shell_command('cvs remove r.txt', cwd=self.repo_working_directory, env=self.env) run_shell_command( 'cvs commit -m "{commit}"'.format(commit=self.generate_logmsg()), cwd=self.repo_working_directory, env=self.env) sut = cvs.open_repository(self.repo_working_directory) version = sut.get_head_version('r.txt') major, minor = version.split('.') previous_version = "{major}.{minor}".format(major=major, minor=(int(minor) - 1)) changes = sut.get_changeset().changes self.assertEqual(changes, [ change.Change(sut, "r.txt", previous_version, "r.txt", version, change.ChangeType.remove) ])
def test_get_object_at_head(self): test_file_path = os.path.join(self.repo_working_directory, 'b.txt') with open(test_file_path, 'wb') as test_file: test_file.write(b"asdf") run_shell_command('cvs add b.txt', cwd=self.repo_working_directory, env=self.env) run_shell_command( 'cvs commit -m "{commit}"'.format(commit=self.generate_logmsg()), cwd=self.repo_working_directory, env=self.env) sut = cvs.open_repository(self.repo_working_directory) file_obj = sut.get_file_contents("b.txt") self.assertEqual(file_obj.read(), b"asdf")
def test_get_add_files(self): test_file_path = os.path.join(self.repo_working_directory, 'a.txt') with open(test_file_path, 'w') as test_file: test_file.write('a') run_shell_command('cvs add a.txt', cwd=self.repo_working_directory, env=self.env) run_shell_command( 'cvs commit -m "{commit}"'.format(commit=self.generate_logmsg()), cwd=self.repo_working_directory, env=self.env) sut = cvs.open_repository(self.repo_working_directory) version = sut.get_head_version('a.txt') changes = sut.get_changeset().changes self.assertEqual(changes, [ change.Change(sut, None, None, "a.txt", version, change.ChangeType.add) ])
def test_get_remove_files(self): test_file = os.path.join(self.repo_working_directory, 'a.txt') with open(test_file, 'w') as test_file: test_file.write('a') run_shell_command('svn add a.txt', cwd=self.repo_working_directory) run_shell_command('svn commit -m "Test"', cwd=self.repo_working_directory) run_shell_command('svn rm a.txt', cwd=self.repo_working_directory) run_shell_command('svn commit -m "Test"', cwd=self.repo_working_directory) run_shell_command('svn up', cwd=self.repo_working_directory) sut = svn.SVNRepository(self.repo_working_directory) revision = sut.info()['commit']['@revision'] changes = sut.get_changeset(revision).changes self.assertEqual(changes, [ change.Change(sut, "a.txt", str(int(revision) - 1), None, None, change.ChangeType.remove) ])
def test_get_modify_files(self): test_file_path = os.path.join(self.repo_working_directory, 'm.txt') with open(test_file_path, 'w') as test_file: test_file.write('a') run_shell_command('cvs add m.txt', cwd=self.repo_working_directory, env=self.env) run_shell_command( 'cvs commit -m "{commit}"'.format(commit=self.generate_logmsg()), cwd=self.repo_working_directory, env=self.env) time.sleep(1) # CVS commits aren't synchronous with open(test_file_path, 'a') as test_file: test_file.write('\nb\n') run_shell_command( 'cvs commit -m "{commit}"'.format(commit=self.generate_logmsg()), cwd=self.repo_working_directory, env=self.env) sut = cvs.open_repository(self.repo_working_directory) version = sut.get_head_version('m.txt') major, minor = version.split('.') previous_version = "{major}.{minor}".format(major=major, minor=(int(minor) - 1)) changes = sut.get_changeset().changes self.assertEqual(changes, [ change.Change(sut, "m.txt", previous_version, "m.txt", version, change.ChangeType.modify) ])
def tearDown(self): for path in os.listdir(self.repo_working_directory): if path != '.svn': run_shell_command('svn rm {path} --force -q'.format(path=path), cwd=self.repo_working_directory) run_shell_command('svn commit -m "Cleanup"', cwd=self.repo_working_directory) run_shell_command('svn up', cwd=self.repo_working_directory)
def test_get_properties(self): test_file_path = os.path.join(self.repo_working_directory, 'a.txt') with open(test_file_path, 'wb') as test_file: test_file.write(b'a') run_shell_command('svn add a.txt', cwd=self.repo_working_directory) run_shell_command('svn propset a:b c a.txt', cwd=self.repo_working_directory) run_shell_command('svn commit -m "Test"', cwd=self.repo_working_directory) run_shell_command('svn up', cwd=self.repo_working_directory) sut = svn.SVNRepository(self.repo_working_directory) revision = sut.info()['commit']['@revision'] self.assertTrue( ('a:b', 'c') in sut.get_properties('a.txt', revision=revision).items())
def test_get_file_contents(self): test_file_path = os.path.join(self.repo_working_directory, 'a.txt') with open(test_file_path, 'wb') as test_file: test_file.write(b'a') run_shell_command('svn add a.txt', cwd=self.repo_working_directory) run_shell_command('svn commit -m "Test"', cwd=self.repo_working_directory) run_shell_command('svn up', cwd=self.repo_working_directory) sut = svn.SVNRepository(self.repo_working_directory) revision = sut.info()['commit']['@revision'] self.assertEqual( sut.get_file_contents('a.txt', revision=revision).read(), b'a')