Skip to content

Commit 74528ef

Browse files
committed
Add test capturing expectation.
1 parent 091f229 commit 74528ef

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,5 +1,7 @@
11
import typing
2+
import textwrap
23
import unittest
4+
import importlib
35
import contextlib
46

57
import importlib_resources as resources
@@ -68,5 +70,33 @@ def test_module_resources(self):
6870
assert actual == spec['res.txt']
6971

7072

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

0 commit comments

Comments
 (0)