MCPcopy Index your code
hub / github.com/python/cpython / _check_io_encoding

Method _check_io_encoding

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

Source from the content-addressed store, hash-verified

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

Callers 1

check_io_encodingMethod · 0.95

Calls 6

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

Tested by

no test coverage detected