File tree Expand file tree Collapse file tree 3 files changed +3
-28
lines changed
Expand file tree Collapse file tree 3 files changed +3
-28
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ def files(package):
1919 """
2020 Get a Traversable resource from a package
2121 """
22- return from_package (get_package (package ))
22+ return from_package (resolve (package ))
2323
2424
2525def get_resource_reader (package ):
@@ -44,18 +44,6 @@ def resolve(cand):
4444 return cand if isinstance (cand , types .ModuleType ) else importlib .import_module (cand )
4545
4646
47- def get_package (package ):
48- # type: (Package) -> types.ModuleType
49- """Take a package name or module object and return the module.
50-
51- Raise an exception if the resolved module is not a package.
52- """
53- resolved = resolve (package )
54- if wrap_spec (resolved ).submodule_search_locations is None :
55- raise TypeError (f'{ package !r} is not a package' )
56- return resolved
57-
58-
5947def from_package (package ):
6048 """
6149 Return a Traversable object for the given package.
Original file line number Diff line number Diff line change @@ -64,10 +64,8 @@ def test_module_resources(self):
6464 _path .build (spec , self .site_dir )
6565 import mod
6666
67- # currently a failure occurs; ref #203
68- with self .assertRaisesRegex (TypeError , '.*mod.* is not a package' ):
69- actual = resources .files (mod ).joinpath ('res.txt' ).read_text ()
70- assert actual == spec ['res.txt' ]
67+ actual = resources .files (mod ).joinpath ('res.txt' ).read_text ()
68+ assert actual == spec ['res.txt' ]
7169
7270
7371if __name__ == '__main__' :
Original file line number Diff line number Diff line change @@ -102,17 +102,6 @@ def test_importing_module_as_side_effect(self):
102102 del sys .modules [data01 .__name__ ]
103103 self .execute (data01 .__name__ , 'utf-8.file' )
104104
105- def test_non_package_by_name (self ):
106- # The anchor package cannot be a module.
107- with self .assertRaises (TypeError ):
108- self .execute (__name__ , 'utf-8.file' )
109-
110- def test_non_package_by_package (self ):
111- # The anchor package cannot be a module.
112- with self .assertRaises (TypeError ):
113- module = sys .modules ['importlib_resources.tests.util' ]
114- self .execute (module , 'utf-8.file' )
115-
116105 def test_missing_path (self ):
117106 # Attempting to open or read or request the path for a
118107 # non-existent path should succeed if open_resource
You can’t perform that action at this time.
0 commit comments