use pytest tmp_path fixture to fix windows ci

This commit is contained in:
Sean Breckenridge 2023-02-22 23:16:38 -08:00
parent f05e81cee5
commit 0bb62531b1

View file

@ -1,7 +1,7 @@
import warnings import warnings
import json import json
import tempfile from pathlib import Path
from datetime import datetime from datetime import datetime
from typing import NamedTuple, Iterator from typing import NamedTuple, Iterator
@ -27,14 +27,14 @@ def data() -> Iterator[IP]:
yield IP(addr="127.105.171.61", dt=datetime(2020, 10, 1)) yield IP(addr="127.105.171.61", dt=datetime(2020, 10, 1))
def test_denylist() -> None: def test_denylist(tmp_path: Path) -> None:
with tempfile.NamedTemporaryFile() as tf, warnings.catch_warnings(record=True): tf = (tmp_path / "denylist.json").absolute()
with warnings.catch_warnings(record=True):
# create empty denylist (though file does not have to exist for denylist to work) # create empty denylist (though file does not have to exist for denylist to work)
tf.write(b"[]") tf.write_text("[]")
tf.flush()
d = DenyList(tf.name) d = DenyList(tf)
d.load() d.load()
assert dict(d._deny_map) == {} assert dict(d._deny_map) == {}
@ -93,7 +93,7 @@ def test_denylist() -> None:
assert "59.40.113.87" not in [i.addr for i in filtered] assert "59.40.113.87" not in [i.addr for i in filtered]
with open(tf.name, "r") as f: with open(tf, "r") as f:
data_json = json.loads(f.read()) data_json = json.loads(f.read())
assert data_json == [ assert data_json == [