Пример #1
0
    def _build_qa_json(self) -> QajsonRoot:
        """
        Builds a QA JSON root object based on the information currently
        entered into the user interface.
        """
        root = QajsonRoot(None)

        # update the qajson object with the check tool details
        for config_check_tool in self.tab_inputs.selected_check_tools:
            plugin_check_tool = QaxPlugins.instance().get_plugin(
                self.profile.name, config_check_tool.plugin_class)
            # update the `root` qa json object with the selected checks
            plugin_check_tool.update_qa_json(root)

            # get a list of user selected files from the relevant controls
            # for this plugin (based on the file groups)
            file_groups = plugin_check_tool.get_file_groups()
            all_files = self.tab_inputs.file_group_selection.get_files(
                file_groups)
            # update the `root` qa json object with files selected by the
            # user
            plugin_check_tool.update_qa_json_input_files(root, all_files)

            # get the plugin tab for the current check tool
            plugin_tab = next((ptab for ptab in self.tab_plugins.plugin_tabs
                               if ptab.plugin == plugin_check_tool), None)
            if plugin_tab is None:
                raise RuntimeError("No plugin tab found for {}".format(
                    config_check_tool.name))
            check_param_details = plugin_tab.get_check_ids_and_params()
            for (check_id, params) in check_param_details:
                plugin_check_tool.update_qa_json_input_params(
                    root, check_id, params)

        return root
Пример #2
0
def qajson_valid(qajson: QajsonRoot) -> bool:
    ''' Is this qajson object valid. This is implemented by first attempting to
    generate the dictionary representation (returns false if this fails).
    '''
    try:
        as_dict = qajson.to_dict()
    except Exception as e:
        return False

    # TODO: Consider validating the dictionary representation against
    # the json schema. Only reason not to would be performance.

    return True
Пример #3
0
def minimal_qajson() -> QajsonRoot:
    ''' Builds a minimal QAJSON structure '''

    version = latest_schema_version()
    raw_data = QajsonDataLevel([])
    survey_products = QajsonDataLevel([])

    qa = QajsonQa(
        version=version,
        raw_data=raw_data,
        survey_products=survey_products,
    )

    root = QajsonRoot(qa=qa)
    return root
Пример #4
0
def qajson_from_inputs(
        input: InputFileDetails,
        check_classes: List[Type['GridCheck']]) -> QajsonRoot:

    checks = []
    for check_class in check_classes:
        info = QajsonInfo(
            id=check_class.id,
            name=check_class.name,
            description=None,
            version=check_class.version,
            group=QajsonGroup("", "", ""),
        )

        input_file_path, _, _ = input.input_band_details[0]
        input_file = QajsonFile(
            path=input_file_path,
            file_type="Survey DTMs",
            description=None
        )

        inputs = QajsonInputs(
            files=[input_file],
            params=check_class.input_params
        )
        check = QajsonCheck(
            info=info,
            inputs=inputs,
            outputs=None
        )
        checks.append(check)

    datalevel = QajsonDataLevel(checks=checks)
    qa = QajsonQa(
        version=latest_schema_version(),
        raw_data=QajsonDataLevel([]),
        survey_products=datalevel,
        chart_adequacy=None
    )
    root = QajsonRoot(qa)

    return root
Пример #5
0
    def test_qa_json_generation(self):
        qa_json = QajsonRoot(qa=None)
        plugins = QaxPlugins()
        check_tool_plugin = plugins._load_plugin(
            TestQaxPlugins.check_tool_profile,
            TestQaxPlugins.check_tool_config)
        check_tool_plugin_other = plugins._load_plugin(
            TestQaxPlugins.check_tool_profile,
            TestQaxPlugins.check_tool_config_other)

        check_tool_plugin.update_qa_json(qa_json)
        check_tool_plugin_other.update_qa_json(qa_json)

        files = [
            (Path('/my/test/bagfile.bag'), 'Raw Files'),
            (Path('/my/test/csarfile.csar'), 'Raw Files'),
            (Path('/my/test/shpfile.shp'), 'Raw Files'),
        ]
        check_tool_plugin.update_qa_json_input_files(qa_json, files)
        check_tool_plugin_other.update_qa_json_input_files(qa_json, files)
