Skip to content

Commit 8bb0635

Browse files
committed
Add test capturing expectation.
1 parent 19ca481 commit 8bb0635

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

importlib_resources/tests/test_files.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import typing
2+
import textwrap
23
import unittest
34
import warnings
5+
import importlib
46
import contextlib
57

68
import importlib_resources as resources
@@ -84,5 +86,33 @@ def test_module_resources(self):
8486
assert actual == spec['res.txt']
8587

8688

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+
87117
if __name__ == '__main__':
88118
unittest.main()

0 commit comments

Comments
 (0)