Validator Reporter
Error and Warning Reporting Module
- class reasoner_validator.report.ReportJsonEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)
Bases:
JSONEncoder
Methods
default
(o)Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).encode
(o)Return a JSON string representation of a Python data structure.
iterencode
(o[, _one_shot])Encode the given object and yield each string representation as available.
- default(o)
Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
- class reasoner_validator.report.TRAPIGraphType(value)
Bases:
Enum
Enum type of Biolink Model compliant graph data being validated.
- Input_Edge = 'Input Edge'
- Knowledge_Graph = 'Knowledge Graph'
- Query_Graph = 'Query Graph'
- label() str
- class reasoner_validator.report.ValidationReporter(default_test: str | None = None, default_target: str | None = None, strict_validation: bool | None = None)
Bases:
object
General wrapper for managing validation status messages: information, warnings, errors and ‘critical’ (errors). The TRAPI version and Biolink Model versions are also tracked for convenience at this abstract level although their application is within specific pertinent subclasses.
Methods
add_messages
(new_messages)Batch addition of MESSAGES_BY_TARGET messages to a ValidationReporter instance. :param new_messages: MESSAGES_BY_TARGET, messages indexed by target, test and categories: one of "information", "skipped tests", "warnings", "errors" or "critical", with code-keyed dictionaries of (structured) message parameters.
apply_validation
(validation_method, *args, ...)Wrapper to allow validation_methods direct access to the ValidationReporter.
dump
([title, id_rows, msg_rows, ...])Dump all available messages captured by the ValidationReporter, printed as formatted human-readable text, on a specified file device.
dump_all_messages
([test, target, flat])Dump all messages for a given test from a given target, as JSON.
dump_critical
([test, target, flat])Dump critical error messages as JSON.
dump_errors
([test, target, flat])Dump 'error' messages as JSON.
dump_info
([test, target, flat])Dump 'information' messages as JSON.
dump_messages_type
(message_type[, test, ...])Dump ValidationReporter messages of type 'message_type' as JSON.
dump_skipped
([test, target, flat])Dump 'skipped test' messages as JSON.
dump_warnings
([test, target, flat])Dump 'warning' messages as JSON.
dumps
([id_rows, msg_rows, compact_format])Text string version of dump(): returns all available messages captured by the ValidationReporter, as a formatted human-readable text blob.
Get copy of all MESSAGES_BY_TARGET as a Python data structure.
get_all_messages_of_type
(message_type)Get MESSAGE_PARTITION dictionary of all ValidationReporter messages of a given 'message_type', harvested from all target and test contexts.
get_critical
([test, target])Get copy of all recorded 'critical' error messages, for a given test from a given target.
Returns the current target of the ValidationReporter.
Returns the current default test identifier of the ValidationReporter.
get_errors
([test, target])Get copy of all recorded 'error' messages, for a given test from a given target.
get_info
([test, target])Get copy of all recorded 'information' messages, for a given test from a given target.
get_message_type
(code)Get type of message code.
get_messages_by_target
([target])Returns a block of MESSAGES_BY_TEST corresponding to a given or default target.
get_messages_by_test
([test, target])Returns MESSAGE_CATALOG corresponding to a given or default target. Note that the dictionary returned is not a copy of the original thus caution should be taken not to mutate it! :param test: str, specified test (gets current 'default' test if not given) :param target: str, specified target (gets current 'default' test if not given) :return: MESSAGES_BY_TEST corresponding to a resolved target.
get_messages_of_type
(message_type[, test, ...])Get Python data dictionary of ValidationReporter messages of 'message_type', for a specified (or default?) target and test.
get_skipped
([test, target])Get copy of all recorded 'skipped test' messages, for a given test from a given target.
get_warnings
([test, target])Get copy of all recorded 'warning' messages, for a given test from a given target.
has_critical
([test, target])Predicate to detect any recorded critical error messages.
has_errors
([test, target])Predicate to detect any recorded error messages.
has_information
([test, target])Predicate to detect any recorded information messages.
has_message_type
(message_type[, test, target])Predicate to detect if ValidationReporter has any non-empty messages of type 'message_type'.
has_messages
([test, target])Predicate to detect any recorded validation messages.
has_skipped
([test, target])Predicate to detect any recorded 'skipped test' messages.
has_warnings
([test, target])Predicate to detect any recorded warning messages.
is_strict_validation
(graph_type[, ...])Predicate to test if strict validation is to be applied.
merge
(reporter)Merge all messages and metadata from a second ValidationReporter, into the calling ValidationReporter instance.
merge_coded_messages
(aggregated, additions)Merge additional MESSAGE_PARTITION content into an already aggregate MESSAGE_PARTITION.
report
(code[, test, target, source_trail])Capture a single validation message, as per specified 'code' (with any code-specific contextual parameters). :param code: str, dot delimited validation path code :param test: str, specified test (gets current 'default' test if not given) :param target: str, specified target (gets current 'default' test if not given) :param source_trail, Optional[str], audit trail of knowledge source provenance for a given Edge, as a string. Defaults to "global" if not specified. :param message: **Dict, named parameters representing extra (str-formatted) context for the given code message :return: None (internally record the validation message).
report_header
([title, compact_format])Return a suitably generated report header. :param title: Optional[str], if title is None, then only the 'reasoner-validator' version is printed out in the header. If the title is an empty string (the default), then 'Validation Report' used. :param compact_format: bool, whether to print the header in compact format (default: True). Extra line feeds are otherwise provided to provide space around the header and control characters are output to underline the header. :return: str, generated header.
reset_default_target
(name)Resets the default target identifier of the ValidationReporter to a new string.
reset_default_test
(name)Resets the default test identifier of the ValidationReporter to a new string.
test_case_has_validation_errors
(tag, case)Check if test case has validation errors.
to_dict
()Export ValidationReporter message contents as a Python dictionary.
merge_identified_messages
merge_scoped_messages
- DEFAULT_TRAPI_VERSION = '1'
- add_messages(new_messages: Dict[str, Dict[str, Dict[str, Dict[str, Dict[str, Dict[str, List[Dict[str, str]] | None] | None]]]]])
Batch addition of MESSAGES_BY_TARGET messages to a ValidationReporter instance. :param new_messages: MESSAGES_BY_TARGET, messages indexed by target, test and categories:
one of “information”, “skipped tests”, “warnings”, “errors” or “critical”, with code-keyed dictionaries of (structured) message parameters.
- apply_validation(validation_method, *args, **kwargs) bool
Wrapper to allow validation_methods direct access to the ValidationReporter.
- Parameters:
validation_method – function which accepts this instance of the ValidationReporter as its first argument, for use in reporting validation errors.
args – any positional arguments to the validation_method, after the initial ValidationReporter argument
kwargs – any (optional, additional) keyword arguments to the validation_method, after positional arguments
- Returns:
bool, returns ‘False’ if validation method documented (critical) errors; True otherwise
- dump(title: str | None = '', id_rows: int = 0, msg_rows: int = 0, compact_format: bool = False, file=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)
Dump all available messages captured by the ValidationReporter, printed as formatted human-readable text, on a specified file device.
- Parameters:
title – Optional[str], user supplied report title (default: autogenerated if not set or empty string; suppressed if an explicit argument of None is given); default: “” -> default title
id_rows – int >= 0, if set, maximum number of code-related identifiers to print per code (value of 0 means print all; default: 0)
msg_rows – int >= 0, if set, maximum number of parameterized code-related messages to print per identifier row (value of 0 means print all; default: 0)
compact_format – bool, if True, omit blank lines inserted by default for human readability; also, suppress character escapes (i.e. underlining of titles) (default: False)
file – target file device for output
- Returns:
n/a
- dump_all_messages(test: str | None = None, target: str | None = None, flat=False) str
Dump all messages for a given test from a given target, as JSON. :param test: str, specified test (gets current ‘default’ test if not given) :param target: str, specified target (gets current ‘default’ test if not given) :param flat: render output as ‘flat’ JSON (default: False) :return: str, JSON formatted string of all messages of test for target.
- dump_critical(test: str | None = None, target: str | None = None, flat=False) str
Dump critical error messages as JSON. :param test: str, specified test (gets current ‘default’ test if not given) :param target: str, specified target (gets current ‘default’ test if not given) :param flat: render output as ‘flat’ JSON (default: False) :return: str, JSON formatted string of critical error messages.
- dump_errors(test: str | None = None, target: str | None = None, flat=False) str
Dump ‘error’ messages as JSON. :param test: str, specified test (gets current ‘default’ test if not given) :param target: str, specified target (gets current ‘default’ test if not given) :param flat: render output as ‘flat’ JSON (default: False) :return: str, JSON formatted string of error messages.
- dump_info(test: str | None = None, target: str | None = None, flat=False) str
Dump ‘information’ messages as JSON. :param test: str, specified test (gets current ‘default’ test if not given) :param target: str, specified target (gets current ‘default’ test if not given) :param flat: render output as ‘flat’ JSON (default: False) :return: str, JSON formatted string of information messages.
- dump_messages_type(message_type: MessageType, test: str | None = None, target: str | None = None, flat=False) str
Dump ValidationReporter messages of type ‘message_type’ as JSON. :param message_type: MessageType, type of message whose presence is to be detected. :param test: str, specified test (gets current ‘default’ test if not given) :param target: str, specified target (gets current ‘default’ test if not given) :param flat: render output as ‘flat’ JSON (default: False) :return: bool, true only if ValidationReporter has any non-empty messages of type ‘message_type’.
- dump_skipped(test: str | None = None, target: str | None = None, flat=False) str
Dump ‘skipped test’ messages as JSON. :param test: str, specified test (gets current ‘default’ test if not given) :param target: str, specified target (gets current ‘default’ test if not given) :param flat: render output as ‘flat’ JSON (default: False) :return: str, JSON formatted string of ‘skipped test’ messages.
- dump_warnings(test: str | None = None, target: str | None = None, flat=False) str
Dump ‘warning’ messages as JSON. :param test: str, specified test (gets current ‘default’ test if not given) :param target: str, specified target (gets current ‘default’ test if not given) :param flat: render output as ‘flat’ JSON (default: False) :return: str, JSON formatted string of warning messages.
- dumps(id_rows: int = 0, msg_rows: int = 0, compact_format: bool = True) str
Text string version of dump(): returns all available messages captured by the ValidationReporter, as a formatted human-readable text blob.
- Parameters:
id_rows – int >= 0, if set, maximum number of code-related identifiers to print per code (value of 0 means print all; default: 0)
msg_rows – int >= 0, if set, maximum number of parameterized code-related messages to print per identifier row (value of 0 means print all; default: 0)
compact_format – bool, if True, omit blank lines inserted by default for human readability (default: True)
- Returns:
n/a
- get_all_messages() Dict[str, Dict[str, Dict[str, Dict[str, Dict[str, Dict[str, List[Dict[str, str]] | None] | None]]]]]
Get copy of all MESSAGES_BY_TARGET as a Python data structure. :return: Dict (copy) of all validation messages in the ValidationReporter.
- get_all_messages_of_type(message_type: MessageType) Dict[str, Dict[str, Dict[str, List[Dict[str, str]] | None] | None]]
Get MESSAGE_PARTITION dictionary of all ValidationReporter messages of a given ‘message_type’, harvested from all target and test contexts. :param message_type: MessageType, type of message whose presence is to be detected. :return: MESSAGE_PARTITION of aggregated messages of the specified MessageType.
- get_critical(test: str | None = None, target: str | None = None) Dict[str, Dict[str, Dict[str, List[Dict[str, str]] | None] | None]]
Get copy of all recorded ‘critical’ error messages, for a given test from a given target. :param test: str, specified test (gets current ‘default’ test if not given) :param target: str, specified target (gets current ‘default’ test if not given) :return: Dict of all ‘critical error’ messages.
- get_default_target() str
Returns the current target of the ValidationReporter. :return: str, current target
- get_default_test() str
Returns the current default test identifier of the ValidationReporter. :return: str, current default test identifier
- get_errors(test: str | None = None, target: str | None = None) Dict[str, Dict[str, Dict[str, List[Dict[str, str]] | None] | None]]
Get copy of all recorded ‘error’ messages, for a given test from a given target. :param test: str, specified test (gets current ‘default’ test if not given) :param target: str, specified target (gets current ‘default’ test if not given) :return: Dict of all ‘error’ messages.
- get_info(test: str | None = None, target: str | None = None) Dict[str, Dict[str, Dict[str, List[Dict[str, str]] | None] | None]]
Get copy of all recorded ‘information’ messages, for a given test from a given target. :param test: str, specified test (gets current ‘default’ test if not given) :param target: str, specified target (gets current ‘default’ test if not given) :return: Dict of all ‘information’ messages.
- static get_message_type(code: str) MessageType
Get type of message code. :param code: message code :return: MessageType
- get_messages_by_target(target: str | None = None) Dict[str, Dict[str, Dict[str, Dict[str, Dict[str, List[Dict[str, str]] | None] | None]]]]
Returns a block of MESSAGES_BY_TEST corresponding to a given or default target. :param target: str, specified target (gets current ‘default’ target if not given) :return: MESSAGES_BY_TEST corresponding to a resolved target
- get_messages_by_test(test: str | None = None, target: str | None = None) Dict[str, Dict[str, Dict[str, Dict[str, List[Dict[str, str]] | None] | None]]]
Returns MESSAGE_CATALOG corresponding to a given or default target. Note that the dictionary returned is not a copy of the original
thus caution should be taken not to mutate it!
- Parameters:
test – str, specified test (gets current ‘default’ test if not given)
target – str, specified target (gets current ‘default’ test if not given)
- Returns:
MESSAGES_BY_TEST corresponding to a resolved target
- get_messages_of_type(message_type: MessageType, test: str | None = None, target: str | None = None) Dict[str, Dict[str, Dict[str, List[Dict[str, str]] | None] | None]]
Get Python data dictionary of ValidationReporter messages of ‘message_type’, for a specified (or default?) target and test. :param message_type: MessageType, type of message whose presence is to be detected. :param test: str, specified test (gets current ‘default’ test if not given) :param target: str, specified target (gets current ‘default’ test if not given) :return: get copy of messages of type ‘message_type’.
- get_skipped(test: str | None = None, target: str | None = None) Dict[str, Dict[str, Dict[str, List[Dict[str, str]] | None] | None]]
Get copy of all recorded ‘skipped test’ messages, for a given test from a given target. :param test: str, specified test (gets current ‘default’ test if not given) :param target: str, specified target (gets current ‘default’ test if not given) :return: Dict of all ‘skipped test’ messages.
- get_warnings(test: str | None = None, target: str | None = None) Dict[str, Dict[str, Dict[str, List[Dict[str, str]] | None] | None]]
Get copy of all recorded ‘warning’ messages, for a given test from a given target. :param test: str, specified test (gets current ‘default’ test if not given) :param target: str, specified target (gets current ‘default’ test if not given) :return: Dict of all ‘warning’ messages.
- has_critical(test: str | None = None, target: str | None = None) bool
Predicate to detect any recorded critical error messages. :param test: str, specified test (gets current ‘default’ test if not given) :param target: str, specified target (gets current ‘default’ test if not given) :return: bool, True if ValidationReporter has any ‘critical error’ messages.
- has_errors(test: str | None = None, target: str | None = None) bool
Predicate to detect any recorded error messages. :param test: str, specified test (gets current ‘default’ test if not given) :param target: str, specified target (gets current ‘default’ test if not given) :return: bool, True if ValidationReporter has any ‘error’ messages.
- has_information(test: str | None = None, target: str | None = None) bool
Predicate to detect any recorded information messages. :param test: str, specified test (gets current ‘default’ test if not given) :param target: str, specified target (gets current ‘default’ test if not given) :return: bool, True if ValidationReporter has any ‘information’ messages.
- has_message_type(message_type: MessageType, test: str | None = None, target: str | None = None) bool
Predicate to detect if ValidationReporter has any non-empty messages of type ‘message_type’. :param message_type: MessageType, type of message whose presence is to be detected. :param test: str, specified test (gets current ‘default’ test if not given) :param target: str, specified target (gets current ‘default’ test if not given) :return: bool, true only if ValidationReporter has any non-empty messages of type ‘message_type’.
- has_messages(test: str | None = None, target: str | None = None) bool
Predicate to detect any recorded validation messages. :param test: str, specified test (gets current ‘default’ test if not given) :param target: str, specified target (gets current ‘default’ test if not given) :return: bool, True if ValidationReporter has any non-empty messages.
- has_skipped(test: str | None = None, target: str | None = None) bool
Predicate to detect any recorded ‘skipped test’ messages. :param test: str, specified test (gets current ‘default’ test if not given) :param target: str, specified target (gets current ‘default’ test if not given) :return: bool, True if ValidationReporter has any ‘skipped tests’ messages.
- has_warnings(test: str | None = None, target: str | None = None) bool
Predicate to detect any recorded warning messages. :param test: str, specified test (gets current ‘default’ test if not given) :param target: str, specified target (gets current ‘default’ test if not given) :return: bool, True if ValidationReporter has any ‘warning’ messages.
- is_strict_validation(graph_type: TRAPIGraphType, ignore_graph_type: bool = False) bool
Predicate to test if strict validation is to be applied. If the internal ‘strict_validation’ flag is not set (i.e. None), then graph_type is to resolve strictness based on TRAPI graph type context.
- Parameters:
graph_type – TRAPIGraphType, type of TRAPI graph component being validated
ignore_graph_type – bool, if strict validation is None (not set globally), then only apply graph-type-differential strict validation if ‘ignore_graph_type’ is False
- Returns:
bool, value of validation strictness set in the ValidationReporter.
- merge(reporter)
Merge all messages and metadata from a second ValidationReporter, into the calling ValidationReporter instance.
- Parameters:
reporter – second ValidationReporter
- merge_coded_messages(aggregated: Dict[str, Dict[str, Dict[str, List[Dict[str, str]] | None] | None]], additions: Dict[str, Dict[str, Dict[str, List[Dict[str, str]] | None] | None]])
Merge additional MESSAGE_PARTITION content into an already aggregate MESSAGE_PARTITION. :param aggregated: MESSAGE_PARTITION of messages aggregated so far :param additions: MESSAGE_PARTITION of additional messages to be merged into the aggregated set. :return: None - mutable ‘aggregrated’ MESSAGE_PARTITION is updated as a side effect
- static merge_identified_messages(aggregated: Dict[str, List[Dict[str, str]] | None], additions: Dict[str, List[Dict[str, str]] | None])
- merge_scoped_messages(aggregated: Dict[str, Dict[str, List[Dict[str, str]] | None] | None], additions: Dict[str, Dict[str, List[Dict[str, str]] | None] | None])
- report(code: str, test: str | None = None, target: str | None = None, source_trail: str | None = None, **message)
Capture a single validation message, as per specified ‘code’ (with any code-specific contextual parameters). :param code: str, dot delimited validation path code :param test: str, specified test (gets current ‘default’ test if not given) :param target: str, specified target (gets current ‘default’ test if not given) :param source_trail, Optional[str], audit trail of knowledge source provenance for
a given Edge, as a string. Defaults to “global” if not specified.
- Parameters:
message – **Dict, named parameters representing extra (str-formatted) context for the given code message
- Returns:
None (internally record the validation message)
- report_header(title: str | None = '', compact_format: bool = True) str
Return a suitably generated report header. :param title: Optional[str], if title is None, then only the ‘reasoner-validator’ version is printed out
in the header. If the title is an empty string (the default), then ‘Validation Report’ used.
- Parameters:
compact_format – bool, whether to print the header in compact format (default: True). Extra line feeds are otherwise provided to provide space around the header and control characters are output to underline the header.
- Returns:
str, generated header.
- reset_default_target(name: str)
Resets the default target identifier of the ValidationReporter to a new string. :param name: str, new default target identifier (generally a URL, URI or CURIE) :return: None
- reset_default_test(name: str)
Resets the default test identifier of the ValidationReporter to a new string. :param name: str, new default test identifier :return: None
- static test_case_has_validation_errors(tag: str, case: Dict) bool
Check if test case has validation errors.
- Parameters:
tag – str, top level string key in the ‘case’ whose value is the validation messages ‘dictionary’
case – Dict, containing error messages in a structurally similar format to what is returned by the to_dict() method in this class.
- Returns:
True if the case contains validation messages
- to_dict() Dict
Export ValidationReporter message contents as a Python dictionary. :return: Dict