示例#1
0
 def execute(self, as_obj=False, for_master=False):
     if self._template_data_dict is not True and self._datamap_data_dict is not True:
         try:
             self._set_datamap_and_template_data()
         except DatamapNotCSVException:
             raise
     self._datamap_data_dict = json.loads(self._datamap_data_json)
     self._template_data_dict = json.loads(self._template_data_json)
     logger.info("Checking template data.")
     checks = check_datamap_sheets(self._datamap_data_dict, self._template_data_dict)
     # TODO -reintroduce SKIP_MISSING_SHEETS check here
     # We set a config variable to choose whether we
     # throw out files with a single missing sheet
     try:
         self._template_data_dict = remove_failing_files(
             checks, self._template_data_dict
         )
     except NoApplicableSheetsInTemplateFiles:
         # TODO add log message here
         # for now...
         # logger.critical("There are no files containing sheets declared in datamap. Quitting.")
         raise
     except RemoveFileWithNoSheetRequiredByDatamap as e:
         logging.warning(
             f"{e.args[0][0]} does not contain the sheets required by datamap (eg. {e.args[0][1]}). Not set to "
             f"skip sheets so omitting from master. "
         )
         raise
     # TODO - we have to do something when SKIP_MISSING_SHEETS is True here
     if for_master:
         self._format_data_for_master()
示例#2
0
def test_template_checked_for_correct_sheets_which_passes(
        datamap_lst_with_sheets_same_as_template_dict, template_dict):
    """
    Function under test should notify if a template does not have all the
    sheets included in the datamap.
    """
    check_status = check_datamap_sheets(
        datamap_lst_with_sheets_same_as_template_dict, template_dict)
    for f in check_status:
        assert f.state == CheckType.PASS
        assert f.error_type == CheckType.UNDEFINED
        assert f.msg == f"File {f.filename} checked: OK."
        assert f.proceed is True
示例#3
0
def test_template_checked_for_correct_sheets_which_fails(
        datamap_lst_with_single_sheet, template_dict):
    """
    Function under test should notify if a template does not have all the
    sheets included in the datamap.
    """
    # Because there is no Introduction sheet in template data (template_dict) - should return a fail check
    check_status = check_datamap_sheets(datamap_lst_with_single_sheet,
                                        template_dict)
    for f in check_status:
        assert f.state == CheckType.FAIL
        assert f.error_type == CheckType.MISSING_SHEETS_REQUIRED_BY_DATAMAP
        assert f.msg == f"File {f.filename} has no sheet[s] Introduction."
        assert f.proceed is False