Skip to content

Commit

Permalink
Fix remaining behavior and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianSipos committed Jan 31, 2025
1 parent 93f9a37 commit 273ce47
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 114 deletions.
4 changes: 2 additions & 2 deletions src/ace/adm_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ def _post_load(self, adm_new:models.AdmModule, del_dupe:bool):
# if dependant adm not added yet
import_names = [obj.name for obj in adm_new.imports]
pending = False
for adm_name in import_names:
if not adm_name in self:
for module_name in import_names:
if not module_name in self:
pending = True
break

Expand Down
4 changes: 2 additions & 2 deletions src/ace/ari.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ def __str__(self) -> str:
text += f'/{self.org_id}'
if self.model_id is not None:
text += f'/{self.model_id}'
if self.ns_rev:
text += f'@{self.ns_rev}'
if self.model_rev:
text += f'@{self.model_rev}'
text += f'/{self.type_id.name}'
text += f'/{self.obj_id}'
return text
Expand Down
32 changes: 16 additions & 16 deletions src/ace/constraints/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,23 @@ class unique_adm_names: # pylint: disable=invalid-name

def __call__(self, issuelist, obj, db_sess):
count = 0
for name in ('norm_name', 'enum'):
attr = getattr(models.AdmModule, name)
search = (
db_sess.query(attr, func.count(models.AdmModule.id))
.group_by(attr)
.having(func.count(models.AdmModule.id) > 1)
attr = models.AdmModule.norm_name

search = (
db_sess.query(attr, func.count(models.AdmModule.id))
.group_by(attr)
.having(func.count(models.AdmModule.id) > 1)
)
for row in search.all():
query = db_sess.query(models.AdmModule).filter(
attr == row[0]
)
for row in search.all():
query = db_sess.query(models.AdmModule).filter(
attr == row[0]
)
for adm in query.all():
issuelist.append(Issue(
obj=adm,
detail=f'Multiple ADMs with metadata "{name}" of "{row[0]}"'
))
count += 1
for adm in query.all():
issuelist.append(Issue(
obj=adm,
detail=f'Multiple ADMs with metadata "norm_name" of "{row[0]}"'
))
count += 1

return count

Expand Down
25 changes: 12 additions & 13 deletions src/ace/constraints/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,23 @@
import logging
from ace import models


LOGGER = logging.getLogger(__name__)
#: Accumulated list of all constraints to check
CONSTRAINTS = {}
''' Accumulated list of all constraints to check '''


@dataclass
class Issue:
''' An issue resulting from a failed constraint.
'''
#: The name of the constraint noting the issue, which will be set automatically
check_name: str = None
#: The name of the ADM containing the issue, which will be set automatically
adm_name: str = None
#: The object containing the issue
''' The name of the constraint noting the issue, which will be set automatically '''
module_name: str = None
''' The name of the ADM module containing the issue, which will be set automatically '''
obj: object = None
#: Any specific detail about the issue
''' The object containing the issue '''
detail: str = None
''' Any specific detail about the issue '''


def register(obj):
Expand Down Expand Up @@ -74,7 +73,7 @@ class Checker:
def __init__(self, db_sess):
self._db_sess = db_sess

def check(self, src: models.AdmModule = None):
def check(self, src: models.AdmModule=None):
''' Check a specific ADM for issues.
:param src: The ADM to check or None.
Expand All @@ -97,8 +96,8 @@ def check(self, src: models.AdmModule = None):

# Run non-global constraints per each adm
for adm in adm_list:
adm_name = adm.norm_name
LOGGER.debug('Checking ADM: %s', adm_name)
module_name = adm.norm_name
LOGGER.debug('Checking ADM: %s', module_name)
for cst_name, cst in CONSTRAINTS.items():
if getattr(cst, 'is_global', False):
continue
Expand All @@ -117,11 +116,11 @@ def _add_result(self, issuelist, check_count, cst_name, cst, adm):
check_count += count

for issue in issuelist:
if issue.adm_name is None:
if issue.module_name is None:
if adm is not None:
issue.adm_name = adm.norm_name
issue.module_name = adm.norm_name
elif isinstance(issue.obj, models.AdmModule):
issue.adm_name = issue.obj.norm_name
issue.module_name = issue.obj.norm_name
if issue.check_name is None:
issue.check_name = cst_name
LOGGER.debug(
Expand Down
40 changes: 31 additions & 9 deletions src/ace/nickname.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,29 @@ def _convert_ref(self, ari:ReferenceARI) -> ReferenceARI:

if self._mode == Mode.TO_NN:
# Prefer nicknames
ns_id = ari.ident.ns_id
if adm is None or adm.enum is None:
org_id = ari.ident.org_id
if adm is None or adm.ns_org_enum is None:
if self._must:
if adm is None:
err = 'does not exist'
else:
err = 'does not have an enumeration'
msg = f'The ADM named {ns_id} {err}'
msg = f'The ADM named {org_id} {err}'
raise RuntimeError(msg)
else:
ns_id = adm.enum
org_id = adm.ns_org_enum

model_id = ari.ident.model_id
if adm is None or adm.ns_model_enum is None:
if self._must:
if adm is None:
err = 'does not exist'
else:
err = 'does not have an enumeration'
msg = f'The ADM named {model_id} {err}'
raise RuntimeError(msg)
else:
model_id = adm.ns_model_enum

obj_id = ari.ident.obj_id
if obj is None or obj.enum is None:
Expand All @@ -103,19 +115,28 @@ def _convert_ref(self, ari:ReferenceARI) -> ReferenceARI:

# ARI IDs from enums
new_ident = Identity(
ns_id=ns_id,
org_id=org_id,
model_id=model_id,
type_id=ari.ident.type_id,
obj_id=obj_id
)

elif self._mode == Mode.FROM_NN:
ns_id = ari.ident.ns_id
org_id = ari.ident.org_id
if adm is None:
if self._must:
msg = f'The ADM organization named {org_id} does not exist'
raise RuntimeError(msg)
else:
org_id = adm.ns_org_name

model_id = ari.ident.model_id
if adm is None:
if self._must:
msg = f'The ADM named {ns_id} does not exist'
msg = f'The ADM model named {model_id} does not exist'
raise RuntimeError(msg)
else:
ns_id = adm.norm_name
model_id = adm.ns_model_name

obj_id = ari.ident.obj_id
if obj is None:
Expand All @@ -127,7 +148,8 @@ def _convert_ref(self, ari:ReferenceARI) -> ReferenceARI:

# ARI IDs from names
new_ident = Identity(
ns_id=ns_id,
org_id=org_id,
model_id=model_id,
type_id=ari.ident.type_id,
obj_id=obj_id
)
Expand Down
22 changes: 12 additions & 10 deletions src/ace/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@

LOGGER = logging.getLogger(__name__)

AMM_MODULE_ID = 'ietf-amm'
''' Identifier of the ietf-amm module. '''

def get_amm_ident(obj_id:str) -> Identity:
''' Get an IDENT in the ietf-amm model. '''
return Identity(org_id='ietf', model_id='amm', type_id=StructType.IDENT, obj_id=obj_id)


class Constraint:
Expand Down Expand Up @@ -498,7 +500,7 @@ def all_constraints(self) -> Set[Constraint]:

def ari_name(self) -> ARI:
return ReferenceARI(
Identity(ns_id=AMM_MODULE_ID, type_id=StructType.IDENT, obj_id='semtype-use'),
get_amm_ident('semtype-use'),
params={
LiteralARI('name'): self.type_ari,
}
Expand Down Expand Up @@ -558,7 +560,7 @@ def all_constraints(self) -> Set[Constraint]:

def ari_name(self) -> ARI:
return ReferenceARI(
Identity(ns_id=AMM_MODULE_ID, type_id=StructType.IDENT, obj_id='semtype-union'),
get_amm_ident('semtype-union'),
params={
LiteralARI('choices'): LiteralARI([choice.ari_name() for choice in self.types], StructType.AC),
}
Expand Down Expand Up @@ -616,7 +618,7 @@ def all_type_ids(self) -> Set[StructType]:

def ari_name(self) -> ARI:
return ReferenceARI(
Identity(ns_id=AMM_MODULE_ID, type_id=StructType.IDENT, obj_id='semtype-ulist'),
get_amm_ident('semtype-ulist'),
params={
LiteralARI('item-type'): self.base.ari_name(),
LiteralARI('min-elements'): LiteralARI(self.min_elements),
Expand Down Expand Up @@ -697,7 +699,7 @@ def all_type_ids(self) -> Set[StructType]:

def ari_name(self) -> ARI:
return ReferenceARI(
Identity(ns_id=AMM_MODULE_ID, type_id=StructType.IDENT, obj_id='semtype-seq'),
get_amm_ident('semtype-seq'),
params={
LiteralARI('item-type'): self.base.ari_name(),
LiteralARI('min-elements'): LiteralARI(self.min_elements),
Expand Down Expand Up @@ -758,7 +760,7 @@ def all_type_ids(self) -> Set[StructType]:

def ari_name(self) -> ARI:
return ReferenceARI(
Identity(ns_id=AMM_MODULE_ID, type_id=StructType.IDENT, obj_id='semtype-dlist'),
get_amm_ident('semtype-dlist'),
params={
LiteralARI('item-types'): LiteralARI([part.ari_name() for part in self.parts], StructType.AC),
}
Expand Down Expand Up @@ -846,7 +848,7 @@ def all_type_ids(self) -> Set[StructType]:

def ari_name(self) -> ARI:
return ReferenceARI(
Identity(ns_id=AMM_MODULE_ID, type_id=StructType.IDENT, obj_id='semtype-umap'),
get_amm_ident('semtype-umap'),
params={
LiteralARI('key-type'): self.kbase.ari_name() if self.kbase is not None else NULL,
LiteralARI('value-type'): self.kbase.ari_name() if self.kbase is not None else NULL,
Expand Down Expand Up @@ -907,7 +909,7 @@ class TableColumn:

def ari_name(self) -> ARI:
return ReferenceARI(
Identity(ns_id=AMM_MODULE_ID, type_id=StructType.IDENT, obj_id='semtype-tblt-col'),
get_amm_ident('semtype-tblt-col'),
params={
LiteralARI('name'): LiteralARI('name'),
LiteralARI('datatype'): self.base.ari_name(),
Expand Down Expand Up @@ -940,7 +942,7 @@ def all_type_ids(self) -> Set[StructType]:

def ari_name(self) -> ARI:
return ReferenceARI(
Identity(ns_id=AMM_MODULE_ID, type_id=StructType.IDENT, obj_id='semtype-tblt'),
get_amm_ident('semtype-tblt'),
params={
LiteralARI('columns'): LiteralARI([col.ari_name() for col in self.columns], StructType.AC),
LiteralARI('min-elements'): LiteralARI(self.min_elements),
Expand Down
Loading

0 comments on commit 273ce47

Please sign in to comment.