From 79e302f54a433ee95446451cf8d264084eb14d5b Mon Sep 17 00:00:00 2001 From: Aleksey Date: Thu, 10 Aug 2023 13:13:12 -0300 Subject: [PATCH 1/2] Convert path to str if DSL type --- fhirpathpy/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fhirpathpy/__init__.py b/fhirpathpy/__init__.py index 3e33842..dfdf7b4 100644 --- a/fhirpathpy/__init__.py +++ b/fhirpathpy/__init__.py @@ -64,6 +64,8 @@ def evaluate(resource, path, context={}, model=None): int: Description of return value """ + if type(path) is DSL: + path = str(path) node = parse(path) return apply_parsed_path(resource, node, context, model) From 36741546475120bcdbf3df18063ea7ae19a4667c Mon Sep 17 00:00:00 2001 From: Aleksey Date: Thu, 10 Aug 2023 21:05:53 -0300 Subject: [PATCH 2/2] Update check path type --- fhirpathpy/__init__.py | 2 +- tests/test_evaluators.py | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/fhirpathpy/__init__.py b/fhirpathpy/__init__.py index dfdf7b4..1635627 100644 --- a/fhirpathpy/__init__.py +++ b/fhirpathpy/__init__.py @@ -64,7 +64,7 @@ def evaluate(resource, path, context={}, model=None): int: Description of return value """ - if type(path) is DSL: + if isinstance(path, DSL): path = str(path) node = parse(path) return apply_parsed_path(resource, node, context, model) diff --git a/tests/test_evaluators.py b/tests/test_evaluators.py index 67bc93b..5ded737 100644 --- a/tests/test_evaluators.py +++ b/tests/test_evaluators.py @@ -6,6 +6,8 @@ from fhirpathpy import evaluate from fhirpathpy.engine.invocations.constants import constants +from fhirpathpy import dsl + @pytest.mark.parametrize( ("resource", "path", "expected"), @@ -212,7 +214,7 @@ def now_function_test(): old_now_value = evaluate({}, 'now()') frozen_datetime.tick(1.0) new_now_value = evaluate({}, 'now()') - + assert old_now_value != new_now_value @@ -246,3 +248,14 @@ def combining_functions_test(resource, path, expected): ) def path_functions_test(resource, path, expected): assert evaluate(resource, path) == expected + + +@pytest.mark.parametrize( + ("resource", "path", "expected"), + [ + ({"a": "lorem ipsum"}, "a.contains('sum')", [True]), + ({"a": "lorem ipsum"}, dsl.a.contains('sum'), [True]), + ], +) +def convert_dsl_path_test(resource, path, expected): + assert evaluate(resource, path) == expected