|
4 | 4 | # |
5 | 5 | # This module is part of GitPython and is released under |
6 | 6 | # the BSD License: http://www.opensource.org/licenses/bsd-license.php |
7 | | -importcontextlib |
8 | 7 | importos |
9 | 8 | importshutil |
10 | 9 | importsubprocess |
11 | 10 | importsys |
12 | 11 | fromtempfileimportTemporaryDirectory, TemporaryFile |
13 | | -fromunittestimportmock |
| 12 | +fromunittestimportmock, skipUnless |
14 | 13 |
|
15 | 14 | fromgitimportGit, refresh, GitCommandError, GitCommandNotFound, Repo, cmd |
16 | 15 | fromtest.libimportTestBase, fixture_path |
17 | 16 | fromtest.libimportwith_rw_directory |
18 | | -fromgit.utilimportfinalize_process |
| 17 | +fromgit.utilimportcwd, finalize_process |
19 | 18 |
|
20 | 19 | importos.pathasosp |
21 | 20 |
|
22 | 21 | fromgit.compatimportis_win |
23 | 22 |
|
24 | 23 |
|
25 | | -@contextlib.contextmanager |
26 | | -def_chdir(new_dir): |
27 | | -"""Context manager to temporarily change directory. Not reentrant.""" |
28 | | -old_dir=os.getcwd() |
29 | | -os.chdir(new_dir) |
30 | | -try: |
31 | | -yield |
32 | | -finally: |
33 | | -os.chdir(old_dir) |
34 | | - |
35 | | - |
36 | 24 | classTestGit(TestBase): |
37 | 25 | @classmethod |
38 | 26 | defsetUpClass(cls): |
@@ -102,9 +90,26 @@ def test_it_executes_git_not_from_cwd(self): |
102 | 90 | print("#!/bin/sh", file=file) |
103 | 91 | os.chmod(impostor_path, 0o755) |
104 | 92 |
|
105 | | -with_chdir(tmpdir): |
| 93 | +withcwd(tmpdir): |
106 | 94 | self.assertRegex(self.git.execute(["git", "version"]), r"^git version\b") |
107 | 95 |
|
| 96 | +@skipUnless(is_win, "The regression only affected Windows, and this test logic is OS-specific.") |
| 97 | +deftest_it_avoids_upcasing_unrelated_environment_variable_names(self): |
| 98 | +old_name="28f425ca_d5d8_4257_b013_8d63166c8158" |
| 99 | +ifold_name==old_name.upper(): |
| 100 | +raiseRuntimeError("test bug or strange locale: old_name invariant under upcasing") |
| 101 | +os.putenv(old_name, "1") # It has to be done this lower-level way to set it lower-case. |
| 102 | + |
| 103 | +cmdline= [ |
| 104 | +sys.executable, |
| 105 | +fixture_path("env_case.py"), |
| 106 | +self.rorepo.working_dir, |
| 107 | +old_name, |
| 108 | + ] |
| 109 | +pair_text=subprocess.check_output(cmdline, shell=False, text=True) |
| 110 | +new_name=pair_text.split("=")[0] |
| 111 | +self.assertEqual(new_name, old_name) |
| 112 | + |
108 | 113 | deftest_it_accepts_stdin(self): |
109 | 114 | filename=fixture_path("cat_file_blob") |
110 | 115 | withopen(filename, "r") asfh: |
|
0 commit comments