Skip to content

Commit

Permalink
Resolving reviews, testing required
Browse files Browse the repository at this point in the history
* Resolving text_report review points
* Spell checking for python qc_framework
* force black formatting for all files (just to be sure)
* finishes integration with new qc_framework directory

In-depth testing should be performed, do not merge.

Signed-off-by: Matteo Ragni <[email protected]>
  • Loading branch information
MatteoRagni committed Oct 8, 2024
1 parent ef43499 commit 69bb58d
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 31 deletions.
1 change: 1 addition & 0 deletions qc_framework/qc_framework/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Public License, v. 2.0. If a copy of the MPL was not distributed
# with this file, You can obtain one at https://mozilla.org/MPL/2.0/.


if __name__ == "__main__":
from .runtime import main as qc_runtime

Expand Down
6 changes: 3 additions & 3 deletions qc_framework/qc_framework/report/base/report_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class ReportApplication:
r"""
Class that wraps the common behavior for a ``ReportFormatter`` in order to create
a command line application wich is compatible with the desing specification of the
a command line application which is compatible with the design specification of the
Quality Checker runtime.
Application created with this utility class have the following command line
Expand Down Expand Up @@ -112,7 +112,7 @@ def main(self) -> int:
def _define_arguments(self):
r"""
Defines application arguments. Parameters specific for the formatter
are created as ``"param_{name of the parmaeter}"``
are created as ``"param_{name of the parameter}"``
"""
group = self._args.add_mutually_exclusive_group(required=True)
group.add_argument(
Expand Down Expand Up @@ -237,7 +237,7 @@ def report_from_config(self, configuration_file, override_params):
r"""
Runs the formatter by loading a configuration file.
.. info:: command line parameters override configuration parmaeter values
.. info:: command line parameters override configuration parameter values
:param configuration_file: path of the configuration file to load
:param override_param: command line override params
Expand Down
35 changes: 17 additions & 18 deletions qc_framework/qc_framework/report/base/report_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# This Source Code Form is subject to the terms of the Mozilla
# Public License, v. 2.0. If a copy of the MPL was not distributed
# with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

from __future__ import annotations
from typing import Optional, Union, Dict, List
from io import IOBase, StringIO, TextIOBase
Expand All @@ -14,7 +13,7 @@
TParamValue = Optional[Union[str, int, float, bool]]
TParams = Dict[str, TParamValue]
TResultArg = Union[str, IOBase, Result]
TOuptuArg = Optional[Union[str, IOBase, StringIO, TextIOBase]]
TOutputArg = Optional[Union[str, IOBase, StringIO, TextIOBase]]
TStream = Union[IOBase, StringIO, TextIOBase]


