Write results to CSV and read back.
()
| 156 | |
| 157 | @pytest.mark.skipif(not _HAS_YAML, reason="pyyaml not installed") |
| 158 | def test_write_csv(): |
| 159 | """Write results to CSV and read back.""" |
| 160 | with tempfile.TemporaryDirectory() as tmpdir: |
| 161 | path = Path(tmpdir) / "results" / "test.csv" |
| 162 | results = [ |
| 163 | {"repo": "foo", "tokens": 100, "ratio": 2.5}, |
| 164 | {"repo": "bar", "tokens": 200, "ratio": 1.5}, |
| 165 | ] |
| 166 | write_csv(results, path) |
| 167 | |
| 168 | assert path.exists() |
| 169 | with open(path, newline="") as f: |
| 170 | reader = csv.DictReader(f) |
| 171 | rows = list(reader) |
| 172 | |
| 173 | assert len(rows) == 2 |
| 174 | assert rows[0]["repo"] == "foo" |
| 175 | assert rows[1]["tokens"] == "200" |
| 176 | |
| 177 | |
| 178 | @pytest.mark.skipif(not _HAS_YAML, reason="pyyaml not installed") |
nothing calls this directly
no test coverage detected