|
1 | 1 | import json
|
2 | 2 | from collections import defaultdict
|
3 |
| - |
| 3 | +from typing import TextIO |
| 4 | +import bz2, gzip, lzma, io |
4 | 5 | import pytest
|
| 6 | +from pathlib import Path |
5 | 7 | from _pytest.reports import BaseReport
|
6 | 8 |
|
7 |
| -from pytest_reportlog.plugin import cleanup_unserializable |
| 9 | +from pytest_reportlog.plugin import cleanup_unserializable, _open_filtered_writer |
| 10 | + |
| 11 | +from typing_extensions import Protocol, Literal |
| 12 | + |
| 13 | + |
| 14 | +class OpenerModule(Protocol): |
| 15 | + def open(self, path: Path, mode: Literal["rt"]) -> TextIO: |
| 16 | + ... |
| 17 | + |
| 18 | + |
| 19 | +@pytest.mark.parametrize( |
| 20 | + "filename, opener_module", |
| 21 | + [ |
| 22 | + ("test.jsonl", io), |
| 23 | + ("test.unknown", io), |
| 24 | + ("test.jsonl.gz", gzip), |
| 25 | + ("test.jsonl.bz2", bz2), |
| 26 | + ("test.jsonl.xz", lzma), |
| 27 | + ], |
| 28 | +) |
| 29 | +def test_open_filtered(filename: str, opener_module: OpenerModule, tmp_path: Path): |
| 30 | + path = tmp_path / filename |
| 31 | + with _open_filtered_writer(path) as fp: |
| 32 | + fp.write("test\n") |
| 33 | + with opener_module.open(path, "rt") as fp2: |
| 34 | + assert fp2.read() == "test\n" |
8 | 35 |
|
9 | 36 |
|
10 | 37 | def test_basics(testdir, tmp_path, pytestconfig):
|
|
0 commit comments