From 7e55bdd32193f4ab418ef25ff70b607a42a5e822 Mon Sep 17 00:00:00 2001 From: Markus Neifer Date: Wed, 13 Aug 2025 14:43:15 +0000 Subject: [PATCH 1/3] Add documentation --- src/mncpyexamples/asynchello/helloasync.py | 8 ++++++++ 1 file changed, 8 insertions(+) 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__": From cbf48b2eda624e624d43d930890aa5c7a1faccac Mon Sep 17 00:00:00 2001 From: Markus Neifer Date: Wed, 13 Aug 2025 14:43:43 +0000 Subject: [PATCH 2/3] Add documentation --- tests/test_helloasync.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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" From a69c0923e53c7bdd572c7e1894c5cd045121272c Mon Sep 17 00:00:00 2001 From: Markus Neifer Date: Wed, 13 Aug 2025 14:45:23 +0000 Subject: [PATCH 3/3] Add basic JSONPath usage examples --- requirements.txt | 2 ++ src/mncpyexamples/jsonhello/jsonpath.py | 25 +++++++++++++++++++++++++ tests/test_jsonpath.py | 17 +++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 src/mncpyexamples/jsonhello/jsonpath.py create mode 100644 tests/test_jsonpath.py 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/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_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]