Loading testing/compat_asn1.py +36 −24 Original line number Diff line number Diff line Loading @@ -78,11 +78,6 @@ def repr_name(asnobj: pa_asnobj.ASN1Obj) -> str: return result def repr_name_type(asnobj: pa_asnobj.ASN1Obj) -> str: """Return name and type of `asnobj`, using repr_name() and repr_type().""" return f"{repr_name(asnobj)} {repr_type(asnobj)}" def repr_tagpath(asnobj: pa_asnobj.ASN1Obj) -> str: """Return tag path name of `asnobj` as MODULE.TYPE.TAG[.TAG ...]. Loading Loading @@ -114,6 +109,24 @@ def repr_type(asnobj: pa_asnobj.ASN1Obj) -> str: return result def repr_type_name(asnobj: pa_asnobj.ASN1Obj) -> str: """Return type and/or field name for `asnobj`. Returns MODULE.TYPE if asnobj has a type reference or is a type, otherwise the name of the field. """ if (tr := asnobj.get_typeref()) is not None: # reference to type in module result = repr_modname(tr) elif asnobj._parent is None: # type in module result = repr_modname(asnobj) else: # other field result = repr_name(asnobj) return result def repr_type_tagpath(asnobj: pa_asnobj.ASN1Obj) -> str: """Return type and/or tagpath for `asnobj`. Loading @@ -140,7 +153,7 @@ def container_to_tag_dict(ctx: Context, container: pa_asnobj.ASN1Dict) -> dict: tagtuple = asntype._tag if tagtuple is None: process_error( ctx, f"{repr_name(container)} field {name} doesn't have a tag" ctx, f"{repr_type_name(container)} field '{name}' doesn't have a tag" ) continue result[tagtuple[0]] = asntype Loading Loading @@ -169,8 +182,8 @@ def compare_enum( assert fa_enum.TYPE == pa_asnobj.TYPE_ENUM assert fb_enum.TYPE == pa_asnobj.TYPE_ENUM fa_desc = repr_name_type(fa_enum) fb_desc = repr_name_type(fb_enum) fa_desc = repr_type_name(fa_enum) fb_desc = repr_type_name(fb_enum) logging.info(f"Comparing enum {fa_desc} with {fb_desc}") if types_already_seen(ctx, fa_enum, fb_enum): Loading @@ -184,14 +197,14 @@ def compare_enum( if cb_name is None: process_error( ctx, f"{repr_name(fa_enum)}.{ca_name}({tag}) missing", f"{fa_desc} missing enum '{ca_name}({tag})'", ) continue # tag not in fb_enum, stop checking if ca_name != cb_name: process_error( ctx, f"{repr_name(fa_enum)}.{ca_name}({tag}) renamed to {cb_name}({tag})", f"{fa_desc}.{ca_name}({tag}) renamed to '{cb_name}({tag})'", ) Loading @@ -202,8 +215,8 @@ def compare_container( assert fa_type.TYPE in pa_asnobj.TYPE_CONSTRUCT assert fb_type.TYPE in pa_asnobj.TYPE_CONSTRUCT fa_desc = repr_name_type(fa_type) fb_desc = repr_name_type(fb_type) fa_desc = repr_type_name(fa_type) fb_desc = repr_type_name(fb_type) logging.info(f"Comparing container {fa_desc} with {fb_desc}") if types_already_seen(ctx, fa_type, fb_type): Loading @@ -220,7 +233,7 @@ def compare_container( if cb_child is None: process_error( ctx, f"{repr_name(fa_type)}.{ca_name}[{tag}] missing", f"{fa_desc} missing field '{ca_name}[{tag}]'", ) continue # tag not in fb_type, stop checking Loading @@ -230,14 +243,13 @@ def compare_container( if ca_name != cb_name: process_error( ctx, f"{repr_name(fa_type)}.{ca_name}[{tag}] renamed to {cb_name}[{tag}]", f"{fa_desc}.{ca_name}[{tag}] renamed to '{cb_name}[{tag}]'", ) if ca_typerepr != cb_typerepr: process_error( ctx, f"{repr_name(fa_type)}.{ca_name}[{tag}] {ca_typerepr} type changed to " f"{repr_name(fb_type)}.{cb_name}[{tag}] {cb_typerepr}", f"{fa_desc}.{ca_name}[{tag}] type '{ca_typerepr}' changed to '{cb_typerepr}'", ) compare_asntype(ctx=ctx, fa_type=ca_child, fb_type=cb_child) Loading @@ -253,7 +265,7 @@ def compare_container( if child._flag is None or pa_asnobj.FLAG_OPT not in child._flag: process_error( ctx, f"{repr_name(fb_type)} new tag {child._name}[{tag}] is not OPTIONAL", f"{fb_desc} new field '{child._name}[{tag}]' is not OPTIONAL", ) Loading @@ -264,8 +276,8 @@ def compare_container_of( assert fa_type.TYPE in TYPE_CONTAINER_OF assert fb_type.TYPE in TYPE_CONTAINER_OF fa_desc = repr_name_type(fa_type) fb_desc = repr_name_type(fb_type) fa_desc = repr_type_name(fa_type) fb_desc = repr_type_name(fb_type) logging.info(f"Comparing container OF {fa_desc} with {fb_desc}") # TODO: .name may end with "._item_"; removesuffix? Loading @@ -283,14 +295,14 @@ def compare_asntype( ctx: Context, fa_type: pa_asnobj.ASN1Obj, fb_type: pa_asnobj.ASN1Obj ) -> None: """Compare ASN.1 types `fa_type` and `fb_type`.""" fa_desc = repr_name_type(fa_type) fb_desc = repr_name_type(fb_type) fa_desc = repr_type_name(fa_type) fb_desc = repr_type_name(fb_type) logging.info(f"Comparing {fa_desc} with {fb_desc}") if fa_type.TYPE != fb_type.TYPE: process_error( ctx, f"{fa_desc} {fa_type.TYPE} type mismatch with {fb_desc} {fb_type.TYPE}", f"{fa_desc} type '{fa_type.TYPE}' mismatch with {fb_desc} '{fb_type.TYPE}'", ) # No further processing of this type can be performed return Loading @@ -304,7 +316,7 @@ def compare_asntype( if fa_const != fb_const: process_error( ctx, f"{fa_desc} constraint {','.join(fa_const)} changed to {fb_desc} constraint {','.join(fb_const)}", f"{fa_desc} constraint '{','.join(fa_const)}' changed to '{','.join(fb_const)}'", ) if fa_type.TYPE is pa_asnobj.TYPE_ENUM: Loading Loading @@ -352,7 +364,7 @@ def compare_asntext(ctx: Context, fa_asntext: str, fb_asntext: str) -> None: for type_name in fa_module["_type_"]: fa_type = fa_module[type_name] logging.info(f"Checking type {repr_name(fa_type)}") logging.info(f"Checking type {repr_type_name(fa_type)}") if type_name not in fb_module: process_error(ctx, f"Type {type_name} not present in {ctx.fb_path}") Loading Loading
testing/compat_asn1.py +36 −24 Original line number Diff line number Diff line Loading @@ -78,11 +78,6 @@ def repr_name(asnobj: pa_asnobj.ASN1Obj) -> str: return result def repr_name_type(asnobj: pa_asnobj.ASN1Obj) -> str: """Return name and type of `asnobj`, using repr_name() and repr_type().""" return f"{repr_name(asnobj)} {repr_type(asnobj)}" def repr_tagpath(asnobj: pa_asnobj.ASN1Obj) -> str: """Return tag path name of `asnobj` as MODULE.TYPE.TAG[.TAG ...]. Loading Loading @@ -114,6 +109,24 @@ def repr_type(asnobj: pa_asnobj.ASN1Obj) -> str: return result def repr_type_name(asnobj: pa_asnobj.ASN1Obj) -> str: """Return type and/or field name for `asnobj`. Returns MODULE.TYPE if asnobj has a type reference or is a type, otherwise the name of the field. """ if (tr := asnobj.get_typeref()) is not None: # reference to type in module result = repr_modname(tr) elif asnobj._parent is None: # type in module result = repr_modname(asnobj) else: # other field result = repr_name(asnobj) return result def repr_type_tagpath(asnobj: pa_asnobj.ASN1Obj) -> str: """Return type and/or tagpath for `asnobj`. Loading @@ -140,7 +153,7 @@ def container_to_tag_dict(ctx: Context, container: pa_asnobj.ASN1Dict) -> dict: tagtuple = asntype._tag if tagtuple is None: process_error( ctx, f"{repr_name(container)} field {name} doesn't have a tag" ctx, f"{repr_type_name(container)} field '{name}' doesn't have a tag" ) continue result[tagtuple[0]] = asntype Loading Loading @@ -169,8 +182,8 @@ def compare_enum( assert fa_enum.TYPE == pa_asnobj.TYPE_ENUM assert fb_enum.TYPE == pa_asnobj.TYPE_ENUM fa_desc = repr_name_type(fa_enum) fb_desc = repr_name_type(fb_enum) fa_desc = repr_type_name(fa_enum) fb_desc = repr_type_name(fb_enum) logging.info(f"Comparing enum {fa_desc} with {fb_desc}") if types_already_seen(ctx, fa_enum, fb_enum): Loading @@ -184,14 +197,14 @@ def compare_enum( if cb_name is None: process_error( ctx, f"{repr_name(fa_enum)}.{ca_name}({tag}) missing", f"{fa_desc} missing enum '{ca_name}({tag})'", ) continue # tag not in fb_enum, stop checking if ca_name != cb_name: process_error( ctx, f"{repr_name(fa_enum)}.{ca_name}({tag}) renamed to {cb_name}({tag})", f"{fa_desc}.{ca_name}({tag}) renamed to '{cb_name}({tag})'", ) Loading @@ -202,8 +215,8 @@ def compare_container( assert fa_type.TYPE in pa_asnobj.TYPE_CONSTRUCT assert fb_type.TYPE in pa_asnobj.TYPE_CONSTRUCT fa_desc = repr_name_type(fa_type) fb_desc = repr_name_type(fb_type) fa_desc = repr_type_name(fa_type) fb_desc = repr_type_name(fb_type) logging.info(f"Comparing container {fa_desc} with {fb_desc}") if types_already_seen(ctx, fa_type, fb_type): Loading @@ -220,7 +233,7 @@ def compare_container( if cb_child is None: process_error( ctx, f"{repr_name(fa_type)}.{ca_name}[{tag}] missing", f"{fa_desc} missing field '{ca_name}[{tag}]'", ) continue # tag not in fb_type, stop checking Loading @@ -230,14 +243,13 @@ def compare_container( if ca_name != cb_name: process_error( ctx, f"{repr_name(fa_type)}.{ca_name}[{tag}] renamed to {cb_name}[{tag}]", f"{fa_desc}.{ca_name}[{tag}] renamed to '{cb_name}[{tag}]'", ) if ca_typerepr != cb_typerepr: process_error( ctx, f"{repr_name(fa_type)}.{ca_name}[{tag}] {ca_typerepr} type changed to " f"{repr_name(fb_type)}.{cb_name}[{tag}] {cb_typerepr}", f"{fa_desc}.{ca_name}[{tag}] type '{ca_typerepr}' changed to '{cb_typerepr}'", ) compare_asntype(ctx=ctx, fa_type=ca_child, fb_type=cb_child) Loading @@ -253,7 +265,7 @@ def compare_container( if child._flag is None or pa_asnobj.FLAG_OPT not in child._flag: process_error( ctx, f"{repr_name(fb_type)} new tag {child._name}[{tag}] is not OPTIONAL", f"{fb_desc} new field '{child._name}[{tag}]' is not OPTIONAL", ) Loading @@ -264,8 +276,8 @@ def compare_container_of( assert fa_type.TYPE in TYPE_CONTAINER_OF assert fb_type.TYPE in TYPE_CONTAINER_OF fa_desc = repr_name_type(fa_type) fb_desc = repr_name_type(fb_type) fa_desc = repr_type_name(fa_type) fb_desc = repr_type_name(fb_type) logging.info(f"Comparing container OF {fa_desc} with {fb_desc}") # TODO: .name may end with "._item_"; removesuffix? Loading @@ -283,14 +295,14 @@ def compare_asntype( ctx: Context, fa_type: pa_asnobj.ASN1Obj, fb_type: pa_asnobj.ASN1Obj ) -> None: """Compare ASN.1 types `fa_type` and `fb_type`.""" fa_desc = repr_name_type(fa_type) fb_desc = repr_name_type(fb_type) fa_desc = repr_type_name(fa_type) fb_desc = repr_type_name(fb_type) logging.info(f"Comparing {fa_desc} with {fb_desc}") if fa_type.TYPE != fb_type.TYPE: process_error( ctx, f"{fa_desc} {fa_type.TYPE} type mismatch with {fb_desc} {fb_type.TYPE}", f"{fa_desc} type '{fa_type.TYPE}' mismatch with {fb_desc} '{fb_type.TYPE}'", ) # No further processing of this type can be performed return Loading @@ -304,7 +316,7 @@ def compare_asntype( if fa_const != fb_const: process_error( ctx, f"{fa_desc} constraint {','.join(fa_const)} changed to {fb_desc} constraint {','.join(fb_const)}", f"{fa_desc} constraint '{','.join(fa_const)}' changed to '{','.join(fb_const)}'", ) if fa_type.TYPE is pa_asnobj.TYPE_ENUM: Loading Loading @@ -352,7 +364,7 @@ def compare_asntext(ctx: Context, fa_asntext: str, fb_asntext: str) -> None: for type_name in fa_module["_type_"]: fa_type = fa_module[type_name] logging.info(f"Checking type {repr_name(fa_type)}") logging.info(f"Checking type {repr_type_name(fa_type)}") if type_name not in fb_module: process_error(ctx, f"Type {type_name} not present in {ctx.fb_path}") Loading