| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -55,7 +55,7 @@ | |||
| 55 | 55 | ||
| 56 | 56 | __all__ = ('Git',) | |
| 57 | 57 | ||
| 58 | - if is_win(): | ||
| 58 | + if is_win: | ||
| 59 | 59 | WindowsError = OSError | |
| 60 | 60 | ||
| 61 | 61 | if PY3: | |
@@ -239,7 +239,7 @@ def dict_to_slots_and__excluded_are_none(self, d, excluded=()): | |||
| 239 | 239 | ## CREATE_NEW_PROCESS_GROUP is needed to allow killing it afterwards, | |
| 240 | 240 | # seehttps://docs.python.org/3/library/subprocess.html#subprocess.Popen.send_signal | |
| 241 | 241 | PROC_CREATIONFLAGS = (CREATE_NO_WINDOW | subprocess.CREATE_NEW_PROCESS_GROUP | |
| 242 | - if is_win() | ||
| 242 | + if is_win | ||
| 243 | 243 | else 0) | |
| 244 | 244 | ||
| 245 | 245 | ||
@@ -630,7 +630,7 @@ def execute(self, command, | |||
| 630 | 630 | env["LC_ALL"] = "C" | |
| 631 | 631 | env.update(self._environment) | |
| 632 | 632 | ||
| 633 | - if is_win(): | ||
| 633 | + if is_win: | ||
| 634 | 634 | cmd_not_found_exception = WindowsError | |
| 635 | 635 | if kill_after_timeout: | |
| 636 | 636 | raise GitCommandError('"kill_after_timeout" feature is not supported on Windows.') | |
@@ -650,13 +650,13 @@ def execute(self, command, | |||
| 650 | 650 | stderr=PIPE, | |
| 651 | 651 | stdout=PIPE if with_stdout else open(os.devnull, 'wb'), | |
| 652 | 652 | shell=self.USE_SHELL, | |
| 653 | - close_fds=(is_posix()), # unsupported on windows | ||
| 653 | + close_fds=(is_posix), # unsupported on windows | ||
| 654 | 654 | universal_newlines=universal_newlines, | |
| 655 | 655 | creationflags=PROC_CREATIONFLAGS, | |
| 656 | 656 | **subprocess_kwargs | |
| 657 | 657 | ) | |
| 658 | 658 | except cmd_not_found_exception as err: | |
| 659 | - raise GitCommandNotFound(str(err)) | ||
| 659 | + raise GitCommandNotFound('%s: %s' % (command[0], err)) | ||
| 660 | 660 | ||
| 661 | 661 | if as_process: | |
| 662 | 662 | return self.AutoInterrupt(proc, command) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,6 +24,9 @@ | |||
| 24 | 24 | ) | |
| 25 | 25 | ||
| 26 | 26 | PY3 = sys.version_info[0] >= 3 | |
| 27 | + is_win = (os.name == 'nt') | ||
| 28 | + is_posix = (os.name == 'posix') | ||
| 29 | + is_darwin = (os.name == 'darwin') | ||
| 27 | 30 | defenc = sys.getdefaultencoding() | |
| 28 | 31 | ||
| 29 | 32 | if PY3: | |
@@ -78,17 +81,6 @@ def __new__(cls, name, nbases, d): | |||
| 78 | 81 | return meta(name, bases, d) | |
| 79 | 82 | return metaclass(meta.__name__ + 'Helper', None, {}) | |
| 80 | 83 | ||
| 81 | - def is_win(): | ||
| 82 | - return os.name == 'nt' | ||
| 83 | - | ||
| 84 | - | ||
| 85 | - def is_posix(): | ||
| 86 | - return os.name == 'posix' | ||
| 87 | - | ||
| 88 | - | ||
| 89 | - def is_darwin(): | ||
| 90 | - return os.name == 'darwin' | ||
| 91 | - | ||
| 92 | 84 | ||
| 93 | 85 | ## From https://docs.python.org/3.3/howto/pyporting.html | |
| 94 | 86 | class UnicodeMixin(object): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -137,7 +137,7 @@ def _set_cache_(self, attr): | |||
| 137 | 137 | # which happens during read-tree. | |
| 138 | 138 | # In this case, we will just read the memory in directly. | |
| 139 | 139 | # Its insanely bad ... I am disappointed ! | |
| 140 | - allow_mmap = (is_win() or sys.version_info[1] > 5) | ||
| 140 | + allow_mmap = (is_win or sys.version_info[1] > 5) | ||
| 141 | 141 | stream = file_contents_ro(fd, stream=True, allow_mmap=allow_mmap) | |
| 142 | 142 | ||
| 143 | 143 | try: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -76,7 +76,7 @@ def run_commit_hook(name, index): | |||
| 76 | 76 | stdout=subprocess.PIPE, | |
| 77 | 77 | stderr=subprocess.PIPE, | |
| 78 | 78 | cwd=index.repo.working_dir, | |
| 79 | - close_fds=(is_posix()), | ||
| 79 | + close_fds=(is_posix), | ||
| 80 | 80 | creationflags=PROC_CREATIONFLAGS,) | |
| 81 | 81 | stdout, stderr = cmd.communicate() | |
| 82 | 82 | cmd.stdout.close() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -376,7 +376,7 @@ def __init__(self, repo, name): | |||
| 376 | 376 | self.repo = repo | |
| 377 | 377 | self.name = name | |
| 378 | 378 | ||
| 379 | - if is_win(): | ||
| 379 | + if is_win: | ||
| 380 | 380 | # some oddity: on windows, python 2.5, it for some reason does not realize | |
| 381 | 381 | # that it has the config_writer property, but instead calls __getattr__ | |
| 382 | 382 | # which will not yield the expected results. 'pinging' the members | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -370,7 +370,7 @@ def delete_remote(self, remote): | |||
| 370 | 370 | def _get_config_path(self, config_level): | |
| 371 | 371 | # we do not support an absolute path of the gitconfig on windows , | |
| 372 | 372 | # use the global config instead | |
| 373 | - if is_win() and config_level == "system": | ||
| 373 | + if is_win and config_level == "system": | ||
| 374 | 374 | config_level = "global" | |
| 375 | 375 | ||
| 376 | 376 | if config_level == "system": | |
@@ -884,7 +884,7 @@ def _clone(cls, git, url, path, odb_default_type, progress, **kwargs): | |||
| 884 | 884 | prev_cwd = None | |
| 885 | 885 | prev_path = None | |
| 886 | 886 | odbt = kwargs.pop('odbt', odb_default_type) | |
| 887 | - if is_win(): | ||
| 887 | + if is_win: | ||
| 888 | 888 | if '~' in path: | |
| 889 | 889 | raise OSError("Git cannot handle the ~ character in path %r correctly" % path) | |
| 890 | 890 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -74,7 +74,7 @@ def _mktemp(*args): | |||
| 74 | 74 | prefixing /private/ will lead to incorrect paths on OSX.""" | |
| 75 | 75 | tdir = tempfile.mktemp(*args) | |
| 76 | 76 | # See :note: above to learn why this is comented out. | |
| 77 | - # if is_darwin(): | ||
| 77 | + # if is_darwin: | ||
| 78 | 78 | # tdir = '/private' + tdir | |
| 79 | 79 | return tdir | |
| 80 | 80 | ||
@@ -84,7 +84,7 @@ def _rmtree_onerror(osremove, fullpath, exec_info): | |||
| 84 | 84 | Handle the case on windows that read-only files cannot be deleted by | |
| 85 | 85 | os.remove by setting it to mode 777, then retry deletion. | |
| 86 | 86 | """ | |
| 87 | - if is_win() or osremove is not os.remove: | ||
| 87 | + if is_win or osremove is not os.remove: | ||
| 88 | 88 | raise | |
| 89 | 89 | ||
| 90 | 90 | os.chmod(fullpath, 0o777) | |
@@ -141,7 +141,7 @@ def repo_creator(self): | |||
| 141 | 141 | ||
| 142 | 142 | ||
| 143 | 143 | def launch_git_daemon(temp_dir, ip, port): | |
| 144 | - if is_win(): | ||
| 144 | + if is_win: | ||
| 145 | 145 | ## On MINGW-git, daemon exists in .\Git\mingw64\libexec\git-core\, | |
| 146 | 146 | # but if invoked as 'git daemon', it detaches from parent `git` cmd, | |
| 147 | 147 | # and then CANNOT DIE! | |
@@ -242,7 +242,7 @@ def remote_repo_creator(self): | |||
| 242 | 242 | gd.proc.terminate() | |
| 243 | 243 | log.warning('git(%s) ls-remote failed due to:%s', | |
| 244 | 244 | rw_repo.git_dir, e) | |
| 245 | - if is_win(): | ||
| 245 | + if is_win: | ||
| 246 | 246 | msg = textwrap.dedent(""" | |
| 247 | 247 | MINGW yet has problems with paths, and `git-daemon.exe` must be in PATH | |
| 248 | 248 | (look into .\Git\mingw64\libexec\git-core\); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -118,7 +118,7 @@ def test_with_rw_remote_and_rw_repo(self, rw_repo, rw_remote_repo): | |||
| 118 | 118 | assert rw_remote_repo.config_reader("repository").getboolean("core", "bare") | |
| 119 | 119 | assert os.path.isdir(os.path.join(rw_repo.working_tree_dir, 'lib')) | |
| 120 | 120 | ||
| 121 | - @skipIf(sys.version_info < (3,) and is_win(), | ||
| 121 | + @skipIf(sys.version_info < (3,) and is_win, | ||
| 122 | 122 | "Unicode woes, see https://github.com/gitpython-developers/GitPython/pull/519") | |
| 123 | 123 | @with_rw_repo('0.1.6') | |
| 124 | 124 | def test_add_unicode(self, rw_repo): | |
@@ -135,7 +135,7 @@ def test_add_unicode(self, rw_repo): | |||
| 135 | 135 | ||
| 136 | 136 | open(file_path, "wb").write(b'something') | |
| 137 | 137 | ||
| 138 | - if is_win(): | ||
| 138 | + if is_win: | ||
| 139 | 139 | # on windows, there is no way this works, see images on | |
| 140 | 140 | # https://github.com/gitpython-developers/GitPython/issues/147#issuecomment-68881897 | |
| 141 | 141 | # Therefore, it must be added using the python implementation | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -85,7 +85,7 @@ def test_it_transforms_kwargs_into_git_command_arguments(self): | |||
| 85 | 85 | ||
| 86 | 86 | # order is undefined | |
| 87 | 87 | res = self.git.transform_kwargs(**{'s': True, 't': True}) | |
| 88 | - assert ['-s', '-t'] == res or ['-t', '-s'] == res | ||
| 88 | + self.assertEqual(set(['-s', '-t']), set(res)) | ||
| 89 | 89 | ||
| 90 | 90 | def test_it_executes_git_to_shell_and_returns_result(self): | |
| 91 | 91 | assert_match('^git version [\d\.]{2}.*$', self.git.execute(["git", "version"])) | |
@@ -117,7 +117,7 @@ def test_persistent_cat_file_command(self): | |||
| 117 | 117 | g.stdin.write(b"b2339455342180c7cc1e9bba3e9f181f7baa5167\n") | |
| 118 | 118 | g.stdin.flush() | |
| 119 | 119 | obj_info_two = g.stdout.readline() | |
| 120 | - assert obj_info == obj_info_two | ||
| 120 | + self.assertEqual(obj_info, obj_info_two) | ||
| 121 | 121 | ||
| 122 | 122 | # read data - have to read it in one large chunk | |
| 123 | 123 | size = int(obj_info.split()[2]) | |
@@ -127,18 +127,19 @@ def test_persistent_cat_file_command(self): | |||
| 127 | 127 | # now we should be able to read a new object | |
| 128 | 128 | g.stdin.write(b"b2339455342180c7cc1e9bba3e9f181f7baa5167\n") | |
| 129 | 129 | g.stdin.flush() | |
| 130 | - assert g.stdout.readline() == obj_info | ||
| 130 | + self.assertEqual(g.stdout.readline(), obj_info) | ||
| 131 | 131 | ||
| 132 | 132 | # same can be achived using the respective command functions | |
| 133 | 133 | hexsha, typename, size = self.git.get_object_header(hexsha) | |
| 134 | 134 | hexsha, typename_two, size_two, data = self.git.get_object_data(hexsha) | |
| 135 | - assert typename == typename_two and size == size_two | ||
| 135 | + self.assertEqual(typename, typename_two) | ||
| 136 | + self.assertEqual(size, size_two) | ||
| 136 | 137 | ||
| 137 | 138 | def test_version(self): | |
| 138 | 139 | v = self.git.version_info | |
| 139 | - assert isinstance(v, tuple) | ||
| 140 | + self.assertIsInstance(v, tuple) | ||
| 140 | 141 | for n in v: | |
| 141 | - assert isinstance(n, int) | ||
| 142 | + self.assertIsInstance(n, int) | ||
| 142 | 143 | # END verify number types | |
| 143 | 144 | ||
| 144 | 145 | def test_cmd_override(self): | |
@@ -174,28 +175,28 @@ def test_insert_after_kwarg_raises(self): | |||
| 174 | 175 | def test_env_vars_passed_to_git(self): | |
| 175 | 176 | editor = 'non_existant_editor' | |
| 176 | 177 | with mock.patch.dict('os.environ', {'GIT_EDITOR': editor}): | |
| 177 | - assert self.git.var("GIT_EDITOR") == editor | ||
| 178 | + self.assertEqual(self.git.var("GIT_EDITOR"), editor) | ||
| 178 | 179 | ||
| 179 | 180 | @with_rw_directory | |
| 180 | 181 | def test_environment(self, rw_dir): | |
| 181 | 182 | # sanity check | |
| 182 | - assert self.git.environment() == {} | ||
| 183 | + self.assertEqual(self.git.environment(), {}) | ||
| 183 | 184 | ||
| 184 | 185 | # make sure the context manager works and cleans up after itself | |
| 185 | 186 | with self.git.custom_environment(PWD='/tmp'): | |
| 186 | - assert self.git.environment() == {'PWD': '/tmp'} | ||
| 187 | + self.assertEqual(self.git.environment(), {'PWD': '/tmp'}) | ||
| 187 | 188 | ||
| 188 | - assert self.git.environment() == {} | ||
| 189 | + self.assertEqual(self.git.environment(), {}) | ||
| 189 | 190 | ||
| 190 | 191 | old_env = self.git.update_environment(VARKEY='VARVALUE') | |
| 191 | 192 | # The returned dict can be used to revert the change, hence why it has | |
| 192 | 193 | # an entry with value 'None'. | |
| 193 | - assert old_env == {'VARKEY': None} | ||
| 194 | - assert self.git.environment() == {'VARKEY': 'VARVALUE'} | ||
| 194 | + self.assertEqual(old_env, {'VARKEY': None}) | ||
| 195 | + self.assertEqual(self.git.environment(), {'VARKEY': 'VARVALUE'}) | ||
| 195 | 196 | ||
| 196 | 197 | new_env = self.git.update_environment(**old_env) | |
| 197 | - assert new_env == {'VARKEY': 'VARVALUE'} | ||
| 198 | - assert self.git.environment() == {} | ||
| 198 | + self.assertEqual(new_env, {'VARKEY': 'VARVALUE'}) | ||
| 199 | + self.assertEqual(self.git.environment(), {}) | ||
| 199 | 200 | ||
| 200 | 201 | path = os.path.join(rw_dir, 'failing-script.sh') | |
| 201 | 202 | stream = open(path, 'wt') | |
@@ -214,11 +215,11 @@ def test_environment(self, rw_dir): | |||
| 214 | 215 | try: | |
| 215 | 216 | remote.fetch() | |
| 216 | 217 | except GitCommandError as err: | |
| 217 | - if sys.version_info[0] < 3 and is_darwin(): | ||
| 218 | - assert 'ssh-origin' in str(err) | ||
| 219 | - assert err.status == 128 | ||
| 218 | + if sys.version_info[0] < 3 and is_darwin: | ||
| 219 | + self.assertIn('ssh-orig, ' in str(err)) | ||
| 220 | + self.assertEqual(err.status, 128) | ||
| 220 | 221 | else: | |
| 221 | - assert 'FOO' in str(err) | ||
| 222 | + self.assertIn('FOO', str(err)) | ||
| 222 | 223 | # end | |
| 223 | 224 | # end | |
| 224 | 225 | # end if select.poll exists | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -577,7 +577,7 @@ def mixed_iterator(): | |||
| 577 | 577 | assert len(entries) == 1 and entries[0].hexsha != null_hex_sha | |
| 578 | 578 | ||
| 579 | 579 | # add symlink | |
| 580 | - if not is_win(): | ||
| 580 | + if not is_win: | ||
| 581 | 581 | for target in ('/etc/nonexisting', '/etc/passwd', '/etc'): | |
| 582 | 582 | basename = "my_real_symlink" | |
| 583 | 583 | ||
@@ -630,7 +630,7 @@ def mixed_iterator(): | |||
| 630 | 630 | index.checkout(fake_symlink_path) | |
| 631 | 631 | ||
| 632 | 632 | # on windows we will never get symlinks | |
| 633 | - if is_win(): | ||
| 633 | + if is_win: | ||
| 634 | 634 | # simlinks should contain the link as text ( which is what a | |
| 635 | 635 | # symlink actually is ) | |
| 636 | 636 | open(fake_symlink_path, 'rb').read() == link_target | |
@@ -711,7 +711,7 @@ def make_paths(): | |||
| 711 | 711 | assert fkey not in index.entries | |
| 712 | 712 | ||
| 713 | 713 | index.add(files, write=True) | |
| 714 | - if is_win(): | ||
| 714 | + if is_win: | ||
| 715 | 715 | hp = hook_path('pre-commit', index.repo.git_dir) | |
| 716 | 716 | hpd = os.path.dirname(hp) | |
| 717 | 717 | if not os.path.isdir(hpd): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments