diff options
author | Kostis Anagnostopoulos <ankostis@gmail.com> | 2016-09-27 16:05:58 +0200 |
---|---|---|
committer | Kostis Anagnostopoulos <ankostis@gmail.com> | 2016-09-28 03:35:38 +0200 |
commit | e61439b3018b0b9a8eb43e59d0d7cf32041e2fed (patch) | |
tree | 864b8c57283d3167b192b69bd17e366252ebee15 /git/test | |
parent | df2fb548040c8313f4bb98870788604bc973fa18 (diff) | |
download | gitpython-e61439b3018b0b9a8eb43e59d0d7cf32041e2fed.tar.gz |
src: constify is_<platform>() calls
+ TCs: unittest-asserts for git-tests.
Diffstat (limited to 'git/test')
-rw-r--r-- | git/test/lib/helper.py | 8 | ||||
-rw-r--r-- | git/test/test_base.py | 4 | ||||
-rw-r--r-- | git/test/test_git.py | 37 | ||||
-rw-r--r-- | git/test/test_index.py | 6 | ||||
-rw-r--r-- | git/test/test_submodule.py | 2 | ||||
-rw-r--r-- | git/test/test_util.py | 2 |
6 files changed, 30 insertions, 29 deletions
diff --git a/git/test/lib/helper.py b/git/test/lib/helper.py index 0a845a3f..7f4e81e0 100644 --- a/git/test/lib/helper.py +++ b/git/test/lib/helper.py @@ -74,7 +74,7 @@ def _mktemp(*args): prefixing /private/ will lead to incorrect paths on OSX.""" tdir = tempfile.mktemp(*args) # See :note: above to learn why this is comented out. - # if is_darwin(): + # if is_darwin: # tdir = '/private' + tdir return tdir @@ -84,7 +84,7 @@ def _rmtree_onerror(osremove, fullpath, exec_info): Handle the case on windows that read-only files cannot be deleted by os.remove by setting it to mode 777, then retry deletion. """ - if is_win() or osremove is not os.remove: + if is_win or osremove is not os.remove: raise os.chmod(fullpath, 0o777) @@ -141,7 +141,7 @@ def with_rw_repo(working_tree_ref, bare=False): def launch_git_daemon(temp_dir, ip, port): - if is_win(): + if is_win: ## On MINGW-git, daemon exists in .\Git\mingw64\libexec\git-core\, # but if invoked as 'git daemon', it detaches from parent `git` cmd, # and then CANNOT DIE! @@ -242,7 +242,7 @@ def with_rw_and_rw_remote_repo(working_tree_ref): gd.proc.terminate() log.warning('git(%s) ls-remote failed due to:%s', rw_repo.git_dir, e) - if is_win(): + if is_win: msg = textwrap.dedent(""" MINGW yet has problems with paths, and `git-daemon.exe` must be in PATH (look into .\Git\mingw64\libexec\git-core\); diff --git a/git/test/test_base.py b/git/test/test_base.py index cf92997f..fa0bebca 100644 --- a/git/test/test_base.py +++ b/git/test/test_base.py @@ -118,7 +118,7 @@ class TestBase(TestBase): assert rw_remote_repo.config_reader("repository").getboolean("core", "bare") assert os.path.isdir(os.path.join(rw_repo.working_tree_dir, 'lib')) - @skipIf(sys.version_info < (3,) and is_win(), + @skipIf(sys.version_info < (3,) and is_win, "Unicode woes, see https://github.com/gitpython-developers/GitPython/pull/519") @with_rw_repo('0.1.6') def test_add_unicode(self, rw_repo): @@ -135,7 +135,7 @@ class TestBase(TestBase): open(file_path, "wb").write(b'something') - if is_win(): + if is_win: # on windows, there is no way this works, see images on # https://github.com/gitpython-developers/GitPython/issues/147#issuecomment-68881897 # Therefore, it must be added using the python implementation 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 diff --git a/git/test/test_index.py b/git/test/test_index.py index b83201c9..2a8df798 100644 --- a/git/test/test_index.py +++ b/git/test/test_index.py @@ -577,7 +577,7 @@ class TestIndex(TestBase): assert len(entries) == 1 and entries[0].hexsha != null_hex_sha # add symlink - if not is_win(): + if not is_win: for target in ('/etc/nonexisting', '/etc/passwd', '/etc'): basename = "my_real_symlink" @@ -630,7 +630,7 @@ class TestIndex(TestBase): index.checkout(fake_symlink_path) # on windows we will never get symlinks - if is_win(): + if is_win: # simlinks should contain the link as text ( which is what a # symlink actually is ) open(fake_symlink_path, 'rb').read() == link_target @@ -711,7 +711,7 @@ class TestIndex(TestBase): assert fkey not in index.entries index.add(files, write=True) - if is_win(): + if is_win: hp = hook_path('pre-commit', index.repo.git_dir) hpd = os.path.dirname(hp) if not os.path.isdir(hpd): diff --git a/git/test/test_submodule.py b/git/test/test_submodule.py index 5906b06c..9307bab2 100644 --- a/git/test/test_submodule.py +++ b/git/test/test_submodule.py @@ -26,7 +26,7 @@ from git.repo.fun import ( # Change the configuration if possible to prevent the underlying memory manager # to keep file handles open. On windows we get problems as they are not properly # closed due to mmap bugs on windows (as it appears) -if is_win(): +if is_win: try: import smmap.util smmap.util.MapRegion._test_read_into_memory = True diff --git a/git/test/test_util.py b/git/test/test_util.py index 76a5e0e9..9fc159df 100644 --- a/git/test/test_util.py +++ b/git/test/test_util.py @@ -92,7 +92,7 @@ class TestUtils(TestBase): elapsed = time.time() - start # More extra time costs, but... extra_time = 0.2 - if is_win(): + if is_win: extra_time *= 4 self.assertLess(elapsed, wait_time + 0.02) |