From b717d056bd4a2f1d82858cd7aa191d799604c667 Mon Sep 17 00:00:00 2001 From: Pierre Camilleri <22995923+pierrecamilleri@users.noreply.github.com> Date: Mon, 23 Sep 2024 22:34:58 +0200 Subject: [PATCH 1/6] =?UTF-8?q?=F0=9F=94=B4=20test=20schema=20with=20path?= =?UTF-8?q?=20property?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/issue-1688/schema_with_path.json | 10 ++++++++++ .../resource/__spec__/test_datatype.py | 18 +++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 data/issue-1688/schema_with_path.json diff --git a/data/issue-1688/schema_with_path.json b/data/issue-1688/schema_with_path.json new file mode 100644 index 0000000000..c93eb6af88 --- /dev/null +++ b/data/issue-1688/schema_with_path.json @@ -0,0 +1,10 @@ +{ + "name": "schema", + "path": "abc", + "fields": [ + { + "name": "id", + "type": "integer" + } + ] +} diff --git a/frictionless/resource/__spec__/test_datatype.py b/frictionless/resource/__spec__/test_datatype.py index 4e1d1546b9..9315e33971 100644 --- a/frictionless/resource/__spec__/test_datatype.py +++ b/frictionless/resource/__spec__/test_datatype.py @@ -1,6 +1,7 @@ import pytest -from frictionless import Resource, resources +from frictionless import Resource, Schema, resources +from frictionless.resources.json import SchemaResource # File @@ -162,3 +163,18 @@ def test_resource_from_descriptor_with_class_datatype(): assert resource.type == "table" assert resource.datatype == "table" assert isinstance(resource, resources.TableResource) + + +@pytest.mark.parametrize( + "source", + [ + "data/issue-1688/schema_with_path.json", + ], +) +def test_schema_resource_with_path_property(source): + schema = Schema(source) + print(source) + resource = Resource(schema.to_descriptor(), datatype="schema") + assert resource.type == "json" + assert resource.datatype == "schema" + assert isinstance(resource, SchemaResource) From 6e177aab64e6887fc9afe0f2dc85645806ec68a6 Mon Sep 17 00:00:00 2001 From: Pierre Camilleri <22995923+pierrecamilleri@users.noreply.github.com> Date: Mon, 23 Sep 2024 22:43:34 +0200 Subject: [PATCH 2/6] =?UTF-8?q?=F0=9F=9F=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frictionless/resource/factory.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/frictionless/resource/factory.py b/frictionless/resource/factory.py index dd6867ce10..82472c9c2d 100644 --- a/frictionless/resource/factory.py +++ b/frictionless/resource/factory.py @@ -45,10 +45,16 @@ def __call__( path = source if isinstance(source, str): path = helpers.join_basepath(source, basepath=basepath) - md_type = Detector.detect_metadata_type(path, format=options.get("format")) + md_type = options.get("datatype") + if not md_type: + md_type = Detector.detect_metadata_type( + path, format=options.get("format") + ) if md_type != "resource": options["path" if isinstance(source, str) else "data"] = source - resource = cls(control=control, basepath=basepath, **options) # type: ignore + resource = cls( # type: ignore + control=control, basepath=basepath, **options + ) return cast(T, resource) # Descriptor From 3a77070cbe05179edad8fba704c6b2e1a2003875 Mon Sep 17 00:00:00 2001 From: Pierre Camilleri <22995923+pierrecamilleri@users.noreply.github.com> Date: Mon, 23 Sep 2024 22:50:50 +0200 Subject: [PATCH 3/6] =?UTF-8?q?=F0=9F=94=B5=20remove=20print=20and=20unnec?= =?UTF-8?q?essary=20diff?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frictionless/resource/__spec__/test_datatype.py | 1 - frictionless/resource/factory.py | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/frictionless/resource/__spec__/test_datatype.py b/frictionless/resource/__spec__/test_datatype.py index 9315e33971..509b358bc2 100644 --- a/frictionless/resource/__spec__/test_datatype.py +++ b/frictionless/resource/__spec__/test_datatype.py @@ -173,7 +173,6 @@ def test_resource_from_descriptor_with_class_datatype(): ) def test_schema_resource_with_path_property(source): schema = Schema(source) - print(source) resource = Resource(schema.to_descriptor(), datatype="schema") assert resource.type == "json" assert resource.datatype == "schema" diff --git a/frictionless/resource/factory.py b/frictionless/resource/factory.py index 82472c9c2d..a2dcc798e8 100644 --- a/frictionless/resource/factory.py +++ b/frictionless/resource/factory.py @@ -45,16 +45,16 @@ def __call__( path = source if isinstance(source, str): path = helpers.join_basepath(source, basepath=basepath) + md_type = options.get("datatype") if not md_type: md_type = Detector.detect_metadata_type( path, format=options.get("format") ) + if md_type != "resource": options["path" if isinstance(source, str) else "data"] = source - resource = cls( # type: ignore - control=control, basepath=basepath, **options - ) + resource = cls(control=control, basepath=basepath, **options) # type: ignore return cast(T, resource) # Descriptor From f445e4065c619bd0798d79be46b71a0c6224a39c Mon Sep 17 00:00:00 2001 From: Pierre Camilleri <22995923+pierrecamilleri@users.noreply.github.com> Date: Tue, 24 Sep 2024 09:27:57 +0200 Subject: [PATCH 4/6] =?UTF-8?q?=F0=9F=94=B5=20simplify=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/issue-1688/schema_with_path.json | 10 ---------- frictionless/resource/__spec__/test_datatype.py | 15 +++++++-------- 2 files changed, 7 insertions(+), 18 deletions(-) delete mode 100644 data/issue-1688/schema_with_path.json diff --git a/data/issue-1688/schema_with_path.json b/data/issue-1688/schema_with_path.json deleted file mode 100644 index c93eb6af88..0000000000 --- a/data/issue-1688/schema_with_path.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "schema", - "path": "abc", - "fields": [ - { - "name": "id", - "type": "integer" - } - ] -} diff --git a/frictionless/resource/__spec__/test_datatype.py b/frictionless/resource/__spec__/test_datatype.py index 509b358bc2..ced47b143c 100644 --- a/frictionless/resource/__spec__/test_datatype.py +++ b/frictionless/resource/__spec__/test_datatype.py @@ -165,15 +165,14 @@ def test_resource_from_descriptor_with_class_datatype(): assert isinstance(resource, resources.TableResource) -@pytest.mark.parametrize( - "source", - [ - "data/issue-1688/schema_with_path.json", - ], -) def test_schema_resource_with_path_property(source): - schema = Schema(source) - resource = Resource(schema.to_descriptor(), datatype="schema") + # Non regression test for issue #1688 + schema_descriptor = { + "name": "schema", + "path": "abc", + "fields": [], + } + resource = Resource(schema_descriptor, datatype="schema") assert resource.type == "json" assert resource.datatype == "schema" assert isinstance(resource, SchemaResource) From 6eb8327e4464372396501423a659f2242e7700fd Mon Sep 17 00:00:00 2001 From: Pierre Camilleri <22995923+pierrecamilleri@users.noreply.github.com> Date: Tue, 24 Sep 2024 09:28:53 +0200 Subject: [PATCH 5/6] fix: forgot to remove unused type --- frictionless/resource/__spec__/test_datatype.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frictionless/resource/__spec__/test_datatype.py b/frictionless/resource/__spec__/test_datatype.py index ced47b143c..d191759f18 100644 --- a/frictionless/resource/__spec__/test_datatype.py +++ b/frictionless/resource/__spec__/test_datatype.py @@ -1,6 +1,6 @@ import pytest -from frictionless import Resource, Schema, resources +from frictionless import Resource, resources from frictionless.resources.json import SchemaResource # File From 1c638c58a22205722e431e12ff0e36d6d8015ec2 Mon Sep 17 00:00:00 2001 From: Pierre Camilleri <22995923+pierrecamilleri@users.noreply.github.com> Date: Tue, 24 Sep 2024 10:12:06 +0200 Subject: [PATCH 6/6] fix: forgot to remove "source" fixture --- frictionless/resource/__spec__/test_datatype.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frictionless/resource/__spec__/test_datatype.py b/frictionless/resource/__spec__/test_datatype.py index d191759f18..f61e8101fa 100644 --- a/frictionless/resource/__spec__/test_datatype.py +++ b/frictionless/resource/__spec__/test_datatype.py @@ -165,7 +165,7 @@ def test_resource_from_descriptor_with_class_datatype(): assert isinstance(resource, resources.TableResource) -def test_schema_resource_with_path_property(source): +def test_schema_resource_with_path_property(): # Non regression test for issue #1688 schema_descriptor = { "name": "schema",