Skip to content

Commit

Permalink
tests for jq
Browse files Browse the repository at this point in the history
  • Loading branch information
amyasnikov committed Mar 6, 2024
1 parent 57dff0b commit c1607c5
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion validity/tests/test_utils/test_json.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from validity.utils.json import transform_json
from validity.utils.json import transform_json, jq
import pytest


class TestTransformJson:
Expand Down Expand Up @@ -31,3 +32,13 @@ def test_change_key(self):
)
assert result["groups"]["admin2"] == self.JSON["groups"]["admin"]
assert "admin" not in result["groups"]


@pytest.mark.parametrize('data, expression, result', [
({'a': {'b': 'one', 'c': 'two'}}, '. | mkarr(.a.b)', {'a': {'b': ['one'], 'c': 'two'}}),
({'a': {'b': ['one'], 'c': 'two'}}, '. | mkarr(.a.b)', {'a': {'b': ['one'], 'c': 'two'}}),
({'a': '10.2', 'b': {'c': '20'}}, '. | mknum(.b)', {'a': '10.2', 'b': {'c': 20}}),
({'a': '10.2', 'b': {'c': '20'}}, '. | mknum', {'a': 10.2, 'b': {'c': 20}}),
])
def test_jq(data, expression, result):
assert jq.first(expression, data) == result

0 comments on commit c1607c5

Please sign in to comment.