Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration tests against reference data #62

Open
acmiyaguchi opened this issue May 1, 2019 · 0 comments
Open

Add integration tests against reference data #62

acmiyaguchi opened this issue May 1, 2019 · 0 comments

Comments

@acmiyaguchi
Copy link
Contributor

The test suite currently has a hand-curated set of expected outputs for the schemas. However, the resulting schema may not be valid against certain edge-cases. For each of the test cases under tests/resources/, there should be a json document that passes validation. This can be used for validating that transformations are working correctly.

This testing script was useful for validating sampled data from the aws pipeline against mozilla-pipeline-schemas.

def convert(data, schema):
if schema.type == "string":
if not isinstance(data, str):
return json.dumps(data)
if schema.type == "record":
# iterate over all keys
out = {}
if not data:
return out
for key, value in data.items():
# apply the appropriate transformations on the key
key = format_key(key)
field = schema.field_map.get(key)
if not field:
continue
out[key] = convert(value, field.type)
return out
if schema.type == "union":
for sub in schema.schemas:
if sub.type == "null":
continue
out = convert(data, sub)
return out
if schema.type == "array":
out = []
if not data:
return out
for item in data:
out.append(convert(item, schema.items))
return out
if schema.type == "map":
out = {}
for key, value in data.items():
out[key] = convert(value, schema.values)
return out
# terminal node, do nothing
return data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant