From 6e7fddde2a0b9fc7479dcf28d8f7daf2d055097b Mon Sep 17 00:00:00 2001 From: burnout87 Date: Fri, 17 Jan 2025 15:01:12 +0100 Subject: [PATCH 1/2] some tests --- tests/test_input_types.py | 21 +++++++++++++-------- tests/test_type_reconcile.py | 3 +++ tests/testfiles/multiline.ipynb | 2 ++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/tests/test_input_types.py b/tests/test_input_types.py index c169b55..4566db8 100644 --- a/tests/test_input_types.py +++ b/tests/test_input_types.py @@ -36,6 +36,10 @@ def test_posix_download_file_with_arg(client): r = client.get('/api/v1.0/get/testposixpath', query_string={'fits_file_path': 'https://fits.gsfc.nasa.gov/samples/testkeys.fits'}) assert r.json['output']['output_file_download'] == 'file downloaded successfully' +def test_posix_download_file_default_value_with_arg(client): + r = client.get('/api/v1.0/get/testposixpath', query_string={'fits_file_path': ''}) + assert r.json['output']['output_file_download'] == 'file not downloaded' + def test_posix_download_file_extra_annotations(client): r = client.get('/api/v1.0/get/testposixpath_extra_annotated', query_string={'fits_file_path': 'https://fits.gsfc.nasa.gov/samples/testkeys.fits'}) assert r.json['output']['output_file_download'] == 'file downloaded successfully' @@ -264,14 +268,15 @@ def test_dict_wrong(client): @pytest.mark.parametrize('inp,outp', [({'opt': None}, {'opt': None}), - ({'opt': 10}, {'opt': 10.}), - ({'intfloat': 25}, {'intfloat': 25.}), - ({'intfloat': 25.}, {'intfloat': 25.}), - ({'inten': 20}, {'inten': 20}), - ({'flag': False}, {'flag': False}), - ({'flag': 0}, {'flag': False}), - ({'string_param': 'contains = symbol'}, {'string_param': 'contains = symbol'}), - ({'otheropt': '\x00'}, {'otheropt': None}) + ({'opt': 10}, {'opt': 10.}), + ({'intfloat': 25}, {'intfloat': 25.}), + ({'intfloat': 25.}, {'intfloat': 25.}), + ({'inten': 20}, {'inten': 20}), + ({'flag': False}, {'flag': False}), + ({'flag': 0}, {'flag': False}), + ({'string_param': 'contains = symbol'}, {'string_param': 'contains = symbol'}), + ({'otheropt': '\x00'}, {'otheropt': None}), + ({'short_string_param': ''}, {'short_string_param': ''}), ]) def test_type_casting(client, inp, outp): r = client.get('/api/v1.0/options') diff --git a/tests/test_type_reconcile.py b/tests/test_type_reconcile.py index a4d2602..988a8b4 100644 --- a/tests/test_type_reconcile.py +++ b/tests/test_type_reconcile.py @@ -46,7 +46,10 @@ ('foo', None, 'oda:WithNoTypeDefined', '', str, False), ({'foo': ['bar', 'baz']}, None, 'oda:WithNoTypeDefined', '', dict, False), + + ('', None, 'oda:POSIXPath', '', str, False) ] + # 'value,type_annotation,owl_type,extra_ttl,expected_type,expected_optional' ) def test_reconcile_python_type(value,type_annotation,owl_type,extra_ttl,expected_type,expected_optional): assert reconcile_python_type(value=value, diff --git a/tests/testfiles/multiline.ipynb b/tests/testfiles/multiline.ipynb index 107436d..e1e2227 100644 --- a/tests/testfiles/multiline.ipynb +++ b/tests/testfiles/multiline.ipynb @@ -29,6 +29,7 @@ "Contains = Symbol\n", "Spam Ham\n", "''' # oda:LongString\n", + "short_string_param = 'Just a string' # oda:String\n", "flag = True" ] }, @@ -50,6 +51,7 @@ " intfloat = intfloat,\n", " inten = inten,\n", " string_param = string_param,\n", + " short_string_param = short_string_param,\n", " flag = flag)" ] } From 3d069b2bd0f047c085659b2984275b220fad40d1 Mon Sep 17 00:00:00 2001 From: burnout87 Date: Fri, 17 Jan 2025 15:39:57 +0100 Subject: [PATCH 2/2] assigning empty string in case no input value, for POSIXPath, is provided --- nb2workflow/nbadapter.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nb2workflow/nbadapter.py b/nb2workflow/nbadapter.py index 09a035b..8e60b3d 100644 --- a/nb2workflow/nbadapter.py +++ b/nb2workflow/nbadapter.py @@ -879,7 +879,10 @@ def handle_url_params(self, parameters, tmpdir, context={}): if is_posix_path or is_file_url or is_file_reference: arg_par_value = parameters.get(input_par_name, None) if arg_par_value is None: - arg_par_value = input_par_obj['default_value'] + if is_posix_path: + arg_par_value = '' + else: + arg_par_value = input_par_obj['default_value'] if validators.url(arg_par_value, simple_host=True): logger.info(f"checking url: {arg_par_value}") if is_mmoda_url(arg_par_value):