Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ jobs:
RELEASE: false
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
# Python 3.8 is unavailable on Ubuntu 26.04 (ubuntu-latest).
os: [ubuntu-22.04, windows-latest, macOS-latest]
python_version: [3.8]
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion aw_query/query2.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def parse(string: str, namespace: dict) -> QToken:
key = QString.parse(key_str, {}).value
entries_str = entries_str.strip()
# Remove :
if entries_str[0] != ":":
if not entries_str.startswith(":"):
raise QueryParseException("Key in dict is not followed by a :")
entries_str = entries_str[1:]
# parse val
Expand Down
32 changes: 32 additions & 0 deletions tests/test_query2.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,38 @@ def test_dict():
d = QDict.parse(d_str, ns)


@pytest.mark.parametrize(
"literal",
['{"a"}', '{"a" }', '{"a"\t\n}', '{"a": 1, "b"}', '{"outer": {"a"}}'],
)
def test_dict_truncated_key(literal):
with pytest.raises(QueryParseException, match="Key in dict is not followed by a :"):
QDict.parse(literal, {})

start = datetime(2026, 1, 1, tzinfo=timezone.utc)
with pytest.raises(QueryParseException, match="Key in dict is not followed by a :"):
query("test", f"RETURN = {literal};", start, start, mock_ds)


@pytest.mark.parametrize("literal", ['{"a":}', '{"a": }', '{"a" 1}'])
Comment thread
TimeToBuildBob marked this conversation as resolved.
Resolved
def test_dict_missing_colon_or_value(literal):
with pytest.raises(QueryParseException):
QDict.parse(literal, {})


@pytest.mark.parametrize(
"literal, expected",
[
("{}", {}),
('{"a": 1}', {"a": 1}),
('{"a": 1, "b": 2}', {"a": 1, "b": 2}),
('{"outer": {"a": 1}, "empty": {}}', {"outer": {"a": 1}, "empty": {}}),
],
)
def test_dict_valid_controls(literal, expected):
assert QDict.parse(literal, {}).interpret(mock_ds, {}) == expected


def test_list():
ds = mock_ds
ns: Dict[str, Any] = {}
Expand Down
Loading