77import importlib_resources as resources
88from ..abc import Traversable
99from . import util
10- from . import _path
1110from .compat .py39 import os_helper
1211from .compat .py312 import import_helper
1312
@@ -72,12 +71,22 @@ def setUp(self):
7271 self .fixtures .enter_context (import_helper .isolated_modules ())
7372
7473
74+ class DirectSpec :
75+ """
76+ Override behavior of ModuleSetup to write a full spec directly.
77+ """
78+
79+ MODULE = 'unused'
80+
81+ def load_fixture (self , name ):
82+ self .tree_on_path (self .spec )
83+
84+
7585class ModulesFiles :
7686 spec = {
7787 'mod.py' : '' ,
7888 'res.txt' : 'resources are the best' ,
7989 }
80- MODULE = 'unused'
8190
8291 def test_module_resources (self ):
8392 """
@@ -88,33 +97,36 @@ def test_module_resources(self):
8897 actual = resources .files (mod ).joinpath ('res.txt' ).read_text (encoding = 'utf-8' )
8998 assert actual == self .spec ['res.txt' ]
9099
91- def load_fixture (self , name ):
92- self .tree_on_path (self .spec )
93-
94100
95- class ModuleFilesDiskTests (ModulesFiles , util .DiskSetup , unittest .TestCase ):
101+ class ModuleFilesDiskTests (DirectSpec , util .DiskSetup , ModulesFiles , unittest .TestCase ):
96102 pass
97103
98104
99- class ImplicitContextFilesTests (SiteDir , unittest .TestCase ):
105+ class ImplicitContextFiles :
106+ spec = {
107+ 'somepkg' : {
108+ '__init__.py' : textwrap .dedent (
109+ """
110+ import importlib_resources as res
111+ val = res.files().joinpath('res.txt').read_text(encoding='utf-8')
112+ """
113+ ),
114+ 'res.txt' : 'resources are the best' ,
115+ },
116+ }
117+
100118 def test_implicit_files (self ):
101119 """
102120 Without any parameter, files() will infer the location as the caller.
103121 """
104- spec = {
105- 'somepkg' : {
106- '__init__.py' : textwrap .dedent (
107- """
108- import importlib_resources as res
109- val = res.files().joinpath('res.txt').read_text(encoding='utf-8')
110- """
111- ),
112- 'res.txt' : 'resources are the best' ,
113- },
114- }
115- _path .build (spec , self .site_dir )
116122 assert importlib .import_module ('somepkg' ).val == 'resources are the best'
117123
118124
125+ class ImplicitContextFilesDiskTests (
126+ DirectSpec , util .DiskSetup , ImplicitContextFiles , unittest .TestCase
127+ ):
128+ pass
129+
130+
119131if __name__ == '__main__' :
120132 unittest .main ()
0 commit comments