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