Skip to content

Commit

Permalink
Testing poetry
Browse files Browse the repository at this point in the history
  • Loading branch information
bhorinrb committed Oct 24, 2024
1 parent 2b186e6 commit 28a2127
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/normalize/NORMKEYS-01/test_normkeys01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
from ruamel.yaml import YAML
from deepdiff import DeepDiff
from yatter.normalization import normalize_yaml

R2RML_URI = 'http://www.w3.org/ns/r2rml#'


def convert_to_dict(data):
from ruamel.yaml.comments import CommentedMap
if isinstance(data, CommentedMap):
return {key: convert_to_dict(value) for key, value in data.items()}
elif isinstance(data, list):
return [convert_to_dict(item) for item in data]
else:
return data


def test_normkeys01():
yaml = YAML(typ='safe', pure=True)

with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping_normalized.yml')) as file:
expected_mapping = yaml.load(file)

with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.yml')) as file:
data = yaml.load(file)
normalized_mapping = normalize_yaml(data)

expected_mapping = convert_to_dict(expected_mapping)
normalized_mapping = convert_to_dict(normalized_mapping)

ddiff = DeepDiff(expected_mapping, normalized_mapping, ignore_order=True)

if ddiff:
assert False
else:
assert True
20 changes: 20 additions & 0 deletions test/normalize/NORMKEYS-02/mapping.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
sources:
person-source: [data/person.json~jsonpath, $]

mappings:
person:
sources:
- person-source
- [ data/person2.json~jsonpath, $ ]
- [ data/person3.json~jsonpath, "$.persons[*]" ]
- access: http://localhost/example
type: mysql
credentials:
username: root
password: root
queryFormulation: sql2008
query: |
SELECT DEPTNO, DNAME, LOC,
(SELECT COUNT(*) FROM EMP WHERE EMP.DEPTNO=DEPT.DEPTNO) AS STAFF
FROM DEPT;
referenceFormulation: csv
27 changes: 27 additions & 0 deletions test/normalize/NORMKEYS-02/mapping_normalized.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
sources:
person-source:
access: data/person.json
referenceFormulation: jsonpath
iterator: $

mappings:
person:
sources:
- person-source
- access: data/person2.json
referenceFormulation: jsonpath
iterator: $
- access: data/person3.json
referenceFormulation: jsonpath
iterator: "$.persons[*]"
- access: http://localhost/example
type: mysql
credentials:
username: root
password: root
queryFormulation: sql2008
query: |
SELECT DEPTNO, DNAME, LOC,
(SELECT COUNT(*) FROM EMP WHERE EMP.DEPTNO=DEPT.DEPTNO) AS STAFF
FROM DEPT;
referenceFormulation: csv
37 changes: 37 additions & 0 deletions test/normalize/NORMKEYS-02/test_normkeys02.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
from ruamel.yaml import YAML
from deepdiff import DeepDiff
from yatter.normalization import normalize_yaml

R2RML_URI = 'http://www.w3.org/ns/r2rml#'


def convert_to_dict(data):
from ruamel.yaml.comments import CommentedMap
if isinstance(data, CommentedMap):
return {key: convert_to_dict(value) for key, value in data.items()}
elif isinstance(data, list):
return [convert_to_dict(item) for item in data]
else:
return data


def test_normkeys02():
yaml = YAML(typ='safe', pure=True)

with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping_normalized.yml')) as file:
expected_mapping = yaml.load(file)

with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mapping.yml')) as file:
data = yaml.load(file)
normalized_mapping = normalize_yaml(data)

expected_mapping = convert_to_dict(expected_mapping)
normalized_mapping = convert_to_dict(normalized_mapping)

ddiff = DeepDiff(expected_mapping, normalized_mapping, ignore_order=True)

if ddiff:
assert False
else:
assert True

0 comments on commit 28a2127

Please sign in to comment.