(self, module, encoding=None, errors=None)
| 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") |
no test coverage detected