Expand All @@ -32,7 +31,7 @@ class ReportFormatter:
function is the following::
def dump_function(
result: Reuslt,
result: Result,
get_param: Callable[[str], Optional[TParamValue]],
output: TStream) -> None:
pass
Expand All @@ -51,7 +50,7 @@ def dump_function(
the value can be modified by using injection or inheritance. To inject new values, simply
provide new values via ``kwargs``. To change via inheritance, override the appropriate property.
A full list of avaialbale ``kwargs`` is provided below.
A full list of available ``kwargs`` is provided below.
Additional parameters can be defined via injection (``kwargs``) or by an override of the property.
The custom parameters can be used also to modify the default parameters.
Expand Down Expand Up @@ -127,7 +126,7 @@ def new_custom_formatter():
:param default_output_file_param_name: optional ``kwargs`` to change parameter output file value
(default is ``"Report.txt"``). Should be a string.
:param default_custom_parameters: optional ``kwargs`` for the definition of additional parameters.
(dafault is ``{}``). With the same ``kwargs`` it is possible
(default is ``{}``). With the same ``kwargs`` it is possible
to override the default parameters value (but not keys)
"""

Expand All @@ -142,7 +141,7 @@ class Constants:

def __init__(self, *args, **kwargs):
r"""
Default constructor. Can be used for injection, or used in inhierited constructors.
Default constructor. Can be used for injection, or used in inherited constructors.
Supported parameters defined in class documentation.
"""
Expand All @@ -161,7 +160,7 @@ def __init__(self, *args, **kwargs):

def set_param(self, name: str, value: TParamValue) -> "ReportFormatter":
r"""
Method to set pèarameters value for the current formatter. Only parameters
Method to set parameters value for the current formatter. Only parameters
already defined can be changed. It currently silently fails if name is
not available. This behavior may change in the future.
Expand All @@ -177,9 +176,9 @@ def set_param(self, name: str, value: TParamValue) -> "ReportFormatter":

def get_params_list(self) -> List[str]:
r"""
Returns a list of available paramters names
Returns a list of available parameters names
:return: List of paramters names
:return: List of parameters names
"""
return list(self._parameters.keys())

Expand All @@ -194,11 +193,11 @@ def get_param(self, key: str) -> Optional[TParamValue]:
return self._parameters.get(key)

def dump(
self, input: TResultArg, output: TOuptuArg = None
self, input: TResultArg, output: TOutputArg = None
) -> Optional[str]:
r"""
Dumps the content of a result file in a different format. Input arguments
controls noth the loading and the data emission strategy.
controls both the loading and the data emission strategy.
Regarding result loading:
Expand All @@ -212,7 +211,7 @@ def dump(
Regarding the report output:
* if ``output`` parameter is ``None``, the method returns a string
* if ``ouptut`` parameter is a ``str``, the result is written in a new
* if ``output`` parameter is a ``str``, the result is written in a new
file with ``output`` as filename. If the value contains the stdout or
stderr placeholder names (by default ``__stdout__`` and ``__stderr__``),
those file are used for emitting the report.
Expand All @@ -239,8 +238,8 @@ def dump(
self._dump(result, sys.stdout) # type: ignore
if output == self.Constants.OUTPUT_FILE_IS_STDERR:
self._dump(result, sys.stderr) # type: ignore
with open(output, "w") as filepointer:
self._dump(result, filepointer)
with open(output, "w") as file_pointer:
self._dump(result, file_pointer)

def default_parameters(self) -> TParams:
r"""
Expand Down Expand Up @@ -321,7 +320,7 @@ def default_input_file_param_name(self):
:return: input parameter name
"""
return self._default_input_file_param_name # type: ignore (dinamically defined)
return self._default_input_file_param_name # type: ignore (dynamically defined)

@property
def default_input_file_param_value(self):
Expand All @@ -332,7 +331,7 @@ def default_input_file_param_value(self):
:return: input parameter value
"""
return self._default_input_file_param_value # type: ignore (dinamically defined)
return self._default_input_file_param_value # type: ignore (dynamically defined)

@property
def default_output_file_param_name(self):
Expand All @@ -343,7 +342,7 @@ def default_output_file_param_name(self):
:return: output parameter name
"""
return self._default_output_file_param_name # type: ignore (dinamically defined)
return self._default_output_file_param_name # type: ignore (dynamically defined)

@property
def default_output_file_param_value(self):
Expand All @@ -354,7 +353,7 @@ def default_output_file_param_value(self):
:return: output parameter value
"""
return self._default_output_file_param_value # type: ignore (dinamically defined)
return self._default_output_file_param_value # type: ignore (dynamically defined)

@property
def default_custom_parameters(self) -> TParams:
Expand Down
1 change: 0 additions & 1 deletion qc_framework/qc_framework/report/github_ci/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
# This Source Code Form is subject to the terms of the Mozilla
# Public License, v. 2.0. If a copy of the MPL was not distributed
# with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

from .github_ci_formatter import GithubCIFormatter
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Public License, v. 2.0. If a copy of the MPL was not distributed
# with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
from __future__ import annotations
from typing import TYPE_CHECKING, Dict, List, Any
from typing import TYPE_CHECKING

import json
from ..base import ReportFormatter
Expand Down
1 change: 0 additions & 1 deletion qc_framework/qc_framework/report/json/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
# This Source Code Form is subject to the terms of the Mozilla
# Public License, v. 2.0. If a copy of the MPL was not distributed
# with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

from .json_formatter import JsonFormatter
2 changes: 2 additions & 0 deletions qc_framework/qc_framework/report/json/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Public License, v. 2.0. If a copy of the MPL was not distributed
# with this file, You can obtain one at https://mozilla.org/MPL/2.0/.


def main():
from ..base import ReportApplication
from .json_formatter import JsonFormatter
Expand All @@ -15,5 +16,6 @@ def main():
description="Creates report for result file in JSON format")
return app.main()


