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
4
+ import importlib
3
5
import contextlib
4
6
5
7
import importlib_resources as resources
@@ -68,5 +70,33 @@ def test_module_resources(self):
68
70
assert actual == spec ['res.txt' ]
69
71
70
72
73
+ class ImplicitContextFilesTests (unittest .TestCase ):
74
+ def setUp (self ):
75
+ self .fixtures = contextlib .ExitStack ()
76
+ self .addCleanup (self .fixtures .close )
77
+ self .site_dir = self .fixtures .enter_context (os_helper .temp_dir ())
78
+ self .fixtures .enter_context (import_helper .DirsOnSysPath (self .site_dir ))
79
+ self .fixtures .enter_context (import_helper .CleanImport ())
80
+
81
+ @__import__ ('pytest' ).mark .xfail (reason = "work in progress" )
82
+ def test_implicit_files (self ):
83
+ """
84
+ Without any parameter, files() will infer the location as the caller.
85
+ """
86
+ spec = {
87
+ 'somepkg' : {
88
+ '__init__.py' : textwrap .dedent (
89
+ """
90
+ import importlib_resources as res
91
+ val = res.files().joinpath('res.txt').read_text()
92
+ """
93
+ ),
94
+ 'res.txt' : 'resources are the best' ,
95
+ },
96
+ }
97
+ _path .build (spec , self .site_dir )
98
+ assert importlib .import_module ('somepkg' ).val == 'resources are the best'
99
+
100
+
71
101
if __name__ == '__main__' :
72
102
unittest .main ()
You can’t perform that action at this time.
0 commit comments