1import typing 2import unittest 3 4from importlib import resources 5from importlib.abc import Traversable 6from . import data01 7from .resources import util 8 9 10class FilesTests: 11 def test_read_bytes(self): 12 files = resources.files(self.data) 13 actual = files.joinpath('utf-8.file').read_bytes() 14 assert actual == b'Hello, UTF-8 world!\n' 15 16 def test_read_text(self): 17 files = resources.files(self.data) 18 actual = files.joinpath('utf-8.file').read_text(encoding='utf-8') 19 assert actual == 'Hello, UTF-8 world!\n' 20 21 @unittest.skipUnless( 22 hasattr(typing, 'runtime_checkable'), 23 "Only suitable when typing supports runtime_checkable", 24 ) 25 def test_traversable(self): 26 assert isinstance(resources.files(self.data), Traversable) 27 28 29class OpenDiskTests(FilesTests, unittest.TestCase): 30 def setUp(self): 31 self.data = data01 32 33 34class OpenZipTests(FilesTests, util.ZipSetup, unittest.TestCase): 35 pass 36 37 38class OpenNamespaceTests(FilesTests, unittest.TestCase): 39 def setUp(self): 40 from . import namespacedata01 41 42 self.data = namespacedata01 43 44 45if __name__ == '__main__': 46 unittest.main() 47