7
7
8
8
class CommonBinaryTests (util .CommonTests , unittest .TestCase ):
9
9
def execute (self , package , path ):
10
- with util . suppress_known_deprecation ():
11
- with resources . open_binary ( package , path ):
12
- pass
10
+ target = resources . files ( package ). joinpath ( path )
11
+ with target . open ( 'rb' ):
12
+ pass
13
13
14
14
15
15
class CommonTextTests (util .CommonTests , unittest .TestCase ):
16
16
def execute (self , package , path ):
17
- with util . suppress_known_deprecation ():
18
- with resources . open_text ( package , path ):
19
- pass
17
+ target = resources . files ( package ). joinpath ( path )
18
+ with target . open ( ):
19
+ pass
20
20
21
21
22
22
class OpenTests :
23
23
def test_open_binary (self ):
24
- with util . suppress_known_deprecation ():
25
- with resources . open_binary ( self . data , 'binary.file ' ) as fp :
26
- result = fp .read ()
27
- self .assertEqual (result , b'\x00 \x01 \x02 \x03 ' )
24
+ target = resources . files ( self . data ) / 'binary.file'
25
+ with target . open ( 'rb ' ) as fp :
26
+ result = fp .read ()
27
+ self .assertEqual (result , b'\x00 \x01 \x02 \x03 ' )
28
28
29
29
def test_open_text_default_encoding (self ):
30
- with util . suppress_known_deprecation ():
31
- with resources . open_text ( self . data , 'utf-8.file' ) as fp :
32
- result = fp .read ()
30
+ target = resources . files ( self . data ) / 'utf-8.file'
31
+ with target . open ( ) as fp :
32
+ result = fp .read ()
33
33
self .assertEqual (result , 'Hello, UTF-8 world!\n ' )
34
34
35
35
def test_open_text_given_encoding (self ):
36
- with util .suppress_known_deprecation ():
37
- with resources .open_text (
38
- self .data , 'utf-16.file' , 'utf-16' , 'strict'
39
- ) as fp :
40
- result = fp .read ()
36
+ target = resources .files (self .data ) / 'utf-16.file'
37
+ with target .open (encoding = 'utf-16' , errors = 'strict' ) as fp :
38
+ result = fp .read ()
41
39
self .assertEqual (result , 'Hello, UTF-16 world!\n ' )
42
40
43
41
def test_open_text_with_errors (self ):
44
42
# Raises UnicodeError without the 'errors' argument.
45
- with util .suppress_known_deprecation ():
46
- with resources .open_text (self .data , 'utf-16.file' , 'utf-8' , 'strict' ) as fp :
47
- self .assertRaises (UnicodeError , fp .read )
48
- with util .suppress_known_deprecation ():
49
- with resources .open_text (self .data , 'utf-16.file' , 'utf-8' , 'ignore' ) as fp :
50
- result = fp .read ()
43
+ target = resources .files (self .data ) / 'utf-16.file'
44
+ with target .open (encoding = 'utf-8' , errors = 'strict' ) as fp :
45
+ self .assertRaises (UnicodeError , fp .read )
46
+ with target .open (encoding = 'utf-8' , errors = 'ignore' ) as fp :
47
+ result = fp .read ()
51
48
self .assertEqual (
52
49
result ,
53
50
'H\x00 e\x00 l\x00 l\x00 o\x00 ,\x00 '
@@ -56,16 +53,12 @@ def test_open_text_with_errors(self):
56
53
)
57
54
58
55
def test_open_binary_FileNotFoundError (self ):
59
- with util .suppress_known_deprecation ():
60
- self .assertRaises (
61
- FileNotFoundError , resources .open_binary , self .data , 'does-not-exist'
62
- )
56
+ target = resources .files (self .data ) / 'does-not-exist'
57
+ self .assertRaises (FileNotFoundError , target .open , 'rb' )
63
58
64
59
def test_open_text_FileNotFoundError (self ):
65
- with util .suppress_known_deprecation ():
66
- self .assertRaises (
67
- FileNotFoundError , resources .open_text , self .data , 'does-not-exist'
68
- )
60
+ target = resources .files (self .data ) / 'does-not-exist'
61
+ self .assertRaises (FileNotFoundError , target .open )
69
62
70
63
71
64
class OpenDiskTests (OpenTests , unittest .TestCase ):
0 commit comments