From c02ee540d17db9edf0928ec33d2a3c3e9583a306 Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Mar 10 2017 14:09:36 +0000 Subject: [PATCH 1/2] Allow to specify custom info to a dummy commit This patch makes it easier to specify custom filename, file content, commit message to a dummy commit, that is used for running tests. Signed-off-by: Chenxiong Qi --- diff --git a/tests/utils.py b/tests/utils.py index 7688d49..be25206 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -197,9 +197,8 @@ class CommandTestCase(Assertions, Utils, unittest.TestCase): def create_branch(self, repo, branch_name): repo.git.branch(branch_name) - def make_a_dummy_commit(self, repo): - filename = os.path.join(repo.working_dir, 'document.txt') - with open(filename, 'a+') as f: - f.write('Hello rpkg') - repo.index.add([filename]) - repo.index.commit('update document') + def make_a_dummy_commit(self, repo, filename=None, file_content=None, commit_message=None): + _filename = os.path.join(repo.working_dir, filename or 'document.txt') + self.write_file(_filename, file_content or 'Hello rpkg') + repo.index.add([_filename]) + repo.index.commit(commit_message or 'update document') From a498653b4f1f2297896e5491f497a29a4632e79f Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Mar 10 2017 14:12:39 +0000 Subject: [PATCH 2/2] Make new command be able to print unicode Fix #205 Signed-off-by: Chenxiong Qi --- diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py index 7395fd1..c0f5400 100644 --- a/pyrpkg/cli.py +++ b/pyrpkg/cli.py @@ -1268,7 +1268,8 @@ see API KEY section of copr-cli(1) man page. print(self.cmd.mock_config(self.args.target, self.args.arch)) def new(self): - print(self.cmd.new()) + new_diff = self.cmd.new() + print(new_diff.encode('utf-8')) def new_sources(self): # Check to see if the files passed exist diff --git a/tests/test_cli.py b/tests/test_cli.py index 29b1e2e..d3bc4a9 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -692,6 +692,30 @@ class TestNew(CliTestCase): self.assertTrue('+New change' in output) +class TestNewPrintUnicode(CliTestCase): + """Test new diff contains unicode characters + + Fix issue 205: https://pagure.io/rpkg/issue/205 + """ + + def setUp(self): + super(TestNewPrintUnicode, self).setUp() + self.run_cmd(['git', 'tag', '-m', 'New release 0.1', '0.1'], cwd=self.cloned_repo_path) + self.make_a_dummy_commit(git.Repo(self.cloned_repo_path), + file_content='Include unicode chars á ř', + commit_message=u'Write unicode to file') + + @patch('sys.stdout', new=StringIO()) + def test_get_diff(self): + cli_cmd = ['rpkg', '--path', self.cloned_repo_path, 'new'] + with patch('sys.argv', new=cli_cmd): + cli = self.new_cli() + cli.new() + + output = sys.stdout.getvalue() + self.assertTrue('+Include unicode' in output) + + class LookasideCacheMock(object): def init_lookaside_cache(self):