Skip to content

Commit

Permalink
Organize examples dir
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Jul 12, 2024
1 parent 1ef4054 commit 515586f
Show file tree
Hide file tree
Showing 22 changed files with 32 additions and 21 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
4 changes: 2 additions & 2 deletions ckanext/dcat/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 8 additions & 1 deletion ckanext/dcat/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -24,6 +30,7 @@ def test_produce(cli):
"..",
"..",
"examples",
"ckan",
"full_ckan_dataset.json",
)

Expand Down
8 changes: 4 additions & 4 deletions ckanext/dcat/tests/test_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ 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)

assert dcat_dict == expected_dcat_dict,_poor_mans_dict_diff(
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)
Expand Down
12 changes: 6 additions & 6 deletions ckanext/dcat/tests/test_euro_dcatap_profile_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])

Expand Down Expand Up @@ -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'])

Expand All @@ -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'])

Expand All @@ -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'])

Expand Down Expand Up @@ -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'])

Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion ckanext/dcat/tests/test_scheming_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
14 changes: 9 additions & 5 deletions ckanext/dcat/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand All @@ -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):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 515586f

Please sign in to comment.