diff options
author | Barry Warsaw <barry@python.org> | 2017-12-30 20:18:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-30 20:18:06 (GMT) |
commit | deae6b451fefd5fd3143dd65051e1d341e5a5f84 (patch) | |
tree | 21d0732eb5dd8f7d5ca469b39a1f3b703f3f83f3 /Lib/test/test_importlib/test_path.py | |
parent | ffcb4c0165827d0a48ea973cc88bc134c74879fb (diff) | |
download | cpython-deae6b451fefd5fd3143dd65051e1d341e5a5f84.zip cpython-deae6b451fefd5fd3143dd65051e1d341e5a5f84.tar.gz cpython-deae6b451fefd5fd3143dd65051e1d341e5a5f84.tar.bz2 |
bpo-32248 - Implement importlib.resources (#4911)
Port importlib_resources to importlib.resources
Diffstat (limited to 'Lib/test/test_importlib/test_path.py')
-rw-r--r-- | Lib/test/test_importlib/test_path.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Lib/test/test_importlib/test_path.py b/Lib/test/test_importlib/test_path.py new file mode 100644 index 0000000..2d3dcda --- /dev/null +++ b/Lib/test/test_importlib/test_path.py @@ -0,0 +1,39 @@ +import unittest + +from importlib import resources +from . import data01 +from . import util + + +class CommonTests(util.CommonResourceTests, unittest.TestCase): + def execute(self, package, path): + with resources.path(package, path): + pass + + +class PathTests: + def test_reading(self): + # Path should be readable. + # Test also implicitly verifies the returned object is a pathlib.Path + # instance. + with resources.path(self.data, 'utf-8.file') as path: + # pathlib.Path.read_text() was introduced in Python 3.5. + with path.open('r', encoding='utf-8') as file: + text = file.read() + self.assertEqual('Hello, UTF-8 world!\n', text) + + +class PathDiskTests(PathTests, unittest.TestCase): + data = data01 + + +class PathZipTests(PathTests, util.ZipSetup, unittest.TestCase): + def test_remove_in_context_manager(self): + # It is not an error if the file that was temporarily stashed on the + # file system is removed inside the `with` stanza. + with resources.path(self.data, 'utf-8.file') as path: + path.unlink() + + +if __name__ == '__main__': + unittest.main() |