add general CO3 tests to test suite
This commit is contained in:
parent
1f89f0dee8
commit
2335001a80
@ -113,6 +113,7 @@ class CO3(metaclass=FormatRegistryMeta):
|
||||
logger.debug(f'Collation for {action_key} not supported')
|
||||
return None
|
||||
else:
|
||||
return self.action_registry[action_key][0](self)
|
||||
action_method = self.action_registry[action_key][0]
|
||||
return action_method(self, *action_args, **action_kwargs)
|
||||
|
||||
|
||||
|
@ -6,3 +6,5 @@ myst-parser
|
||||
|
||||
sqlalchemy
|
||||
numpy
|
||||
|
||||
pytest
|
||||
|
@ -24,7 +24,7 @@ class Tomato(Vegetable):
|
||||
def attributes(self):
|
||||
return vars(self)
|
||||
|
||||
def collation_attributes(self, action_key, action_grounp):
|
||||
def collation_attributes(self, action_key, action_group):
|
||||
return {
|
||||
'name': self.name,
|
||||
'state': action_key,
|
||||
|
@ -1,57 +1,36 @@
|
||||
from collections import defaultdict
|
||||
|
||||
from co3.components import Relation
|
||||
|
||||
from setups import vegetables as veg
|
||||
|
||||
|
||||
def test_mapper_getters():
|
||||
veg_comp = veg.vegetable_schema.get_component('vegetable')
|
||||
tom_comp = veg.vegetable_schema.get_component('tomato')
|
||||
|
||||
assert veg.vegetable_mapper.get_attr_comp(veg.Vegetable) is veg_comp
|
||||
assert veg.vegetable_mapper.get_attr_comp(veg.Tomato) is tom_comp
|
||||
|
||||
tom_aging = veg.vegetable_schema.get_component('tomato_aging_states')
|
||||
tom_cooking = veg.vegetable_schema.get_component('tomato_cooking_states')
|
||||
|
||||
assert veg.vegetable_mapper.get_coll_comp(veg.Tomato, 'aging') is tom_aging
|
||||
assert veg.vegetable_mapper.get_coll_comp(veg.Tomato, 'cooking') is tom_cooking
|
||||
|
||||
def test_mapper_attach():
|
||||
assert veg.vegetable_mapper.attach(
|
||||
veg.Tomato,
|
||||
'tomato',
|
||||
coll_groups={
|
||||
'aging': 'tomato_aging_states',
|
||||
'cooking': 'tomato_cooking_states',
|
||||
},
|
||||
) is None
|
||||
|
||||
def test_mapper_attach_many():
|
||||
assert veg.vegetable_mapper.attach_many(
|
||||
[veg.Vegetable, veg.Tomato],
|
||||
lambda t: f'{t.__name__.lower()}'
|
||||
) is None
|
||||
|
||||
def test_mapper_collect():
|
||||
tomato = veg.Tomato('t1', 10)
|
||||
receipts = veg.vegetable_mapper.collect(tomato)
|
||||
|
||||
assert len(receipts) == 2
|
||||
def test_co3_registry():
|
||||
keys_to_groups = defaultdict(list)
|
||||
|
||||
# attempt to retrieve receipts one at a time
|
||||
res1 = veg.vegetable_mapper.collector.collect_inserts([receipts[0]])
|
||||
# collect groups each key is associated
|
||||
for action_group, action_keys in tomato.group_registry.items():
|
||||
for action_key in action_keys:
|
||||
keys_to_groups[action_key].append(action_group)
|
||||
|
||||
assert len(res1) == 1 # should be just one match
|
||||
assert len(res1[next(iter(res1.keys()))]) == 1 # and one dict for matching comp
|
||||
# check against `action_registry`, should map keys to all groups
|
||||
for action_key, (_, action_groups) in tomato.action_registry.items():
|
||||
assert keys_to_groups.get(action_key) == action_groups
|
||||
|
||||
# try again, check no persistent match
|
||||
res1 = veg.vegetable_mapper.collector.collect_inserts([receipts[0]])
|
||||
def test_co3_attributes():
|
||||
assert tomato.attributes is not None
|
||||
|
||||
assert len(res1) == 0 # should be no matches for the same receipt
|
||||
|
||||
res2 = veg.vegetable_mapper.collector.collect_inserts([receipts[1]])
|
||||
|
||||
assert len(res2) == 1
|
||||
assert len(res2[next(iter(res2.keys()))]) == 1
|
||||
def test_co3_components():
|
||||
assert tomato.components is not None
|
||||
|
||||
def test_co3_collation_attributes():
|
||||
for action_group, action_keys in tomato.group_registry.items():
|
||||
for action_key in action_keys:
|
||||
assert tomato.collation_attributes(action_key, action_group) is not None
|
||||
|
||||
def test_co3_collate():
|
||||
for action_group, action_keys in tomato.group_registry.items():
|
||||
for action_key in action_keys:
|
||||
assert tomato.collate(action_key) is not None
|
||||
|
Loading…
Reference in New Issue
Block a user