if __name__ == "__main__":
main()
1 change: 0 additions & 1 deletion qc_framework/qc_framework/report/text/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
# This Source Code Form is subject to the terms of the Mozilla
# Public License, v. 2.0. If a copy of the MPL was not distributed
# with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

from .text_formatter import TextFormatter
2 changes: 2 additions & 0 deletions qc_framework/qc_framework/report/text/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Public License, v. 2.0. If a copy of the MPL was not distributed
# with this file, You can obtain one at https://mozilla.org/MPL/2.0/.


def main():
from ..base import ReportApplication
from .text_formatter import TextFormatter
Expand All @@ -15,5 +16,6 @@ def main():
description="Creates report in human readable text format")
return app.main()


if __name__ == "__main__":
main()
39 changes: 33 additions & 6 deletions qc_framework/qc_framework/report/text/text_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from ..base.report_formatter import TStream, TParams
from qc_baselib import Result


class TextFormatter(ReportFormatter):

@property
Expand Down Expand Up @@ -69,7 +70,7 @@ def n(indent=0): p("", indent)

bundles = result.get_checker_bundle_results()
for bundle in bundles:
p(f" -> {bundle.name} @ v{bundle.version}")
p(f" -> {bundle.name} @ {bundle.version}")
p(f"Description: {bundle.description}", 4)
p(f"Summary: {bundle.summary}", 4)
if len(bundle.params):
Expand Down Expand Up @@ -101,11 +102,11 @@ def n(indent=0): p("", indent)
p("Locations:", 14)
for location in issue.locations:
for file_loc in location.file_location:
p(f" -> File @ {file_loc.column}:{file_loc.row}: {location.description}", 14)
p(f" -> File @ col: {file_loc.column}, row: {file_loc.row}: {location.description}", 14)
for xml_loc in location.xml_location:
p(f" -> XML @ `{xml_loc.xpath}`: {location.description}", 14)
for inertial_loc in location.inertial_location:
p(f" -> Inertial @ [{inertial_loc.x:.4e}, {inertial_loc.y:.4e}, {inertial_loc.z:.4e}]: {location.description}", 14)
p(f" -> Inertial @ [{inertial_loc.x:.4n}; {inertial_loc.y:.4n}; {inertial_loc.z:.4n}]: {location.description}", 14)
if len(checker.metadata):
p("Metadata:", 8)
for metadata in checker.metadata:
Expand All @@ -116,9 +117,35 @@ def n(indent=0): p("", indent)
n()
S()
n()
p("RULE ADDRESSED")
p("ADDRESSED RULES")
s()
n()
p(f"Rule addressed: {len(addressed_rules)}")
p(f"Addressed rules: {len(addressed_rules)}")
for r in addressed_rules:
p(" -> {r}")
n()

p(f"Flagged Rules: {sum((len(x) for x in violated_rules.values()))}")
for t, rs in violated_rules.items():
p(f"with {t.name}: {len(rs)}", 2)
p(f"with {t.name}: {len(rs)}", 2)
for r in rs:
p(f" -> {r}", 2)

s()
n()
p("NOTES")
s()
n()
p("Rule UID format:")
p(" <emanating-entity>:<standard>:x.y.z:rule_set.for_rules.rule_name")
n()
p("where ")
p(" * Emanating Entity: a domain name for the entity (organization or company) that declares the rule UID")
p(" * Standard: a short string that represents the standard or the domain to which the rule is applied")
p(" * Definition Setting: the version of the standard or the domain to which the rule appears or is applied for the first time")
p(" * Rule Full Name: the full name of the rule, as dot separated, snake lower case string. ")
p(" The full name of a rule is composed by the rule set, a categorization for the rule, ")
p(" and the rule name, a unique string inside the categorization. ")
p(" The rule set can be nested (meaning that can be defined as an ")
p(" arbitrary sequence of dot separated names, while the name is the snake ")
p(" case string after the last dot of the full name)")

0 comments on commit 69bb58d

Please sign in to comment.