Add duplicate consistency check
This commit is contained in:
parent
72ff0dae94
commit
bc5d18e7cd
@ -70,6 +70,11 @@ class Implementation:
|
|||||||
self.scheme = scheme
|
self.scheme = scheme
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
|
def metadata(self):
|
||||||
|
for i in self.scheme.metadata()['implementations']:
|
||||||
|
if i['name'] == self.name:
|
||||||
|
return i
|
||||||
|
|
||||||
def path(self, base='..') -> str:
|
def path(self, base='..') -> str:
|
||||||
return os.path.join(self.scheme.path(), self.name)
|
return os.path.join(self.scheme.path(), self.name)
|
||||||
|
|
||||||
|
40
test/test_duplicate_consistency.py
Normal file
40
test/test_duplicate_consistency.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
"""
|
||||||
|
Checks that files duplicated across schemes/implementations are consistent.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import pqclean
|
||||||
|
import helpers
|
||||||
|
|
||||||
|
|
||||||
|
def test_duplicate_consistency():
|
||||||
|
for scheme in pqclean.Scheme.all_schemes():
|
||||||
|
for implementation in scheme.implementations:
|
||||||
|
yield check_duplicate_consistency, implementation
|
||||||
|
|
||||||
|
|
||||||
|
def file_get_contents(filename):
|
||||||
|
with open(filename) as f:
|
||||||
|
return f.read()
|
||||||
|
|
||||||
|
def check_duplicate_consistency(implementation):
|
||||||
|
print(implementation.metadata())
|
||||||
|
if 'duplicate-consistency' in implementation.metadata():
|
||||||
|
dc = implementation.metadata()['duplicate-consistency']
|
||||||
|
for pairs in dc['files']:
|
||||||
|
transformed_src = helpers.run_subprocess(
|
||||||
|
['sed', '-e', 's/{}/{}/g'.format(dc['source_namespace'], dc['target_namespace']), pairs['source_file']],
|
||||||
|
'..',
|
||||||
|
)
|
||||||
|
this_src = file_get_contents(os.path.join(implementation.path(), pairs['target_file']))
|
||||||
|
print(this_src)
|
||||||
|
assert(transformed_src == this_src)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
try:
|
||||||
|
import nose2
|
||||||
|
nose2.main()
|
||||||
|
except ImportError:
|
||||||
|
import nose
|
||||||
|
nose.runmodule()
|
@ -52,6 +52,24 @@ EXPECTED_FIELDS = {
|
|||||||
'spec': {
|
'spec': {
|
||||||
'name': {'type': str},
|
'name': {'type': str},
|
||||||
'version': {'type': str},
|
'version': {'type': str},
|
||||||
|
'duplicate-consistency': {
|
||||||
|
'type': dict,
|
||||||
|
'optional': True,
|
||||||
|
'spec': {
|
||||||
|
'source_namespace': {'type': str},
|
||||||
|
'target_namespace': {'type': str},
|
||||||
|
'files': {
|
||||||
|
'type': list,
|
||||||
|
'elements': {
|
||||||
|
'type': dict,
|
||||||
|
'spec': {
|
||||||
|
'source_file': {'type': str},
|
||||||
|
'target_file': {'type': str},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -68,14 +86,15 @@ SIGNATURE_FIELDS = {
|
|||||||
|
|
||||||
def check_spec(metadata, spec):
|
def check_spec(metadata, spec):
|
||||||
for field, props in spec:
|
for field, props in spec:
|
||||||
if field not in metadata:
|
if field not in metadata and 'optional' not in props:
|
||||||
raise AssertionError("Field '{}' not present.".format(field))
|
raise AssertionError("Field '{}' not present.".format(field))
|
||||||
|
|
||||||
# validate element
|
# validate element
|
||||||
check_element(field, metadata[field], props)
|
if field in metadata:
|
||||||
|
check_element(field, metadata[field], props)
|
||||||
|
|
||||||
# delete it to detect extras
|
# delete it to detect extras
|
||||||
del metadata[field]
|
del metadata[field]
|
||||||
|
|
||||||
# Done checking all specified fields, check if we have extras
|
# Done checking all specified fields, check if we have extras
|
||||||
for field, value in metadata.items():
|
for field, value in metadata.items():
|
||||||
|
Loading…
Reference in New Issue
Block a user