def test_yml_parser_raises_exception(): """ Unit: tests YML parsing. """ BASE_YML_TEST_FOLDER = "./tests/data/drms/" print(parse_yml(BASE_YML_TEST_FOLDER + "drm_yml_parser_broken.yml")) assert parse_yml(BASE_YML_TEST_FOLDER + "drm_yml_parser_broken.yml") is None
def drm_model_sat_coupon_1(): """ DRM dict model for sat coupon. """ DRM_TEST_YML_FOLDER = "./tests/data/drms/" drm = parse_yml(DRM_TEST_YML_FOLDER + "drm_sat_coupon_1.yml") return drm
def drm_model_no_match_1(): """ DRM dict model for an unknown coupon. """ DRM_TEST_YML_FOLDER = "./tests/data/drms/" drm = parse_yml(DRM_TEST_YML_FOLDER + "drm_no_match_1.yml") return drm
def scan_drms_folder(drms_path): """ Scans the DRM directory in order to load a list of available DRMs to parse the ocr result string. Args: drms_path (str): file system folder path of the drms Returns: (list): list of DRMs to parse the ocr result string. """ base_path = os.path.join(drms_path, "") # adds final flash of the directory all_files = os.listdir(drms_path) drms = [] for file in all_files: logger.debug("Reading file %s...", base_path + file) drm_dict = parse_yml(base_path + file) if drm_dict and is_valid_drm(drm_dict): logger.debug("Appending valid DRM...") drms.append(drm_dict) logger.debug("Returning scanned DRMs...") return drms
def drm_model_tax_coupon_with_inline_groups(): """ DRM dict model for tax coupon. """ DRM_TEST_YML_FOLDER = "./tests/data/drms/" drm = parse_yml(DRM_TEST_YML_FOLDER + "drm_inline_named_groups_1.yml") return drm
def test_scan_drms_folder( drm_model_tax_coupon_1, drm_model_sat_coupon_1, drm_model_no_match_1 ): """ Unit: tests that all the drms on the given folder get properly scanned and translated from yml to dictionary (valid ones only). """ DRM_SCANNER_TEST_YML_FOLDER = "./tests/data/drms_scanner/" # method invocation all_drms = scan_drms_folder(DRM_SCANNER_TEST_YML_FOLDER) expected_drm_1 = parse_yml(DRM_SCANNER_TEST_YML_FOLDER + "drm_1.yml") expected_drm_2 = parse_yml(DRM_SCANNER_TEST_YML_FOLDER + "drm_2.yml") expected_drms = [expected_drm_1, expected_drm_2] assert all_drms == expected_drms
def test_yml_parser(): """ Unit: tests YML parsing. """ BASE_YML_TEST_FOLDER = "./tests/data/drms/" expected_yml_dict = { "identifiers": ["id1", "id2"], "fields": { "test1": "key1", "test2": "key2" }, } assert (parse_yml(BASE_YML_TEST_FOLDER + "drm_yml_parser.yml") == expected_yml_dict)