Fixed imports

This commit is contained in:
Profitroll 2023-08-06 11:33:41 +02:00
parent b6537a50ae
commit 723cc40221
Signed by: profitroll
GPG Key ID: FA35CAB49DACD3B2
2 changed files with 17 additions and 9 deletions

View File

@ -1,4 +1,8 @@
from json import JSONDecodeError, dumps
try:
from ujson import JSONDecodeError, dumps
except ImportError:
from json import dumps, JSONDecodeError
from pathlib import Path
from typing import Any, Union
@ -29,13 +33,13 @@ async def test_json_read_valid(path: Union[str, Path], expected: Any):
@pytest.mark.parametrize(
"path, expected",
[
("tests/data/invalid.json", pytest.raises(JSONDecodeError)),
("tests/data/nonexistent.json", pytest.raises(FileNotFoundError)),
("tests/data/invalid.json", JSONDecodeError),
("tests/data/nonexistent.json", FileNotFoundError),
],
)
async def test_json_read_invalid(path: Union[str, Path], expected: Any):
with expected:
assert await json_read(path) == expected
with pytest.raises(expected):
await json_read(path)
@pytest.mark.asyncio

View File

@ -1,4 +1,8 @@
from json import JSONDecodeError, dumps
try:
from ujson import JSONDecodeError, dumps
except ImportError:
from json import dumps, JSONDecodeError
from pathlib import Path
from typing import Any, Union
@ -27,12 +31,12 @@ def test_json_read_valid(path: Union[str, Path], expected: Any):
@pytest.mark.parametrize(
"path, expected",
[
("tests/data/invalid.json", pytest.raises(JSONDecodeError)),
("tests/data/nonexistent.json", pytest.raises(FileNotFoundError)),
("tests/data/invalid.json", JSONDecodeError),
("tests/data/nonexistent.json", FileNotFoundError),
],
)
def test_json_read_invalid(path: Union[str, Path], expected: Any):
with expected:
with pytest.raises(expected):
assert sync.json_read(path) == expected