8
8
9
9
class CommonBinaryTests (util .CommonTests , unittest .TestCase ):
10
10
def execute (self , package , path ):
11
- with util .suppress_known_deprecation ():
12
- resources .read_binary (package , path )
11
+ resources .files (package ).joinpath (path ).read_bytes ()
13
12
14
13
15
14
class CommonTextTests (util .CommonTests , unittest .TestCase ):
16
15
def execute (self , package , path ):
17
- with util .suppress_known_deprecation ():
18
- resources .read_text (package , path )
16
+ resources .files (package ).joinpath (path ).read_text ()
19
17
20
18
21
19
class ReadTests :
22
- def test_read_binary (self ):
23
- with util .suppress_known_deprecation ():
24
- result = resources .read_binary (self .data , 'binary.file' )
20
+ def test_read_bytes (self ):
21
+ result = resources .files (self .data ).joinpath ('binary.file' ).read_bytes ()
25
22
self .assertEqual (result , b'\0 \1 \2 \3 ' )
26
23
27
24
def test_read_text_default_encoding (self ):
28
- with util .suppress_known_deprecation ():
29
- result = resources .read_text (self .data , 'utf-8.file' )
25
+ result = resources .files (self .data ).joinpath ('utf-8.file' ).read_text ()
30
26
self .assertEqual (result , 'Hello, UTF-8 world!\n ' )
31
27
32
28
def test_read_text_given_encoding (self ):
33
- with util .suppress_known_deprecation ():
34
- result = resources .read_text (self .data , 'utf-16.file' , encoding = 'utf-16' )
29
+ result = (
30
+ resources .files (self .data )
31
+ .joinpath ('utf-16.file' )
32
+ .read_text (encoding = 'utf-16' )
33
+ )
35
34
self .assertEqual (result , 'Hello, UTF-16 world!\n ' )
36
35
37
36
def test_read_text_with_errors (self ):
38
37
# Raises UnicodeError without the 'errors' argument.
39
- with util .suppress_known_deprecation ():
40
- self .assertRaises (
41
- UnicodeError , resources .read_text , self .data , 'utf-16.file'
42
- )
43
- with util .suppress_known_deprecation ():
44
- result = resources .read_text (self .data , 'utf-16.file' , errors = 'ignore' )
38
+ target = resources .files (self .data ) / 'utf-16.file'
39
+ self .assertRaises (UnicodeError , target .read_text , encoding = 'utf-8' )
40
+ result = target .read_text (encoding = 'utf-8' , errors = 'ignore' )
45
41
self .assertEqual (
46
42
result ,
47
43
'H\x00 e\x00 l\x00 l\x00 o\x00 ,\x00 '
@@ -57,13 +53,15 @@ class ReadDiskTests(ReadTests, unittest.TestCase):
57
53
class ReadZipTests (ReadTests , util .ZipSetup , unittest .TestCase ):
58
54
def test_read_submodule_resource (self ):
59
55
submodule = import_module ('ziptestdata.subdirectory' )
60
- with util .suppress_known_deprecation ():
61
- result = resources .read_binary (submodule , 'binary.file' )
56
+ result = resources .files (submodule ).joinpath ('binary.file' ).read_bytes ()
62
57
self .assertEqual (result , b'\0 \1 \2 \3 ' )
63
58
64
59
def test_read_submodule_resource_by_name (self ):
65
- with util .suppress_known_deprecation ():
66
- result = resources .read_binary ('ziptestdata.subdirectory' , 'binary.file' )
60
+ result = (
61
+ resources .files ('ziptestdata.subdirectory' )
62
+ .joinpath ('binary.file' )
63
+ .read_bytes ()
64
+ )
67
65
self .assertEqual (result , b'\0 \1 \2 \3 ' )
68
66
69
67
0 commit comments