From 723cc402210e47f9df7d36fae5870639b861c99e Mon Sep 17 00:00:00 2001 From: profitroll Date: Sun, 6 Aug 2023 11:33:41 +0200 Subject: [PATCH] Fixed imports --- tests/test_json_async.py | 14 +++++++++----- tests/test_json_sync.py | 12 ++++++++---- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/tests/test_json_async.py b/tests/test_json_async.py index e8dacdc..9a47cbc 100644 --- a/tests/test_json_async.py +++ b/tests/test_json_async.py @@ -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 diff --git a/tests/test_json_sync.py b/tests/test_json_sync.py index 88765c9..65b519d 100644 --- a/tests/test_json_sync.py +++ b/tests/test_json_sync.py @@ -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