Skip to content

Commit

Permalink
Test jsonpath simple field name
Browse files Browse the repository at this point in the history
  • Loading branch information
steinitzu committed Nov 28, 2024
1 parent d11e8f9 commit 8a0c020
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tests/common/test_jsonpath.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import pytest

from dlt.common import jsonpath as jp


@pytest.mark.parametrize("compiled", [True, False])
@pytest.mark.parametrize(
"path, expected",
[
("col_a", "col_a"),
("'col.a'", "col.a"),
("'$col_a'", "$col_a"),
("'col|a'", "col|a"),
],
)
def test_extract_simple_field_name_positive(path, expected, compiled):
if compiled:
path = jp.compile_path(path)

result = jp.extract_simple_field_name(path)
assert result == expected


@pytest.mark.parametrize("compiled", [True, False])
@pytest.mark.parametrize(
"path",
[
"$.col_a",
"$.col_a.items",
"$.col_a.items[0]",
"$.col_a.items[*]",
"col_a|col_b",
],
)
def test_extract_simple_field_name_negative(path, compiled):
if compiled:
path = jp.compile_path(path)

result = jp.extract_simple_field_name(path)
assert result is None


# TODO: Test all jsonpath utils

0 comments on commit 8a0c020

Please sign in to comment.