def test_check_gul_and_il_and_single_ri_directory_structure_binaries_fail(self): with TemporaryDirectory() as d: for p in INPUT_FILES.values(): Path(os.path.join(d, p['name'] + '.csv')).touch() Path(os.path.join(d, p['name'] + '.bin')).touch() os.mkdir(os.path.join(d, "RI_1")) for p in INPUT_FILES.values(): Path(os.path.join(d, "RI_1", p['name'] + '.csv')).touch() Path(os.path.join(d, "RI_1", p['name'] + '.bin')).touch() with self.assertRaises(OasisException): check_inputs_directory(d, il=True, ri=True, check_binaries=True)
def test_check_gul_and_il_and_single_ri_directory_structure(self): with TemporaryDirectory() as d: for p in INPUT_FILES.values(): Path(os.path.join(d, p['name'] + '.csv')).touch() os.mkdir(os.path.join(d, "RI_1")) for p in INPUT_FILES.values(): f = os.path.join(d, "RI_1", p['name'] + '.csv') Path(f).touch() try: check_inputs_directory(d, il=True, ri=True, check_binaries=True) except Exception as e: self.fail('Exception was raised {}: {}'.format(type(e), e))
def test_il_is_true_bin_files_are_present_but_check_bin_files_are_true___no_exception_is_raised(self): with TemporaryDirectory() as d: for p in INPUT_FILES.values(): Path(os.path.join(d, p['name'] + '.csv')).touch() for p in INPUT_FILES.values(): Path(os.path.join(d, p['name'] + '.bin')).touch() try: check_inputs_directory(d, il=True, check_binaries=False) except Exception as e: self.fail('Exception was raised {}: {}'.format(type(e), e))
def tar_file_targets(min_size=0): return lists( sampled_from( [target['name'] + '.bin' for target in INPUT_FILES.values()]), min_size=min_size, unique=True, )
def test_all_files_are_present_check_il_is_true___result_is_true(self): with TemporaryDirectory() as d: tar_file_name = os.path.join(d, 'exposures.tar') with tarfile.open(tar_file_name, 'w', encoding='utf-8') as tar: for f in INPUT_FILES.values(): Path(os.path.join(d, '{}.bin'.format(f['name']))).touch() tar.add(d, arcname='/') self.assertTrue(check_binary_tar_file(tar_file_name, check_il=True))
def test_output_and_bin_input_files_are_removed(self): with TemporaryDirectory() as d: Path(os.path.join(d, TAR_FILE)).touch() for f in INPUT_FILES.values(): Path(os.path.join(d, f['name'] + '.bin')).touch() cleanup_bin_directory(d) self.assertFalse(os.path.exists(os.path.join(d, TAR_FILE))) for f in INPUT_FILES: self.assertFalse(os.path.exists(os.path.join(d, f + '.bin')))
def test_some_files_are_missing_check_il_is_true___error_is_raised(self, missing): with TemporaryDirectory() as d: tar_file_name = os.path.join(d, 'exposures.tar') with tarfile.open(tar_file_name, 'w', encoding='utf-8') as tar: for f in INPUT_FILES.values(): if f['name'] in missing: continue Path(os.path.join(d, '{}.bin'.format(f['name']))).touch() tar.add(d, arcname='/') with self.assertRaises(OasisException): check_binary_tar_file(tar_file_name, check_il=True)
fm_profile_types = ( 'acc', 'loc', ) keys_status_flags = tuple(v['id'] for v in viewvalues(OASIS_KEYS_STATUS)) perils = tuple(v['id'] for v in viewvalues(PERILS)) peril_groups = tuple(v['id'] for v in viewvalues(PERIL_GROUPS)) # Used simple echo command rather than ktools conversion utility for testing purposes ECHO_CONVERSION_INPUT_FILES = { k: ChainMap({'conversion_tool': 'echo'}, v) for k, v in INPUT_FILES.items() } def standard_input_files(min_size=0): return lists( sampled_from([ target['name'] for target in chain( viewvalues(GUL_INPUT_FILES), viewvalues(OPTIONAL_INPUT_FILES)) ]), min_size=min_size, unique=True, ) def il_input_files(min_size=0):
(t.get('FMLevelName'), t.get('FMLevel')) for t in itertools.chain(six.itervalues(canonical_exposures_profile_simple), six.itervalues(canonical_accounts_profile)) ) if t != (None,None)], key=lambda t: t[1]) ) fm_term_types = tuple(FM_TERMS[k]['desc'] for k in FM_TERMS) fm_profile_types = ('acc', 'loc',) keys_status_flags = tuple(OASIS_KEYS_STATUS[k]['id'] for k in OASIS_KEYS_STATUS) peril_ids = tuple(OASIS_PERILS[k]['id'] for k in OASIS_PERILS) oed_peril_ids = tuple(OED_PERILS[k]['id'] for k in OED_PERILS) # Used simple echo command rather than ktools conversion utility for testing purposes ECHO_CONVERSION_INPUT_FILES = {k: ChainMap({'conversion_tool': 'echo'}, v) for k, v in INPUT_FILES.items()} def standard_input_files(min_size=0): return lists( sampled_from([target['name'] for target in chain(six.itervalues(GUL_INPUT_FILES), six.itervalues(OPTIONAL_INPUT_FILES))]), min_size=min_size, unique=True, ) def il_input_files(min_size=0): return lists( sampled_from([target['name'] for target in six.itervalues(IL_INPUT_FILES)]), min_size=min_size, unique=True, )