File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
importlib_resources/tests Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 1
1
import typing
2
+ import textwrap
2
3
import unittest
3
4
import warnings
5
+ import importlib
4
6
import contextlib
5
7
6
8
import importlib_resources as resources
@@ -84,5 +86,33 @@ def test_module_resources(self):
84
86
assert actual == spec ['res.txt' ]
85
87
86
88
89
+ class ImplicitContextFilesTests (unittest .TestCase ):
90
+ def setUp (self ):
91
+ self .fixtures = contextlib .ExitStack ()
92
+ self .addCleanup (self .fixtures .close )
93
+ self .site_dir = self .fixtures .enter_context (os_helper .temp_dir ())
94
+ self .fixtures .enter_context (import_helper .DirsOnSysPath (self .site_dir ))
95
+ self .fixtures .enter_context (import_helper .CleanImport ())
96
+
97
+ @__import__ ('pytest' ).mark .xfail (reason = "work in progress" )
98
+ def test_implicit_files (self ):
99
+ """
100
+ Without any parameter, files() will infer the location as the caller.
101
+ """
102
+ spec = {
103
+ 'somepkg' : {
104
+ '__init__.py' : textwrap .dedent (
105
+ """
106
+ import importlib_resources as res
107
+ val = res.files().joinpath('res.txt').read_text()
108
+ """
109
+ ),
110
+ 'res.txt' : 'resources are the best' ,
111
+ },
112
+ }
113
+ _path .build (spec , self .site_dir )
114
+ assert importlib .import_module ('somepkg' ).val == 'resources are the best'
115
+
116
+
87
117
if __name__ == '__main__' :
88
118
unittest .main ()
You can’t perform that action at this time.
0 commit comments