2019-04-04 17:05:43 +01:00
|
|
|
"""
|
|
|
|
Checks that files duplicated across schemes/implementations are consistent.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import pqclean
|
|
|
|
import helpers
|
2019-04-04 17:38:47 +01:00
|
|
|
import unittest
|
2019-04-06 14:07:44 +01:00
|
|
|
import yaml
|
2019-04-04 17:05:43 +01:00
|
|
|
|
|
|
|
def test_duplicate_consistency():
|
2019-04-10 17:07:49 +01:00
|
|
|
helpers.skip_windows()
|
2019-04-04 17:05:43 +01:00
|
|
|
for scheme in pqclean.Scheme.all_schemes():
|
|
|
|
for implementation in scheme.implementations:
|
2019-04-06 14:07:44 +01:00
|
|
|
if os.path.isfile(os.path.join('duplicate_consistency', '{}_{}.yml'.format(scheme.name, implementation.name))):
|
2019-04-10 17:07:49 +01:00
|
|
|
metafile = os.path.join('duplicate_consistency', '{}_{}.yml'.format(implementation.scheme.name, implementation.name))
|
|
|
|
with open(metafile, encoding='utf-8') as f:
|
|
|
|
metadata = yaml.load(f.read())
|
|
|
|
for group in metadata['consistency_checks']:
|
|
|
|
source = pqclean.Implementation.by_name(group['source']['scheme'], group['source']['implementation'])
|
|
|
|
for file in group['files']:
|
|
|
|
yield check_duplicate_consistency, implementation, source, file
|
2019-04-04 17:05:43 +01:00
|
|
|
|
|
|
|
def file_get_contents(filename):
|
|
|
|
with open(filename) as f:
|
|
|
|
return f.read()
|
|
|
|
|
2019-04-10 17:07:49 +01:00
|
|
|
def check_duplicate_consistency(implementation, source, file):
|
|
|
|
transformed_src = helpers.run_subprocess(
|
|
|
|
['sed', '-e', 's/{}/{}/g'.format(source.namespace_prefix(), implementation.namespace_prefix()), os.path.join(source.path(), file)]
|
|
|
|
)
|
|
|
|
this_src = file_get_contents(os.path.join(implementation.path(), file))
|
|
|
|
print(os.path.join(implementation.path(), file))
|
|
|
|
print(this_src)
|
|
|
|
assert(transformed_src == this_src)
|
2019-04-04 17:05:43 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
try:
|
|
|
|
import nose2
|
|
|
|
nose2.main()
|
|
|
|
except ImportError:
|
|
|
|
import nose
|
|
|
|
nose.runmodule()
|