MCPcopy Index your code
hub / github.com/RustPython/RustPython / _check_io_encoding

Method _check_io_encoding

Lib/test/test_utf8_mode.py:172–195  ·  view source on GitHub ↗
(self, module, encoding=None, errors=None)

Source from the content-addressed store, hash-verified

170 self.assertEqual(out.lower(), 'utf-8/strict')
171
172 def _check_io_encoding(self, module, encoding=None, errors=None):
173 filename = __file__
174
175 # Encoding explicitly set
176 args = []
177 if encoding:
178 args.append(f'encoding={encoding!r}')
179 if errors:
180 args.append(f'errors={errors!r}')
181 code = textwrap.dedent('''
182 import sys
183 from %s import open
184 filename = sys.argv[1]
185 with open(filename, %s) as fp:
186 print(f"{fp.encoding}/{fp.errors}")
187 ''') % (module, ', '.join(args))
188 out = self.get_output('-c', code, filename,
189 PYTHONUTF8='1')
190
191 if not encoding:
192 encoding = 'utf-8'
193 if not errors:
194 errors = 'strict'
195 self.assertEqual(out.lower(), f'{encoding}/{errors}')
196
197 def check_io_encoding(self, module):
198 self._check_io_encoding(module, encoding="latin1")

Callers 1

check_io_encodingMethod · 0.95

Calls 6

get_outputMethod · 0.95
dedentMethod · 0.80
appendMethod · 0.45
joinMethod · 0.45
assertEqualMethod · 0.45
lowerMethod · 0.45

Tested by

no test coverage detected