003 File Manager
Current Path:
/usr/local/lib/python3.8/test/test_importlib
usr
/
local
/
lib
/
python3.8
/
test
/
test_importlib
/
📁
..
📄
__init__.py
(142 B)
📄
__main__.py
(58 B)
📁
__pycache__
📄
abc.py
(2.22 KB)
📁
builtin
📁
data
📁
data01
📁
data02
📁
data03
📁
extension
📄
fixtures.py
(4.99 KB)
📁
frozen
📁
import_
📁
namespace_pkgs
📁
source
📄
stubs.py
(233 B)
📄
test_abc.py
(33.07 KB)
📄
test_api.py
(18.36 KB)
📄
test_lazy.py
(4.81 KB)
📄
test_locks.py
(4.55 KB)
📄
test_main.py
(7.66 KB)
📄
test_metadata_api.py
(5.01 KB)
📄
test_namespace_pkgs.py
(10.57 KB)
📄
test_open.py
(2.2 KB)
📄
test_path.py
(1.53 KB)
📄
test_read.py
(1.99 KB)
📄
test_resource.py
(8.36 KB)
📄
test_spec.py
(30.38 KB)
📄
test_util.py
(34.67 KB)
📄
test_windows.py
(5.83 KB)
📄
test_zip.py
(2.41 KB)
📄
util.py
(18.04 KB)
📁
zipdata01
📁
zipdata02
Editing: test_open.py
import unittest from importlib import resources from . import data01 from . import util class CommonBinaryTests(util.CommonResourceTests, unittest.TestCase): def execute(self, package, path): with resources.open_binary(package, path): pass class CommonTextTests(util.CommonResourceTests, unittest.TestCase): def execute(self, package, path): with resources.open_text(package, path): pass class OpenTests: def test_open_binary(self): with resources.open_binary(self.data, 'binary.file') as fp: result = fp.read() self.assertEqual(result, b'\x00\x01\x02\x03') def test_open_text_default_encoding(self): with resources.open_text(self.data, 'utf-8.file') as fp: result = fp.read() self.assertEqual(result, 'Hello, UTF-8 world!\n') def test_open_text_given_encoding(self): with resources.open_text( self.data, 'utf-16.file', 'utf-16', 'strict') as fp: result = fp.read() self.assertEqual(result, 'Hello, UTF-16 world!\n') def test_open_text_with_errors(self): # Raises UnicodeError without the 'errors' argument. with resources.open_text( self.data, 'utf-16.file', 'utf-8', 'strict') as fp: self.assertRaises(UnicodeError, fp.read) with resources.open_text( self.data, 'utf-16.file', 'utf-8', 'ignore') as fp: result = fp.read() self.assertEqual( result, 'H\x00e\x00l\x00l\x00o\x00,\x00 ' '\x00U\x00T\x00F\x00-\x001\x006\x00 ' '\x00w\x00o\x00r\x00l\x00d\x00!\x00\n\x00') def test_open_binary_FileNotFoundError(self): self.assertRaises( FileNotFoundError, resources.open_binary, self.data, 'does-not-exist') def test_open_text_FileNotFoundError(self): self.assertRaises( FileNotFoundError, resources.open_text, self.data, 'does-not-exist') class OpenDiskTests(OpenTests, unittest.TestCase): def setUp(self): self.data = data01 class OpenZipTests(OpenTests, util.ZipSetup, unittest.TestCase): pass if __name__ == '__main__': unittest.main()
Upload File
Create Folder