Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf0e15e8

Browse files
committed
Further cleanup in test_util (on new tests)
The main change here is to move the tests of how the HIDE_*environment variables are treated up near the rmtree tests, sincethey although the behaviors being tested are separate, they areconceptually related, and also not entirely independent in thatthey both involve the HIDE_WINDOWS_KNOWN_ERRORS attribute.Other changes are mostly to formatting.
1 parentc11b366 commitf0e15e8

File tree

1 file changed

+54
-40
lines changed

1 file changed

+54
-40
lines changed

‎test/test_util.py

Lines changed: 54 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,14 @@ def test_rmtree_deletes_nested_dir_with_files(self):
8787
td=pathlib.Path(parent,"testdir")
8888
fordintd,td/"q",td/"s":
8989
d.mkdir()
90-
forfintd/"p",td/"q"/"w",td/"q"/"x",td/"r",td/"s"/"y",td/"s"/"z":
90+
forfin (
91+
td/"p",
92+
td/"q"/"w",
93+
td/"q"/"x",
94+
td/"r",
95+
td/"s"/"y",
96+
td/"s"/"z",
97+
):
9198
f.write_bytes(b"")
9299

93100
try:
@@ -97,7 +104,10 @@ def test_rmtree_deletes_nested_dir_with_files(self):
97104

98105
self.assertFalse(td.exists())
99106

100-
@skipIf(sys.platform=="cygwin","Cygwin can't set the permissions that make the test meaningful.")
107+
@skipIf(
108+
sys.platform=="cygwin",
109+
"Cygwin can't set the permissions that make the test meaningful.",
110+
)
101111
deftest_rmtree_deletes_dir_with_readonly_files(self):
102112
# Automatically works on Unix, but requires special handling on Windows.
103113
# Not to be confused with what _tmpdir_to_force_permission_error sets up (see below).
@@ -117,7 +127,7 @@ def test_rmtree_deletes_dir_with_readonly_files(self):
117127
self.assertFalse(td.exists())
118128

119129
deftest_rmtree_can_wrap_exceptions(self):
120-
"""Ourrmtree wraps PermissionError when HIDE_WINDOWS_KNOWN_ERRORS is true."""
130+
"""rmtree wraps PermissionError when HIDE_WINDOWS_KNOWN_ERRORS is true."""
121131
with_tmpdir_to_force_permission_error()astd:
122132
# Access the module through sys.modules so it is unambiguous which module's
123133
# attribute we patch: the original git.util, not git.index.util even though
@@ -135,19 +145,58 @@ def test_rmtree_can_wrap_exceptions(self):
135145
(True,FileNotFoundError,_tmpdir_for_file_not_found),
136146
)
137147
deftest_rmtree_does_not_wrap_unless_called_for(self,case):
138-
"""Ourrmtree doesn't wrap non-PermissionError, norwhen HIDE_WINDOWS_KNOWN_ERRORS is false."""
148+
"""rmtree doesn't wrap non-PermissionError, norif HIDE_WINDOWS_KNOWN_ERRORS is false."""
139149
hide_windows_known_errors,exception_type,tmpdir_context_factory=case
140150

141151
withtmpdir_context_factory()astd:
142152
# See comments in test_rmtree_can_wrap_exceptions regarding the patching done here.
143-
withmock.patch.object(sys.modules["git.util"],"HIDE_WINDOWS_KNOWN_ERRORS",hide_windows_known_errors):
153+
withmock.patch.object(
154+
sys.modules["git.util"],
155+
"HIDE_WINDOWS_KNOWN_ERRORS",
156+
hide_windows_known_errors,
157+
):
144158
withmock.patch.object(os,"chmod"),mock.patch.object(pathlib.Path,"chmod"):
145159
withself.assertRaises(exception_type):
146160
try:
147161
rmtree(td)
148162
exceptSkipTestasex:
149163
self.fail(f"rmtree unexpectedly attempts skip:{ex!r}")
150164

165+
@ddt.data("HIDE_WINDOWS_KNOWN_ERRORS","HIDE_WINDOWS_FREEZE_ERRORS")
166+
deftest_env_vars_for_windows_tests(self,name):
167+
defrun_parse(value):
168+
command= [
169+
sys.executable,
170+
"-c",
171+
f"from git.util import{name}; print(repr({name}))",
172+
]
173+
output=subprocess.check_output(
174+
command,
175+
env=NoneifvalueisNoneelsedict(os.environ,**{name:value}),
176+
text=True,
177+
)
178+
returnast.literal_eval(output)
179+
180+
forenv_var_value,expected_truth_valuein (
181+
(None,os.name=="nt"),# True on Windows when the environment variable is unset.
182+
("",False),
183+
(" ",False),
184+
("0",False),
185+
("1",os.name=="nt"),
186+
("false",False),
187+
("true",os.name=="nt"),
188+
("False",False),
189+
("True",os.name=="nt"),
190+
("no",False),
191+
("yes",os.name=="nt"),
192+
("NO",False),
193+
("YES",os.name=="nt"),
194+
(" no ",False),
195+
(" yes ",os.name=="nt"),
196+
):
197+
withself.subTest(env_var_value=env_var_value):
198+
self.assertIs(run_parse(env_var_value),expected_truth_value)
199+
151200
_norm_cygpath_pairs= (
152201
(R"foo\bar","foo/bar"),
153202
(R"foo/bar","foo/bar"),
@@ -504,38 +553,3 @@ def test_remove_password_from_command_line(self):
504553

505554
assertcmd_4==remove_password_if_present(cmd_4)
506555
assertcmd_5==remove_password_if_present(cmd_5)
507-
508-
@ddt.data("HIDE_WINDOWS_KNOWN_ERRORS","HIDE_WINDOWS_FREEZE_ERRORS")
509-
deftest_env_vars_for_windows_tests(self,name):
510-
defrun_parse(value):
511-
command= [
512-
sys.executable,
513-
"-c",
514-
f"from git.util import{name}; print(repr({name}))",
515-
]
516-
output=subprocess.check_output(
517-
command,
518-
env=NoneifvalueisNoneelsedict(os.environ,**{name:value}),
519-
text=True,
520-
)
521-
returnast.literal_eval(output)
522-
523-
forenv_var_value,expected_truth_valuein (
524-
(None,os.name=="nt"),# True on Windows when the environment variable is unset.
525-
("",False),
526-
(" ",False),
527-
("0",False),
528-
("1",os.name=="nt"),
529-
("false",False),
530-
("true",os.name=="nt"),
531-
("False",False),
532-
("True",os.name=="nt"),
533-
("no",False),
534-
("yes",os.name=="nt"),
535-
("NO",False),
536-
("YES",os.name=="nt"),
537-
(" no ",False),
538-
(" yes ",os.name=="nt"),
539-
):
540-
withself.subTest(env_var_value=env_var_value):
541-
self.assertIs(run_parse(env_var_value),expected_truth_value)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp