tweak test_names.py

This commit is contained in:
Matthew Yacavone 2023-04-13 13:19:14 -04:00
parent cf23e6f702
commit 5a655ea287

View File

@ -4,9 +4,6 @@ import unittest
import cryptol
from cryptol.single_connection import *
def names_dict_to_names(names_dict, *, module):
return [ {"module": module, "name": n, **vs} for n,vs in names_dict.items() ]
def filter_names(names, *, module, fields_to_exclude):
return [ { k:v for k,v in n.items() if k not in fields_to_exclude } for n in names if n["module"] == module ]
@ -17,14 +14,13 @@ class TestNames(unittest.TestCase):
# names()
expected_names_dict = {
'key': {'parameter': True},
'enc': {},
'enc_correct': {'pragmas': ['property']},
'prim': {},
'(-!)': {'infix': True, 'infix associativity': 'left-associative', 'infix level': 100}
}
expected_names = names_dict_to_names(expected_names_dict, module="Names")
expected_names = [
{'module': 'Names', 'name': 'key', 'parameter': True },
{'module': 'Names', 'name': 'enc' },
{'module': 'Names', 'name': 'enc_correct', 'pragmas': ['property'] },
{'module': 'Names', 'name': 'prim' },
{'module': 'Names', 'name': '(-!)', 'infix': True, 'infix associativity': 'left-associative', 'infix level': 100 }
]
names_to_check = filter_names(names(), module="Names", fields_to_exclude=["type", "type string"])
@ -32,10 +28,8 @@ class TestNames(unittest.TestCase):
# property_names()
expected_props_dict = {
"enc_correct": expected_names_dict["enc_correct"]
}
expected_props = names_dict_to_names(expected_props_dict, module="Names")
prop_names = ['enc_correct']
expected_props = [ n for n in expected_names if n['name'] in prop_names ]
props_to_check = filter_names(property_names(), module="Names", fields_to_exclude=["type", "type string"])
@ -43,11 +37,9 @@ class TestNames(unittest.TestCase):
# parameter_names()
expected_params_dict = {
"key": expected_names_dict["key"]
}
expected_params = names_dict_to_names(expected_params_dict, module="Names")
param_names = ['key']
expected_params = [ n for n in expected_names if n['name'] in param_names ]
params_to_check = filter_names(parameter_names(), module="Names", fields_to_exclude=["type", "type string"])
self.assertCountEqual(expected_params, params_to_check)