Skip to content

Commit

Permalink
Group tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nineteendo committed Sep 25, 2024
1 parent a254dd1 commit af4f6ba
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
19 changes: 9 additions & 10 deletions src/jsonyx/test/test_dumps.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ def test_int(
assert json.dumps(num_type(num), end="") == repr(num)


def test_int_enum(json: ModuleType) -> None:
"""Test int enum."""
assert json.dumps(_IntEnum.ZERO, end="") == "0"


@pytest.mark.parametrize("num_type", [Decimal, float])
def test_rational_number(
json: ModuleType, num_type: type[Decimal | float],
Expand All @@ -67,11 +62,6 @@ def test_rational_number(
assert json.dumps(num_type("0.0"), end="") == "0.0"


def test_float_enum(json: ModuleType) -> None:
"""Test float enum."""
assert json.dumps(_FloatEnum.ZERO, end="") == "0.0"


@pytest.mark.parametrize("num", ["NaN", "Infinity", "-Infinity"])
@pytest.mark.parametrize("num_type", [Decimal, float])
def test_nan_and_infinity(
Expand Down Expand Up @@ -110,6 +100,15 @@ def test_signaling_nan(json: ModuleType) -> None:
json.dumps(Decimal("sNaN"))


@pytest.mark.parametrize(("obj", "expected"), [
(_IntEnum.ZERO, "0"),
(_FloatEnum.ZERO, "0.0"),
])
def test_enum(json: ModuleType, obj: float, expected: str) -> None:
"""Test enum."""
assert json.dumps(obj, end="") == expected


@pytest.mark.parametrize("obj", [
# UTF-8
"\xa3", "\u0418", "\u0939", "\u20ac", "\ud55c", "\U00010348", "\U001096b3",
Expand Down
6 changes: 2 additions & 4 deletions src/jsonyx/test/test_run_filter_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,8 @@ def test_whitespace(query: str) -> None:


@pytest.mark.parametrize(("query", "msg", "colno", "end_colno"), [
("", "Expecting a relative query", 1, -1),
("$", "Expecting a relative query", 1, -1),
("!", "Expecting a relative query", 2, -1),
("@?", "Optional marker is not allowed", 2, 3),
("", "Expecting a relative query", 1, -1), # relative=True
("@?", "Optional marker is not allowed", 2, 3), # mapping=True
("@ == ", "Expecting value", 6, -1),
("@ && ", "Expecting a relative query", 6, -1),
("!@ == 0", "Unexpected operator", 4, 6),
Expand Down
12 changes: 9 additions & 3 deletions src/jsonyx/test/test_run_select_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,18 @@ def test_invalid_property(key: str) -> None:
check_syntax_err(exc_info, "Expecting property", 3)


@pytest.mark.parametrize("query", ["$.a?", "$.a.b", "$.a[0]"])
@pytest.mark.parametrize("query", [
# At the end
"$.a",
# In the middle
"$.a?", "$.a.b", "$.a[0]",
])
def test_list_property(query: str) -> None:
"""Test property on a list."""
match: str = "List index must be int or slice, not"
with pytest.raises(TypeError, match=match):
run_select_query(([[]], 0), query)
run_select_query(([[]], 0), query, allow_slice=True)


@pytest.mark.parametrize("query", [
Expand All @@ -96,7 +102,7 @@ def test_list_property(query: str) -> None:
"$.a.b", "$.a[0]",
])
def test_list_property_mapping(query: str) -> None:
"""Test property on a list."""
"""Test property on a list with mapping."""
with pytest.raises(TypeError, match="List index must be int, not"):
run_select_query(([[]], 0), query, mapping=True)

Expand Down

0 comments on commit af4f6ba

Please sign in to comment.