Пример #6
0
    def update_qa_json(self, qa_json: QajsonRoot) -> NoReturn:
        """ Includes this plugins checks into the `qa_json` object based on
        the checks this plugin provides
        """
        if qa_json.qa is None:
            # assume schema naming convention is
            #  `some_path/v0.1.2/qa.schema.json` or similar
            last_path = QajsonParser.schema_paths()[-1]
            version = last_path.parent.name[1:]
            # if no qa object, initialise the minimum spec
            qa_json.qa = QajsonQa(
                version=version,
                raw_data=None,
                survey_products=None,
            )
            qa_json.qa.get_or_add_data_level('raw_data')
            qa_json.qa.get_or_add_data_level('survey_products')

        check_refs = self.checks()
        for check_ref in check_refs:
            data_level = qa_json.qa.get_or_add_data_level(check_ref.data_level)
            self._get_or_add_check(data_level, check_ref)
Пример #7
0
    def __init__(self,
                 path: Path,
                 schema_path: Optional[Path] = None,
                 check_valid: bool = True):
        self._path = Path(path)
        if schema_path is None:
            schema_path = self.schema_paths()[-1]
        self._schema_path = schema_path

        # validation stuff
        if check_valid:
            valid = self.validate_schema(path=self._schema_path)
            logger.debug("valid QA schema: %s" % valid)
            if not valid:
                raise RuntimeError("invalid schema: %s" % self._schema_path)

            valid = self.validate_qa_json(path=self._path,
                                          schema_path=self._schema_path)
            logger.debug("valid QA json: %s" % valid)
            if not valid:
                raise RuntimeError("invalid json: %s" % self._path)

        self._js = json.loads(open(str(self._path)).read())
        self._root = QajsonRoot.from_dict(self.js)
Пример #8
0
class TestQaCheckSummary(unittest.TestCase):

    qa_json = QajsonRoot.from_dict({
        "qa": {
            "version": "0.1.4",
            "raw_data": {
                "checks": [
                    {
                        "info": {
                            "id": "1",
                            "name": "check 01",
                            "version": "1",
                            "group": {
                                "id": "",
                                "name": ""
                            }
                        },
                        "inputs": {
                            "files": [{
                                "path": "file1.txt",
                                "file_type": "Raw Files"
                            }]
                        },
                        "outputs": {
                            "percentage": 0,
                            "execution": {
                                "start": "2019-07-08T14:56:49.006647",
                                "end": "2019-07-08T14:56:49.006677",
                                "status": "completed"
                            },
                            "files": [],
                            "check_state": "pass"
                        }
                    },
                    {
                        "info": {
                            "id": "1",
                            "name": "check 01",
                            "version": "1",
                            "group": {
                                "id": "",
                                "name": ""
                            }
                        },
                        "inputs": {
                            "files": [{
                                "path": "file3.txt",
                                "file_type": "Raw Files"
                            }]
                        },
                        "outputs": {
                            "percentage": 0,
                            "execution": {
                                "start": "2019-07-08T14:56:49.006647",
                                "end": "2019-07-08T14:56:49.006677",
                                "status": "completed"
                            },
                            "files": [],
                            "check_state": "pass"
                        }
                    },
                    {
                        "info": {
                            "id": "1",
                            "name": "check 01",
                            "version": "1",
                            "group": {
                                "id": "",
                                "name": ""
                            }
                        },
                        "inputs": {
                            "files": [{
                                "path": "file4.txt",
                                "file_type": "Raw Files"
                            }]
                        },
                        "outputs": {
                            "percentage": 0,
                            "execution": {
                                "start": "2019-07-08T14:56:49.006647",
                                "end": "2019-07-08T14:56:49.006677",
                                "status": "completed"
                            },
                            "files": [],
                            "check_state": "fail"
                        }
                    },
                    {
                        "info": {
                            "id": "2",
                            "name": "check 02",
                            "version": "1",
                            "group": {
                                "id": "",
                                "name": ""
                            }
                        },
                        "inputs": {
                            "files": [{
                                "path": "file2.txt",
                                "file_type": "Raw Files"
                            }]
                        },
                        "outputs": {
                            "percentage": 0,
                            "execution": {
                                "start": "2019-07-08T14:56:49.006647",
                                "end": "2019-07-08T14:56:49.006677",
                                "status": "failed"
                            },
                            "files": []
                        }
                    },
                ]
            },
            "survey_products": []
        }
    })

    def test_get_summary(self):
        summaries = QaCheckSummary.get_summary(TestQaCheckSummary.qa_json)

        summary_01 = next((s for s in summaries if s.id == "1"), None)
        self.assertEqual(summary_01.total_executions, 3)
        self.assertEqual(summary_01.failed_executions, 0)
        self.assertEqual(summary_01.failed_check_state, 1)

        summary_02 = next((s for s in summaries if s.id == "2"), None)
        self.assertEqual(summary_02.total_executions, 1)
        self.assertEqual(summary_02.failed_executions, 1)
        self.assertEqual(summary_02.failed_check_state, 0)