@@ -48,15 +48,19 @@ def tearDown(self) -> None:
48
48
del sys .path_importer_cache [k ]
49
49
50
50
def test_find_zipped_module (self ) -> None :
51
- found_spec = spec .find_spec ([self .package ], [resources .find ("data/MyPyPa-0.1.0-py2.5.zip" )])
51
+ found_spec = spec .find_spec (
52
+ [self .package ], [resources .find ("data/MyPyPa-0.1.0-py2.5.zip" )]
53
+ )
52
54
self .assertEqual (found_spec .type , spec .ModuleType .PY_ZIPMODULE )
53
55
self .assertEqual (
54
56
found_spec .location .split (os .sep )[- 3 :],
55
57
["data" , "MyPyPa-0.1.0-py2.5.zip" , self .package ],
56
58
)
57
59
58
60
def test_find_egg_module (self ) -> None :
59
- found_spec = spec .find_spec ([self .package ], [resources .find ("data/MyPyPa-0.1.0-py2.5.egg" )])
61
+ found_spec = spec .find_spec (
62
+ [self .package ], [resources .find ("data/MyPyPa-0.1.0-py2.5.egg" )]
63
+ )
60
64
self .assertEqual (found_spec .type , spec .ModuleType .PY_ZIPMODULE )
61
65
self .assertEqual (
62
66
found_spec .location .split (os .sep )[- 3 :],
@@ -74,7 +78,9 @@ def test_known_values_load_module_from_name_2(self) -> None:
74
78
self .assertEqual (modutils .load_module_from_name ("os.path" ), os .path )
75
79
76
80
def test_raise_load_module_from_name_1 (self ) -> None :
77
- self .assertRaises (ImportError , modutils .load_module_from_name , "_this_module_does_not_exist_" )
81
+ self .assertRaises (
82
+ ImportError , modutils .load_module_from_name , "_this_module_does_not_exist_"
83
+ )
78
84
79
85
80
86
def test_import_dotted_library (
@@ -113,7 +119,9 @@ class GetModulePartTest(unittest.TestCase):
113
119
"""Given a dotted name return the module part of the name."""
114
120
115
121
def test_known_values_get_module_part_1 (self ) -> None :
116
- self .assertEqual (modutils .get_module_part ("astroid.modutils" ), "astroid.modutils" )
122
+ self .assertEqual (
123
+ modutils .get_module_part ("astroid.modutils" ), "astroid.modutils"
124
+ )
117
125
118
126
def test_known_values_get_module_part_2 (self ) -> None :
119
127
self .assertEqual (
@@ -137,7 +145,9 @@ def test_known_values_get_builtin_module_part(self) -> None:
137
145
self .assertEqual (modutils .get_module_part ("sys.path" , "__file__" ), "sys" )
138
146
139
147
def test_get_module_part_exception (self ) -> None :
140
- self .assertRaises (ImportError , modutils .get_module_part , "unknown.module" , modutils .__file__ )
148
+ self .assertRaises (
149
+ ImportError , modutils .get_module_part , "unknown.module" , modutils .__file__
150
+ )
141
151
142
152
def test_get_module_part_only_dot (self ) -> None :
143
153
self .assertEqual (modutils .get_module_part ("." , modutils .__file__ ), "." )
@@ -160,7 +170,9 @@ def test_import_symlink_with_source_outside_of_path(self) -> None:
160
170
linked_file_name = "symlinked_file.py"
161
171
try :
162
172
os .symlink (tmpfile .name , linked_file_name )
163
- self .assertEqual (modutils .modpath_from_file (linked_file_name ), ["symlinked_file" ])
173
+ self .assertEqual (
174
+ modutils .modpath_from_file (linked_file_name ), ["symlinked_file" ]
175
+ )
164
176
finally :
165
177
os .remove (linked_file_name )
166
178
@@ -184,7 +196,9 @@ def test_modpath_from_file_path_order(self) -> None:
184
196
pass
185
197
186
198
# Without additional directory, return relative to tmp_dir
187
- self .assertEqual (modutils .modpath_from_file (module_file ), [sub_dirname , mod_name ])
199
+ self .assertEqual (
200
+ modutils .modpath_from_file (module_file ), [sub_dirname , mod_name ]
201
+ )
188
202
189
203
# With sub directory as additional directory, return relative to
190
204
# sub directory
@@ -198,7 +212,9 @@ def test_import_symlink_both_outside_of_path(self) -> None:
198
212
linked_file_name = os .path .join (tempfile .gettempdir (), "symlinked_file.py" )
199
213
try :
200
214
os .symlink (tmpfile .name , linked_file_name )
201
- self .assertRaises (ImportError , modutils .modpath_from_file , linked_file_name )
215
+ self .assertRaises (
216
+ ImportError , modutils .modpath_from_file , linked_file_name
217
+ )
202
218
finally :
203
219
os .remove (linked_file_name )
204
220
@@ -300,7 +316,9 @@ def test_unicode_in_package_init(self) -> None:
300
316
class GetSourceFileTest (unittest .TestCase ):
301
317
def test (self ) -> None :
302
318
filename = _get_file_from_object (os .path )
303
- self .assertEqual (modutils .get_source_file (os .path .__file__ ), os .path .normpath (filename ))
319
+ self .assertEqual (
320
+ modutils .get_source_file (os .path .__file__ ), os .path .normpath (filename )
321
+ )
304
322
305
323
def test_raise (self ) -> None :
306
324
self .assertRaises (modutils .NoSourceFile , modutils .get_source_file , "whatever" )
@@ -389,7 +407,9 @@ def test_custom_path(self) -> None:
389
407
with pytest .warns (DeprecationWarning ):
390
408
assert modutils .is_standard_module ("data.module" , (datadir ,))
391
409
with pytest .warns (DeprecationWarning ):
392
- assert modutils .is_standard_module ("data.module" , (os .path .abspath (datadir ),))
410
+ assert modutils .is_standard_module (
411
+ "data.module" , (os .path .abspath (datadir ),)
412
+ )
393
413
# "" will evaluate to cwd
394
414
with pytest .warns (DeprecationWarning ):
395
415
assert modutils .is_standard_module ("data.module" , ("" ,))
@@ -503,10 +523,16 @@ def test_known_values_is_relative_3(self) -> None:
503
523
self .assertFalse (modutils .is_relative ("astroid" , astroid .__path__ [0 ]))
504
524
505
525
def test_known_values_is_relative_4 (self ) -> None :
506
- self .assertTrue (modutils .is_relative ("util" , astroid .interpreter ._import .spec .__file__ ))
526
+ self .assertTrue (
527
+ modutils .is_relative ("util" , astroid .interpreter ._import .spec .__file__ )
528
+ )
507
529
508
530
def test_known_values_is_relative_5 (self ) -> None :
509
- self .assertFalse (modutils .is_relative ("objectmodel" , astroid .interpreter ._import .spec .__file__ ))
531
+ self .assertFalse (
532
+ modutils .is_relative (
533
+ "objectmodel" , astroid .interpreter ._import .spec .__file__
534
+ )
535
+ )
510
536
511
537
def test_deep_relative (self ) -> None :
512
538
self .assertTrue (modutils .is_relative ("ElementTree" , xml .etree .__path__ [0 ]))
@@ -521,7 +547,9 @@ def test_deep_relative4(self) -> None:
521
547
self .assertTrue (modutils .is_relative ("etree.gibberish" , xml .__path__ [0 ]))
522
548
523
549
def test_is_relative_bad_path (self ) -> None :
524
- self .assertFalse (modutils .is_relative ("ElementTree" , os .path .join (xml .__path__ [0 ], "ftree" )))
550
+ self .assertFalse (
551
+ modutils .is_relative ("ElementTree" , os .path .join (xml .__path__ [0 ], "ftree" ))
552
+ )
525
553
526
554
527
555
class GetModuleFilesTest (unittest .TestCase ):
@@ -567,18 +595,38 @@ def test_load_module_set_attribute(self) -> None:
567
595
568
596
class ExtensionPackageWhitelistTest (unittest .TestCase ):
569
597
def test_is_module_name_part_of_extension_package_whitelist_true (self ) -> None :
570
- self .assertTrue (modutils .is_module_name_part_of_extension_package_whitelist ("numpy" , {"numpy" }))
571
- self .assertTrue (modutils .is_module_name_part_of_extension_package_whitelist ("numpy.core" , {"numpy" }))
572
598
self .assertTrue (
573
- modutils .is_module_name_part_of_extension_package_whitelist ("numpy.core.umath" , {"numpy" })
599
+ modutils .is_module_name_part_of_extension_package_whitelist (
600
+ "numpy" , {"numpy" }
601
+ )
602
+ )
603
+ self .assertTrue (
604
+ modutils .is_module_name_part_of_extension_package_whitelist (
605
+ "numpy.core" , {"numpy" }
606
+ )
607
+ )
608
+ self .assertTrue (
609
+ modutils .is_module_name_part_of_extension_package_whitelist (
610
+ "numpy.core.umath" , {"numpy" }
611
+ )
574
612
)
575
613
576
614
def test_is_module_name_part_of_extension_package_whitelist_success (self ) -> None :
577
- self .assertFalse (modutils .is_module_name_part_of_extension_package_whitelist ("numpy" , {"numpy.core" }))
578
615
self .assertFalse (
579
- modutils .is_module_name_part_of_extension_package_whitelist ("numpy.core" , {"numpy.core.umath" })
616
+ modutils .is_module_name_part_of_extension_package_whitelist (
617
+ "numpy" , {"numpy.core" }
618
+ )
619
+ )
620
+ self .assertFalse (
621
+ modutils .is_module_name_part_of_extension_package_whitelist (
622
+ "numpy.core" , {"numpy.core.umath" }
623
+ )
624
+ )
625
+ self .assertFalse (
626
+ modutils .is_module_name_part_of_extension_package_whitelist (
627
+ "core.umath" , {"numpy" }
628
+ )
580
629
)
581
- self .assertFalse (modutils .is_module_name_part_of_extension_package_whitelist ("core.umath" , {"numpy" }))
582
630
583
631
584
632
@pytest .mark .skipif (not HAS_URLLIB3_V1 , reason = "This test requires urllib3 < 2." )
0 commit comments