forked from oeg-upm/yatter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |