@@ -87,7 +87,14 @@ def test_rmtree_deletes_nested_dir_with_files(self):
8787 td = pathlib .Path (parent , "testdir" )
8888 for d in td , td / "q" , td / "s" :
8989 d .mkdir ()
90- for f in td / "p" , td / "q" / "w" , td / "q" / "x" , td / "r" , td / "s" / "y" , td / "s" / "z" :
90+ for f in (
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 def test_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 def test_rmtree_can_wrap_exceptions (self ):
120- """Our rmtree 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 () as td :
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 def test_rmtree_does_not_wrap_unless_called_for (self , case ):
138- """Our rmtree doesn't wrap non-PermissionError, nor when HIDE_WINDOWS_KNOWN_ERRORS is false."""
148+ """rmtree doesn't wrap non-PermissionError, nor if HIDE_WINDOWS_KNOWN_ERRORS is false."""
139149 hide_windows_known_errors , exception_type , tmpdir_context_factory = case
140150
141151 with tmpdir_context_factory () as td :
142152 # See comments in test_rmtree_can_wrap_exceptions regarding the patching done here.
143- with mock .patch .object (sys .modules ["git.util" ], "HIDE_WINDOWS_KNOWN_ERRORS" , hide_windows_known_errors ):
153+ with mock .patch .object (
154+ sys .modules ["git.util" ],
155+ "HIDE_WINDOWS_KNOWN_ERRORS" ,
156+ hide_windows_known_errors ,
157+ ):
144158 with mock .patch .object (os , "chmod" ), mock .patch .object (pathlib .Path , "chmod" ):
145159 with self .assertRaises (exception_type ):
146160 try :
147161 rmtree (td )
148162 except SkipTest as ex :
149163 self .fail (f"rmtree unexpectedly attempts skip: { ex !r} " )
150164
165+ @ddt .data ("HIDE_WINDOWS_KNOWN_ERRORS" , "HIDE_WINDOWS_FREEZE_ERRORS" )
166+ def test_env_vars_for_windows_tests (self , name ):
167+ def run_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 = None if value is None else dict (os .environ , ** {name : value }),
176+ text = True ,
177+ )
178+ return ast .literal_eval (output )
179+
180+ for env_var_value , expected_truth_value in (
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+ with self .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 assert cmd_4 == remove_password_if_present (cmd_4 )
506555 assert cmd_5 == remove_password_if_present (cmd_5 )
507-
508- @ddt .data ("HIDE_WINDOWS_KNOWN_ERRORS" , "HIDE_WINDOWS_FREEZE_ERRORS" )
509- def test_env_vars_for_windows_tests (self , name ):
510- def run_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 = None if value is None else dict (os .environ , ** {name : value }),
519- text = True ,
520- )
521- return ast .literal_eval (output )
522-
523- for env_var_value , expected_truth_value in (
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- with self .subTest (env_var_value = env_var_value ):
541- self .assertIs (run_parse (env_var_value ), expected_truth_value )
0 commit comments