@@ -51,28 +51,27 @@ def remove_utf16_bom(string):
5151 return string
5252
5353 def test_read_text (self ):
54- self .assertEqual (
55- resources .read_text (self .anchor01 , 'utf-8.file' ),
56- 'Hello, UTF-8 world!\n ' ,
54+ assert (
55+ resources .read_text (self .anchor01 , 'utf-8.file' ) == 'Hello, UTF-8 world!\n '
5756 )
58- self . assertEqual (
57+ assert (
5958 resources .read_text (
6059 self .anchor02 ,
6160 'subdirectory' ,
6261 'subsubdir' ,
6362 'resource.txt' ,
6463 encoding = 'utf-8' ,
65- ),
66- 'a resource' ,
64+ )
65+ == 'a resource'
6766 )
6867 for path_parts in self ._gen_resourcetxt_path_parts ():
69- self . assertEqual (
68+ assert (
7069 resources .read_text (
7170 self .anchor02 ,
7271 * path_parts ,
7372 encoding = 'utf-8' ,
74- ),
75- 'a resource' ,
73+ )
74+ == 'a resource'
7675 )
7776 # Use generic OSError, since e.g. attempting to read a directory can
7877 # fail with PermissionError rather than IsADirectoryError
@@ -82,48 +81,42 @@ def test_read_text(self):
8281 resources .read_text (self .anchor01 , 'no-such-file' )
8382 with self .assertRaises (UnicodeDecodeError ):
8483 resources .read_text (self .anchor01 , 'utf-16.file' )
85- self . assertEqual (
84+ assert (
8685 resources .read_text (
8786 self .anchor01 ,
8887 'binary.file' ,
8988 encoding = 'latin1' ,
90- ),
91- '\x00 \x01 \x02 \x03 ' ,
89+ )
90+ == '\x00 \x01 \x02 \x03 '
9291 )
93- self .assertEqual (
94- self .remove_utf16_bom (
95- resources .read_text (
96- self .anchor01 ,
97- 'utf-16.file' ,
98- errors = 'backslashreplace' ,
99- ),
100- ),
101- 'Hello, UTF-16 world!\n ' .encode ('utf-16-le' ).decode (
92+ assert self .remove_utf16_bom (
93+ resources .read_text (
94+ self .anchor01 ,
95+ 'utf-16.file' ,
10296 errors = 'backslashreplace' ,
10397 ),
98+ ) == 'Hello, UTF-16 world!\n ' .encode ('utf-16-le' ).decode (
99+ errors = 'backslashreplace' ,
104100 )
105101
106102 def test_read_binary (self ):
107- self . assertEqual (
108- resources .read_binary (self .anchor01 , 'utf-8.file' ),
109- b'Hello, UTF-8 world!\n ' ,
103+ assert (
104+ resources .read_binary (self .anchor01 , 'utf-8.file' )
105+ == b'Hello, UTF-8 world!\n '
110106 )
111107 for path_parts in self ._gen_resourcetxt_path_parts ():
112- self .assertEqual (
113- resources .read_binary (self .anchor02 , * path_parts ),
114- b'a resource' ,
115- )
108+ assert resources .read_binary (self .anchor02 , * path_parts ) == b'a resource'
116109
117110 def test_open_text (self ):
118111 with resources .open_text (self .anchor01 , 'utf-8.file' ) as f :
119- self . assertEqual ( f .read (), 'Hello, UTF-8 world!\n ' )
112+ assert f .read () == 'Hello, UTF-8 world!\n '
120113 for path_parts in self ._gen_resourcetxt_path_parts ():
121114 with resources .open_text (
122115 self .anchor02 ,
123116 * path_parts ,
124117 encoding = 'utf-8' ,
125118 ) as f :
126- self . assertEqual ( f .read (), 'a resource' )
119+ assert f .read () == 'a resource'
127120 # Use generic OSError, since e.g. attempting to read a directory can
128121 # fail with PermissionError rather than IsADirectoryError
129122 with self .assertRaises (OSError ):
@@ -138,53 +131,49 @@ def test_open_text(self):
138131 'binary.file' ,
139132 encoding = 'latin1' ,
140133 ) as f :
141- self . assertEqual ( f .read (), '\x00 \x01 \x02 \x03 ' )
134+ assert f .read () == '\x00 \x01 \x02 \x03 '
142135 with resources .open_text (
143136 self .anchor01 ,
144137 'utf-16.file' ,
145138 errors = 'backslashreplace' ,
146139 ) as f :
147- self .assertEqual (
148- self .remove_utf16_bom (f .read ()),
149- 'Hello, UTF-16 world!\n ' .encode ('utf-16-le' ).decode (
150- errors = 'backslashreplace' ,
151- ),
140+ assert self .remove_utf16_bom (f .read ()) == 'Hello, UTF-16 world!\n ' .encode (
141+ 'utf-16-le'
142+ ).decode (
143+ errors = 'backslashreplace' ,
152144 )
153145
154146 def test_open_binary (self ):
155147 with resources .open_binary (self .anchor01 , 'utf-8.file' ) as f :
156- self . assertEqual ( f .read (), b'Hello, UTF-8 world!\n ' )
148+ assert f .read () == b'Hello, UTF-8 world!\n '
157149 for path_parts in self ._gen_resourcetxt_path_parts ():
158150 with resources .open_binary (
159151 self .anchor02 ,
160152 * path_parts ,
161153 ) as f :
162- self . assertEqual ( f .read (), b'a resource' )
154+ assert f .read () == b'a resource'
163155
164156 def test_path (self ):
165157 with resources .path (self .anchor01 , 'utf-8.file' ) as path :
166158 with open (str (path ), encoding = 'utf-8' ) as f :
167- self . assertEqual ( f .read (), 'Hello, UTF-8 world!\n ' )
159+ assert f .read () == 'Hello, UTF-8 world!\n '
168160 with resources .path (self .anchor01 ) as path :
169161 with open (os .path .join (path , 'utf-8.file' ), encoding = 'utf-8' ) as f :
170- self . assertEqual ( f .read (), 'Hello, UTF-8 world!\n ' )
162+ assert f .read () == 'Hello, UTF-8 world!\n '
171163
172164 def test_is_resource (self ):
173165 is_resource = resources .is_resource
174- self . assertTrue ( is_resource (self .anchor01 , 'utf-8.file' ) )
175- self . assertFalse ( is_resource (self .anchor01 , 'no_such_file' ) )
176- self . assertFalse ( is_resource (self .anchor01 ) )
177- self . assertFalse ( is_resource (self .anchor01 , 'subdirectory' ) )
166+ assert is_resource (self .anchor01 , 'utf-8.file' )
167+ assert not is_resource (self .anchor01 , 'no_such_file' )
168+ assert not is_resource (self .anchor01 )
169+ assert not is_resource (self .anchor01 , 'subdirectory' )
178170 for path_parts in self ._gen_resourcetxt_path_parts ():
179- self . assertTrue ( is_resource (self .anchor02 , * path_parts ) )
171+ assert is_resource (self .anchor02 , * path_parts )
180172
181173 def test_contents (self ):
182174 with warnings_helper .check_warnings ((".*contents.*" , DeprecationWarning )):
183175 c = resources .contents (self .anchor01 )
184- self .assertGreaterEqual (
185- set (c ),
186- {'utf-8.file' , 'utf-16.file' , 'binary.file' , 'subdirectory' },
187- )
176+ assert set (c ) >= {'utf-8.file' , 'utf-16.file' , 'binary.file' , 'subdirectory' }
188177 with (
189178 self .assertRaises (OSError ),
190179 warnings_helper .check_warnings ((
@@ -205,10 +194,7 @@ def test_contents(self):
205194 list (resources .contents (self .anchor01 , * path_parts ))
206195 with warnings_helper .check_warnings ((".*contents.*" , DeprecationWarning )):
207196 c = resources .contents (self .anchor01 , 'subdirectory' )
208- self .assertGreaterEqual (
209- set (c ),
210- {'binary.file' },
211- )
197+ assert set (c ) >= {'binary.file' }
212198
213199 @warnings_helper .ignore_warnings (category = DeprecationWarning )
214200 def test_common_errors (self ):
0 commit comments