From 7842e92ebaf3fc3380cc8d704afa3841f333748c Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Thu, 15 Sep 2016 00:59:36 +0200 Subject: test, deps: FIX `mock` deps on py3. + Del extra spaces, import os.path as osp --- git/test/test_git.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'git/test/test_git.py') diff --git a/git/test/test_git.py b/git/test/test_git.py index b46ac72d..59796a3d 100644 --- a/git/test/test_git.py +++ b/git/test/test_git.py @@ -6,7 +6,6 @@ # the BSD License: http://www.opensource.org/licenses/bsd-license.php import os import sys -import mock import subprocess from git.test.lib import ( @@ -28,6 +27,11 @@ from gitdb.test.lib import with_rw_directory from git.compat import PY3 +try: + from unittest import mock +except ImportError: + import mock + class TestGit(TestBase): -- cgit v1.2.3 From 51bf7cbe8216d9a1da723c59b6feece0b1a34589 Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Sun, 25 Sep 2016 18:08:16 +0200 Subject: win: GC.collect on all TC.tearDown to fix appveyor hang runs + Fixed the hangs at `test_git:TestGit.test_handle_process_output()`. [travisci skip] --- git/test/test_git.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'git/test/test_git.py') diff --git a/git/test/test_git.py b/git/test/test_git.py index 59796a3d..534539d7 100644 --- a/git/test/test_git.py +++ b/git/test/test_git.py @@ -40,6 +40,10 @@ class TestGit(TestBase): super(TestGit, cls).setUpClass() cls.git = Git(cls.rorepo.working_dir) + def tearDown(self): + import gc + gc.collect() + @patch.object(Git, 'execute') def test_call_process_calls_execute(self, git): git.return_value = '' -- cgit v1.2.3 From 7ec2f8a4f26cec3fbbe1fb447058acaf508b39c0 Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Mon, 26 Sep 2016 01:36:57 +0200 Subject: apveyor, #519: FIX incomplete Popen pump + The code in `_read_lines_from_fno()` was reading the stream only once per invocation, so when input was larger than `mmap.PAGESIZE`, bytes were forgotten in the stream. + Replaced buffer-building code with iterate-on-file-descriptors. + Also set deamon-threads. --- git/test/test_git.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'git/test/test_git.py') diff --git a/git/test/test_git.py b/git/test/test_git.py index 534539d7..82ed2ace 100644 --- a/git/test/test_git.py +++ b/git/test/test_git.py @@ -238,9 +238,11 @@ class TestGit(TestBase): stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE, - shell=False) + shell=False, + creationflags=Git.CREATE_NO_WINDOW if sys.platform == 'win32' else 0, + ) handle_process_output(proc, counter_stdout, counter_stderr, lambda proc: proc.wait()) - assert count[1] == line_count - assert count[2] == line_count + self.assertEqual(count[1], line_count) + self.assertEqual(count[2], line_count) -- cgit v1.2.3 From fa70623a651d2a0b227202cad1e526e3eeebfa00 Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Mon, 26 Sep 2016 11:08:57 +0200 Subject: test, #519: FIX appveyor conda & failures in py2.6 `assertRaisesRegexp` --- git/test/test_git.py | 1 - 1 file changed, 1 deletion(-) (limited to 'git/test/test_git.py') diff --git a/git/test/test_git.py b/git/test/test_git.py index 82ed2ace..f8318595 100644 --- a/git/test/test_git.py +++ b/git/test/test_git.py @@ -239,7 +239,6 @@ class TestGit(TestBase): stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False, - creationflags=Git.CREATE_NO_WINDOW if sys.platform == 'win32' else 0, ) handle_process_output(proc, counter_stdout, counter_stderr, lambda proc: proc.wait()) -- cgit v1.2.3 From 7bbaac26906863b9a09158346218457befb2821a Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Mon, 26 Sep 2016 12:32:28 +0200 Subject: test, #519: Popen() universal_newlin.es NoWindow in Winfoes + More win-fixes: + Do not check unicode files in < py3. + util, #519: x4 timeout of lock-file blocking, failing in Appveyor. --- git/test/test_git.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'git/test/test_git.py') diff --git a/git/test/test_git.py b/git/test/test_git.py index f8318595..935673b1 100644 --- a/git/test/test_git.py +++ b/git/test/test_git.py @@ -239,6 +239,8 @@ class TestGit(TestBase): stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False, + universal_newlines=True, + creationflags=Git.CREATE_NO_WINDOW if sys.platform == 'win32' else 0, ) handle_process_output(proc, counter_stdout, counter_stderr, lambda proc: proc.wait()) -- cgit v1.2.3 From 45f8f20bdf1447fbfebd19a07412d337626ed6b0 Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Mon, 26 Sep 2016 19:42:42 +0200 Subject: Win, #519: FIX WinHangs: Popen() CREATE_NEW_PROCESS_GROUP to allow kill + FIXED most hangs BUT no more `git-daemon` un-killable! + Use logger for utils to replace stray print(). --- git/test/test_git.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'git/test/test_git.py') diff --git a/git/test/test_git.py b/git/test/test_git.py index 935673b1..ea62de03 100644 --- a/git/test/test_git.py +++ b/git/test/test_git.py @@ -21,7 +21,8 @@ from git import ( Git, GitCommandError, GitCommandNotFound, - Repo + Repo, + cmd ) from gitdb.test.lib import with_rw_directory @@ -240,7 +241,7 @@ class TestGit(TestBase): stderr=subprocess.PIPE, shell=False, universal_newlines=True, - creationflags=Git.CREATE_NO_WINDOW if sys.platform == 'win32' else 0, + creationflags=cmd.PROC_CREATIONFLAGS, ) handle_process_output(proc, counter_stdout, counter_stderr, lambda proc: proc.wait()) -- cgit v1.2.3 From f495e94028bfddc264727ffc464cd694ddd05ab8 Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Mon, 26 Sep 2016 20:41:41 +0200 Subject: src, #519: collect all is_() calls --- git/test/test_git.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'git/test/test_git.py') diff --git a/git/test/test_git.py b/git/test/test_git.py index ea62de03..2ef15523 100644 --- a/git/test/test_git.py +++ b/git/test/test_git.py @@ -26,7 +26,7 @@ from git import ( ) from gitdb.test.lib import with_rw_directory -from git.compat import PY3 +from git.compat import PY3, is_darwin try: from unittest import mock @@ -214,7 +214,7 @@ class TestGit(TestBase): try: remote.fetch() except GitCommandError as err: - if sys.version_info[0] < 3 and sys.platform == 'darwin': + if sys.version_info[0] < 3 and is_darwin(): assert 'ssh-origin' in str(err) assert err.status == 128 else: -- cgit v1.2.3 From 618e6259ef03a4b25415bae31a7540ac5eb2e38a Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Mon, 26 Sep 2016 22:20:33 +0200 Subject: test, #519: Try appveyor advice for never-ending builds + see http://help.appveyor.com/discussions/problems/5334-nosetests-finsih-bu-build-stuck-and-next-job-dealys-to-start + Use `io.DEFAULT_BUFFER_SIZE`. + test_commit: replace asserts with unittest-asserts. - TRY Popen() NO universal_newlines: NO, reverted in next commits. + [travisci skip] --- git/test/test_git.py | 1 - 1 file changed, 1 deletion(-) (limited to 'git/test/test_git.py') diff --git a/git/test/test_git.py b/git/test/test_git.py index 2ef15523..a6213c58 100644 --- a/git/test/test_git.py +++ b/git/test/test_git.py @@ -240,7 +240,6 @@ class TestGit(TestBase): stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False, - universal_newlines=True, creationflags=cmd.PROC_CREATIONFLAGS, ) -- cgit v1.2.3 From e61439b3018b0b9a8eb43e59d0d7cf32041e2fed Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Tue, 27 Sep 2016 16:05:58 +0200 Subject: src: constify is_() calls + TCs: unittest-asserts for git-tests. --- git/test/test_git.py | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'git/test/test_git.py') diff --git a/git/test/test_git.py b/git/test/test_git.py index a6213c58..36bbbb10 100644 --- a/git/test/test_git.py +++ b/git/test/test_git.py @@ -85,7 +85,7 @@ class TestGit(TestBase): # order is undefined res = self.git.transform_kwargs(**{'s': True, 't': True}) - assert ['-s', '-t'] == res or ['-t', '-s'] == res + self.assertEqual(set(['-s', '-t']), set(res)) def test_it_executes_git_to_shell_and_returns_result(self): assert_match('^git version [\d\.]{2}.*$', self.git.execute(["git", "version"])) @@ -117,7 +117,7 @@ class TestGit(TestBase): g.stdin.write(b"b2339455342180c7cc1e9bba3e9f181f7baa5167\n") g.stdin.flush() obj_info_two = g.stdout.readline() - assert obj_info == obj_info_two + self.assertEqual(obj_info, obj_info_two) # read data - have to read it in one large chunk size = int(obj_info.split()[2]) @@ -127,18 +127,19 @@ class TestGit(TestBase): # now we should be able to read a new object g.stdin.write(b"b2339455342180c7cc1e9bba3e9f181f7baa5167\n") g.stdin.flush() - assert g.stdout.readline() == obj_info + self.assertEqual(g.stdout.readline(), obj_info) # same can be achived using the respective command functions hexsha, typename, size = self.git.get_object_header(hexsha) hexsha, typename_two, size_two, data = self.git.get_object_data(hexsha) - assert typename == typename_two and size == size_two + self.assertEqual(typename, typename_two) + self.assertEqual(size, size_two) def test_version(self): v = self.git.version_info - assert isinstance(v, tuple) + self.assertIsInstance(v, tuple) for n in v: - assert isinstance(n, int) + self.assertIsInstance(n, int) # END verify number types def test_cmd_override(self): @@ -174,28 +175,28 @@ class TestGit(TestBase): def test_env_vars_passed_to_git(self): editor = 'non_existant_editor' with mock.patch.dict('os.environ', {'GIT_EDITOR': editor}): - assert self.git.var("GIT_EDITOR") == editor + self.assertEqual(self.git.var("GIT_EDITOR"), editor) @with_rw_directory def test_environment(self, rw_dir): # sanity check - assert self.git.environment() == {} + self.assertEqual(self.git.environment(), {}) # make sure the context manager works and cleans up after itself with self.git.custom_environment(PWD='/tmp'): - assert self.git.environment() == {'PWD': '/tmp'} + self.assertEqual(self.git.environment(), {'PWD': '/tmp'}) - assert self.git.environment() == {} + self.assertEqual(self.git.environment(), {}) old_env = self.git.update_environment(VARKEY='VARVALUE') # The returned dict can be used to revert the change, hence why it has # an entry with value 'None'. - assert old_env == {'VARKEY': None} - assert self.git.environment() == {'VARKEY': 'VARVALUE'} + self.assertEqual(old_env, {'VARKEY': None}) + self.assertEqual(self.git.environment(), {'VARKEY': 'VARVALUE'}) new_env = self.git.update_environment(**old_env) - assert new_env == {'VARKEY': 'VARVALUE'} - assert self.git.environment() == {} + self.assertEqual(new_env, {'VARKEY': 'VARVALUE'}) + self.assertEqual(self.git.environment(), {}) path = os.path.join(rw_dir, 'failing-script.sh') stream = open(path, 'wt') @@ -214,11 +215,11 @@ class TestGit(TestBase): try: remote.fetch() except GitCommandError as err: - if sys.version_info[0] < 3 and is_darwin(): - assert 'ssh-origin' in str(err) - assert err.status == 128 + if sys.version_info[0] < 3 and is_darwin: + self.assertIn('ssh-orig, ' in str(err)) + self.assertEqual(err.status, 128) else: - assert 'FOO' in str(err) + self.assertIn('FOO', str(err)) # end # end # end if select.poll exists -- cgit v1.2.3 From 137ee6ef22c4e6480f95972ef220d1832cdc709a Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Tue, 27 Sep 2016 22:07:19 +0200 Subject: Win, #519: FIX with_rw_directory() to remove read-only dirs + Stop using gitdb's respective helper. + Fix files chmod(555) which CANNOT DELETE on Windows (but do on Linux). --- git/test/test_git.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'git/test/test_git.py') diff --git a/git/test/test_git.py b/git/test/test_git.py index 36bbbb10..a676d7f7 100644 --- a/git/test/test_git.py +++ b/git/test/test_git.py @@ -24,7 +24,7 @@ from git import ( Repo, cmd ) -from gitdb.test.lib import with_rw_directory +from git.test.lib import with_rw_directory from git.compat import PY3, is_darwin @@ -174,7 +174,7 @@ class TestGit(TestBase): def test_env_vars_passed_to_git(self): editor = 'non_existant_editor' - with mock.patch.dict('os.environ', {'GIT_EDITOR': editor}): + with mock.patch.dict('os.environ', {'GIT_EDITOR': editor}): # @UndefinedVariable self.assertEqual(self.git.var("GIT_EDITOR"), editor) @with_rw_directory @@ -203,7 +203,7 @@ class TestGit(TestBase): stream.write("#!/usr/bin/env sh\n" + "echo FOO\n") stream.close() - os.chmod(path, 0o555) + os.chmod(path, 0o777) rw_repo = Repo.init(os.path.join(rw_dir, 'repo')) remote = rw_repo.create_remote('ssh-origin', "ssh://git@server/foo") @@ -220,9 +220,6 @@ class TestGit(TestBase): self.assertEqual(err.status, 128) else: self.assertIn('FOO', str(err)) - # end - # end - # end if select.poll exists def test_handle_process_output(self): from git.cmd import handle_process_output -- cgit v1.2.3 From 44c6d0b368bc1ec6cd0a97b01678b38788c9bd9c Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Wed, 28 Sep 2016 05:46:50 +0200 Subject: Proc, #519: Rework error-exc msgs & log thread-pumps errors + No WindowsError exception. + Add `test_exc.py` for unicode issues. + Single-arg for decoding-streams in pump-func. --- git/test/test_git.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'git/test/test_git.py') diff --git a/git/test/test_git.py b/git/test/test_git.py index a676d7f7..8a0242e6 100644 --- a/git/test/test_git.py +++ b/git/test/test_git.py @@ -27,6 +27,7 @@ from git import ( from git.test.lib import with_rw_directory from git.compat import PY3, is_darwin +from git.util import finalize_process try: from unittest import mock @@ -233,7 +234,8 @@ class TestGit(TestBase): def counter_stderr(line): count[2] += 1 - proc = subprocess.Popen([sys.executable, fixture_path('cat_file.py'), str(fixture_path('issue-301_stderr'))], + cmdline = [sys.executable, fixture_path('cat_file.py'), str(fixture_path('issue-301_stderr'))] + proc = subprocess.Popen(cmdline, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE, @@ -241,7 +243,7 @@ class TestGit(TestBase): creationflags=cmd.PROC_CREATIONFLAGS, ) - handle_process_output(proc, counter_stdout, counter_stderr, lambda proc: proc.wait()) + handle_process_output(proc, counter_stdout, counter_stderr, finalize_process) self.assertEqual(count[1], line_count) self.assertEqual(count[2], line_count) -- cgit v1.2.3 From 9a521681ff8614beb8e2c566cf3c475baca22169 Mon Sep 17 00:00:00 2001 From: Kostis Anagnostopoulos Date: Sat, 1 Oct 2016 18:20:13 +0200 Subject: io, #519: ALL open() --> with open() + Some cases had restructuring of code. --- git/test/test_git.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'git/test/test_git.py') diff --git a/git/test/test_git.py b/git/test/test_git.py index 8a0242e6..94614cd1 100644 --- a/git/test/test_git.py +++ b/git/test/test_git.py @@ -93,10 +93,9 @@ class TestGit(TestBase): def test_it_accepts_stdin(self): filename = fixture_path("cat_file_blob") - fh = open(filename, 'r') - assert_equal("70c379b63ffa0795fdbfbc128e5a2818397b7ef8", - self.git.hash_object(istream=fh, stdin=True)) - fh.close() + with open(filename, 'r') as fh: + assert_equal("70c379b63ffa0795fdbfbc128e5a2818397b7ef8", + self.git.hash_object(istream=fh, stdin=True)) @patch.object(Git, 'execute') def test_it_ignores_false_kwargs(self, git): @@ -200,10 +199,9 @@ class TestGit(TestBase): self.assertEqual(self.git.environment(), {}) path = os.path.join(rw_dir, 'failing-script.sh') - stream = open(path, 'wt') - stream.write("#!/usr/bin/env sh\n" + - "echo FOO\n") - stream.close() + with open(path, 'wt') as stream: + stream.write("#!/usr/bin/env sh\n" + "echo FOO\n") os.chmod(path, 0o777) rw_repo = Repo.init(os.path.join(rw_dir, 'repo')) -- cgit v1.2.3