From 515586fe0f102f2e859c32ed0588dfb8055aad5e Mon Sep 17 00:00:00 2001 From: amercader Date: Fri, 12 Jul 2024 15:03:54 +0200 Subject: [PATCH] Organize examples dir --- README.md | 4 ++-- ckanext/dcat/cli.py | 4 ++-- ckanext/dcat/tests/test_cli.py | 9 ++++++++- ckanext/dcat/tests/test_converters.py | 8 ++++---- .../dcat/tests/test_euro_dcatap_profile_parse.py | 12 ++++++------ ckanext/dcat/tests/test_scheming_support.py | 2 +- ckanext/dcat/tests/utils.py | 14 +++++++++----- examples/{ => ckan}/catalog.json | 0 examples/{ => ckan}/catalog_datasets_list.json | 0 examples/{ => ckan}/ckan_dataset.json | 0 examples/{ => ckan}/dataset.json | 0 examples/{ => ckan}/full_ckan_dataset.json | 0 examples/{ => dcat}/catalog.rdf | 0 examples/{ => dcat}/catalog_datasets_list.rdf | 0 examples/{ => dcat}/catalog_pod.jsonld | 0 examples/{ => dcat}/catalog_with_at_graph.jsonld | 0 examples/{ => dcat}/dataset.rdf | 0 examples/{ => dcat}/dataset_afs.ttl | 0 examples/{ => dcat}/dataset_deri.ttl | 0 examples/{ => dcat}/dataset_gob_es.ttl | 0 examples/{ => dcat}/dataset_gov_de.rdf | 0 examples/{ => dcat}/dataset_sweden.rdf | 0 22 files changed, 32 insertions(+), 21 deletions(-) rename examples/{ => ckan}/catalog.json (100%) rename examples/{ => ckan}/catalog_datasets_list.json (100%) rename examples/{ => ckan}/ckan_dataset.json (100%) rename examples/{ => ckan}/dataset.json (100%) rename examples/{ => ckan}/full_ckan_dataset.json (100%) rename examples/{ => dcat}/catalog.rdf (100%) rename examples/{ => dcat}/catalog_datasets_list.rdf (100%) rename examples/{ => dcat}/catalog_pod.jsonld (100%) rename examples/{ => dcat}/catalog_with_at_graph.jsonld (100%) rename examples/{ => dcat}/dataset.rdf (100%) rename examples/{ => dcat}/dataset_afs.ttl (100%) rename examples/{ => dcat}/dataset_deri.ttl (100%) rename examples/{ => dcat}/dataset_gob_es.ttl (100%) rename examples/{ => dcat}/dataset_gov_de.rdf (100%) rename examples/{ => dcat}/dataset_sweden.rdf (100%) diff --git a/README.md b/README.md index f050efdf..21ced668 100644 --- a/README.md +++ b/README.md @@ -1128,9 +1128,9 @@ Example output of structured data in JSON-LD: The `ckan dcat` command offers utilites to transform between DCAT RDF Serializations and CKAN datasets (`ckan dcat consume`) and viceversa (`ckan dcat produce`). In both cases the input can be provided as a path to a file: - ckan dcat consume -f ttl examples/dataset.ttl + ckan dcat consume -f ttl examples/dcat/dataset.ttl - ckan dcat produce -f jsonld examples/ckan_datasets.json + ckan dcat produce -f jsonld examples/ckan/ckan_datasets.json or be read from stdin: diff --git a/ckanext/dcat/cli.py b/ckanext/dcat/cli.py index c0343174..52075360 100644 --- a/ckanext/dcat/cli.py +++ b/ckanext/dcat/cli.py @@ -71,7 +71,7 @@ def consume(input, output, format, profiles, pretty, compat_mode): The input serializations can be provided as a path to a file, e.g.: - ckan dcat consume examples/dataset.ttl + ckan dcat consume examples/dcat/dataset.ttl Or be read from stdin: @@ -120,7 +120,7 @@ def produce(input, output, format, profiles, compat_mode): The input datasets can be provided as a path to a file, e.g.: - ckan dcat consume examples/ckan_dataset.json + ckan dcat consume examples/ckan/ckan_dataset.json Or be read from stdin: diff --git a/ckanext/dcat/tests/test_cli.py b/ckanext/dcat/tests/test_cli.py index ecacdc37..5d1a7550 100644 --- a/ckanext/dcat/tests/test_cli.py +++ b/ckanext/dcat/tests/test_cli.py @@ -7,7 +7,13 @@ def test_consume(cli): path = os.path.join( - os.path.dirname(__file__), "..", "..", "..", "examples", "dataset_afs.ttl" + os.path.dirname(__file__), + "..", + "..", + "..", + "examples", + "dcat", + "dataset_afs.ttl", ) result = cli.invoke(dcat_cli, ["consume", "-f", "ttl", path]) @@ -24,6 +30,7 @@ def test_produce(cli): "..", "..", "examples", + "ckan", "full_ckan_dataset.json", ) diff --git a/ckanext/dcat/tests/test_converters.py b/ckanext/dcat/tests/test_converters.py index 1d533fd6..ecea988d 100644 --- a/ckanext/dcat/tests/test_converters.py +++ b/ckanext/dcat/tests/test_converters.py @@ -26,8 +26,8 @@ def _get_lines(d): if l.startswith(('-', '+'))]) def test_ckan_to_dcat(): - ckan_dict =_get_file_as_dict('full_ckan_dataset.json') - expected_dcat_dict =_get_file_as_dict('dataset.json') + ckan_dict =_get_file_as_dict('ckan/full_ckan_dataset.json') + expected_dcat_dict =_get_file_as_dict('ckan/dataset.json') dcat_dict = converters.ckan_to_dcat(ckan_dict) @@ -35,8 +35,8 @@ def test_ckan_to_dcat(): expected_dcat_dict, dcat_dict) def test_dcat_to_ckan(): - dcat_dict =_get_file_as_dict('dataset.json') - expected_ckan_dict =_get_file_as_dict('ckan_dataset.json') + dcat_dict =_get_file_as_dict('ckan/dataset.json') + expected_ckan_dict =_get_file_as_dict('ckan/ckan_dataset.json') # Pop CKAN specific fields expected_ckan_dict.pop('id', None) diff --git a/ckanext/dcat/tests/test_euro_dcatap_profile_parse.py b/ckanext/dcat/tests/test_euro_dcatap_profile_parse.py index c4621901..b9ecc880 100644 --- a/ckanext/dcat/tests/test_euro_dcatap_profile_parse.py +++ b/ckanext/dcat/tests/test_euro_dcatap_profile_parse.py @@ -60,7 +60,7 @@ def _build_and_parse_format_mediatype_graph(self, format_item=None, mediatype_it def test_dataset_all_fields(self): - contents = self._get_file_contents('dataset.rdf') + contents = self._get_file_contents('dcat/dataset.rdf') p = RDFParser(profiles=['euro_dcat_ap']) @@ -716,7 +716,7 @@ def test_distribution_format_and_dcat_mediatype(self): def test_catalog_xml_rdf(self): - contents = self._get_file_contents('catalog.rdf') + contents = self._get_file_contents('dcat/catalog.rdf') p = RDFParser(profiles=['euro_dcat_ap']) @@ -735,7 +735,7 @@ def test_catalog_xml_rdf(self): def test_dataset_turtle_1(self): - contents = self._get_file_contents('dataset_deri.ttl') + contents = self._get_file_contents('dcat/dataset_deri.ttl') p = RDFParser(profiles=['euro_dcat_ap']) @@ -757,7 +757,7 @@ def test_dataset_turtle_1(self): def test_dataset_json_ld_1(self): - contents = self._get_file_contents('catalog_pod.jsonld') + contents = self._get_file_contents('dcat/catalog_pod.jsonld') p = RDFParser(profiles=['euro_dcat_ap']) @@ -787,7 +787,7 @@ def test_dataset_json_ld_1(self): def test_dataset_json_ld_with_at_graph(self): - contents = self._get_file_contents('catalog_with_at_graph.jsonld') + contents = self._get_file_contents('dcat/catalog_with_at_graph.jsonld') p = RDFParser(profiles=['euro_dcat_ap']) @@ -816,7 +816,7 @@ def test_dataset_json_ld_with_at_graph(self): def test_dataset_compatibility_mode(self): - contents = self._get_file_contents('dataset.rdf') + contents = self._get_file_contents('dcat/dataset.rdf') p = RDFParser(profiles=['euro_dcat_ap'], compatibility_mode=True) diff --git a/ckanext/dcat/tests/test_scheming_support.py b/ckanext/dcat/tests/test_scheming_support.py index d79523fd..5c597dce 100644 --- a/ckanext/dcat/tests/test_scheming_support.py +++ b/ckanext/dcat/tests/test_scheming_support.py @@ -726,7 +726,7 @@ def test_e2e_dcat_to_ckan(self): Parse a DCAT RDF graph into a CKAN dataset dict, create a dataset with package_create and check that all expected fields are there """ - contents = self._get_file_contents("dataset.rdf") + contents = self._get_file_contents("dcat/dataset.rdf") p = RDFParser() diff --git a/ckanext/dcat/tests/utils.py b/ckanext/dcat/tests/utils.py index 53618366..d314d938 100644 --- a/ckanext/dcat/tests/utils.py +++ b/ckanext/dcat/tests/utils.py @@ -3,6 +3,14 @@ from rdflib import URIRef, BNode, Literal +def get_file_contents(file_name): + path = os.path.join( + os.path.dirname(__file__), "..", "..", "..", "examples", file_name + ) + with open(path, "r") as f: + return f.read() + + class BaseParseTest(object): def _extras(self, dataset): extras = {} @@ -11,11 +19,7 @@ def _extras(self, dataset): return extras def _get_file_contents(self, file_name): - path = os.path.join( - os.path.dirname(__file__), "..", "..", "..", "examples", file_name - ) - with open(path, "r") as f: - return f.read() + return get_file_contents(file_name) class BaseSerializeTest(object): diff --git a/examples/catalog.json b/examples/ckan/catalog.json similarity index 100% rename from examples/catalog.json rename to examples/ckan/catalog.json diff --git a/examples/catalog_datasets_list.json b/examples/ckan/catalog_datasets_list.json similarity index 100% rename from examples/catalog_datasets_list.json rename to examples/ckan/catalog_datasets_list.json diff --git a/examples/ckan_dataset.json b/examples/ckan/ckan_dataset.json similarity index 100% rename from examples/ckan_dataset.json rename to examples/ckan/ckan_dataset.json diff --git a/examples/dataset.json b/examples/ckan/dataset.json similarity index 100% rename from examples/dataset.json rename to examples/ckan/dataset.json diff --git a/examples/full_ckan_dataset.json b/examples/ckan/full_ckan_dataset.json similarity index 100% rename from examples/full_ckan_dataset.json rename to examples/ckan/full_ckan_dataset.json diff --git a/examples/catalog.rdf b/examples/dcat/catalog.rdf similarity index 100% rename from examples/catalog.rdf rename to examples/dcat/catalog.rdf diff --git a/examples/catalog_datasets_list.rdf b/examples/dcat/catalog_datasets_list.rdf similarity index 100% rename from examples/catalog_datasets_list.rdf rename to examples/dcat/catalog_datasets_list.rdf diff --git a/examples/catalog_pod.jsonld b/examples/dcat/catalog_pod.jsonld similarity index 100% rename from examples/catalog_pod.jsonld rename to examples/dcat/catalog_pod.jsonld diff --git a/examples/catalog_with_at_graph.jsonld b/examples/dcat/catalog_with_at_graph.jsonld similarity index 100% rename from examples/catalog_with_at_graph.jsonld rename to examples/dcat/catalog_with_at_graph.jsonld diff --git a/examples/dataset.rdf b/examples/dcat/dataset.rdf similarity index 100% rename from examples/dataset.rdf rename to examples/dcat/dataset.rdf diff --git a/examples/dataset_afs.ttl b/examples/dcat/dataset_afs.ttl similarity index 100% rename from examples/dataset_afs.ttl rename to examples/dcat/dataset_afs.ttl diff --git a/examples/dataset_deri.ttl b/examples/dcat/dataset_deri.ttl similarity index 100% rename from examples/dataset_deri.ttl rename to examples/dcat/dataset_deri.ttl diff --git a/examples/dataset_gob_es.ttl b/examples/dcat/dataset_gob_es.ttl similarity index 100% rename from examples/dataset_gob_es.ttl rename to examples/dcat/dataset_gob_es.ttl diff --git a/examples/dataset_gov_de.rdf b/examples/dcat/dataset_gov_de.rdf similarity index 100% rename from examples/dataset_gov_de.rdf rename to examples/dcat/dataset_gov_de.rdf diff --git a/examples/dataset_sweden.rdf b/examples/dcat/dataset_sweden.rdf similarity index 100% rename from examples/dataset_sweden.rdf rename to examples/dcat/dataset_sweden.rdf