diff --git a/requirements.txt b/requirements.txt index 19c2093..1524a74 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,11 +4,13 @@ exceptiongroup==1.3.0 gitdb==4.0.12 GitPython==3.1.45 iniconfig==2.1.0 +jsonpath-ng==1.7.0 loguru==0.7.3 -e . packaging==25.0 pip-tools==7.5.0 pluggy==1.6.0 +ply==3.11 Pygments==2.19.2 pyproject_hooks==1.2.0 pytest==8.4.1 diff --git a/src/mncpyexamples/asynchello/helloasync.py b/src/mncpyexamples/asynchello/helloasync.py index 96461fb..8aeb598 100644 --- a/src/mncpyexamples/asynchello/helloasync.py +++ b/src/mncpyexamples/asynchello/helloasync.py @@ -1,11 +1,19 @@ +"""Basic asyncio usage examples. + +Copyright (c) 2025 Markus Neifer +Licensed under the MIT License. +See file LICENSE in project root directory. +""" import asyncio async def main(): + """Say hello asynchronously.""" print('Hello ...') await asyncio.sleep(1) print('... World!') def run_main(): + """Run the main asynchronous function.""" asyncio.run(main()) if __name__ == "__main__": diff --git a/src/mncpyexamples/jsonhello/jsonpath.py b/src/mncpyexamples/jsonhello/jsonpath.py new file mode 100644 index 0000000..500da5e --- /dev/null +++ b/src/mncpyexamples/jsonhello/jsonpath.py @@ -0,0 +1,25 @@ +"""Basic JSONPath usage examples. + +Copyright (c) 2025 Markus Neifer +Licensed under the MIT License. +See file LICENSE in project root directory. + +See https://github.com/h2non/jsonpath-ng +""" +import jsonpath_ng as jp + +def parse_no_space(): + """Parse JSONPath without spaces.""" + jsonpath_expr = jp.parse('foo[*].baz') + + return [match.value for match in jsonpath_expr.find({'foo': [{'baz': 1}, {'baz': 2}]})] + +def parse_with_space(): + """Parse JSONPath with spaces.""" + jsonpath_expr = jp.parse('"foo bar"[*].baz') + + return [match.value for match in jsonpath_expr.find({'foo bar': [{'baz': 1}, {'baz': 2}]})] + +if __name__ == '__main__': + print('parse_no_space:', parse_no_space()) + print('parse_with_space:', parse_with_space()) diff --git a/tests/test_helloasync.py b/tests/test_helloasync.py index a473245..303d7a6 100644 --- a/tests/test_helloasync.py +++ b/tests/test_helloasync.py @@ -1,5 +1,13 @@ +"""Test the helloasync module. + +Copyright (c) 2025 Markus Neifer +Licensed under the MIT License. +See file LICENSE in project root directory. +""" +from mncpyexamples.asynchello import helloasync + def test_helloasync(capsys): - import mncpyexamples.asynchello.helloasync as helloasync + """Test the run_main() function.""" helloasync.run_main() captured = capsys.readouterr() assert captured.out == "Hello ...\n... World!\n" diff --git a/tests/test_jsonpath.py b/tests/test_jsonpath.py new file mode 100644 index 0000000..30f5c98 --- /dev/null +++ b/tests/test_jsonpath.py @@ -0,0 +1,17 @@ +"""Test the jsonpath module. + +Copyright (c) 2025 Markus Neifer +Licensed under the MIT License. +See file LICENSE in project root directory. +""" +from mncpyexamples.jsonhello import jsonpath + +def test_parse_no_space(): + """Test JSONPath parsing without spaces.""" + result = jsonpath.parse_no_space() + assert result == [1, 2] + +def test_parse_with_space(): + """Test JSONPath parsing with spaces.""" + result = jsonpath.parse_with_space() + assert result == [1, 2]