(
tmpdir, # type: Tempdir
encoding_comment, # type: str
comment_line, # type: int
pos, # type: int
)
| 265 | ) |
| 266 | @pytest.mark.parametrize("comment_line", [1, 2]) |
| 267 | def test_script_encoding_bad( |
| 268 | tmpdir, # type: Tempdir |
| 269 | encoding_comment, # type: str |
| 270 | comment_line, # type: int |
| 271 | pos, # type: int |
| 272 | ): |
| 273 | # type: (...) -> None |
| 274 | |
| 275 | script = tmpdir.join("incorrect-encoding-comment.py") |
| 276 | with open(script, "w") as fp: |
| 277 | if comment_line == 2: |
| 278 | shebang = "#!/usr/bin/env python" |
| 279 | print(shebang, file=fp) |
| 280 | pos += len(shebang) + len(os.linesep) |
| 281 | print(encoding_comment, file=fp) |
| 282 | print("# micro: µ", file=fp) |
| 283 | |
| 284 | with pytest.raises( |
| 285 | UnicodeDecodeError, |
| 286 | match=re.escape( |
| 287 | "'ascii' codec can't decode byte 0xc2 in position {pos}: " |
| 288 | "ordinal not in range(128)".format(pos=pos) |
| 289 | ), |
| 290 | ): |
| 291 | apply_script_metadata([script]) |
| 292 | |
| 293 | |
| 294 | def test_script_encoding_default(tmpdir): |
nothing calls this directly
no test coverage detected