def test_should_raise_if_wrong_conf_file_format(work_dir): """ Test raise if wrong conf file format""" conf_file = join(work_dir, '.mlvtools') with open(conf_file, 'wb') as fd: fd.write(b'uueonrhfiss988#') with pytest.raises(MlVToolConfException) as e: MlVToolConf.load_from_file(conf_file, working_directory=work_dir) assert isinstance(e.value.__cause__, JSONDecodeError)
def test_should_raise_if_dvc_invalid_dvc_variable_name(work_dir): """ Test raise if dvc variable names are valid """ existing_path = join(work_dir, 'exists') makedirs(existing_path) conf_data = { 'dvc_var_python_cmd_path': '', 'dvc_var_python_cmd_name': '', 'dvc_var_meta_filename': '' } conf_file = join(work_dir, '.mlvtools') for invalid_var, valid_var_1, valid_var_2 in itertools.permutations(conf_data.keys()): conf_data[valid_var_1] = 'A_Valid_var67_name' conf_data[valid_var_1] = 'A_Valid_var67_name' for invalid_value in ('258_alphanum', '44test', 'with spaces ', 'This_is(_My_var', '#zz', '$rrr'): conf_data[invalid_var] = invalid_value with open(conf_file, 'w') as fd: json.dump(conf_data, fd) with pytest.raises(MlVToolConfException): MlVToolConf.load_from_file(conf_file, working_directory=work_dir)
def test_should_raise_if_path_not_found(work_dir): """ Test raise if at least one path does not exists""" existing_path = join(work_dir, 'exists') makedirs(existing_path) wrong_path = './does_not_exist' conf_data = { 'path': { 'python_script_root_dir': '', 'dvc_cmd_root_dir': '' }, 'ignore_keys': ['# No effect', "# Ignore"], } conf_file = join(work_dir, '.mlvtools') permutations = set(itertools.permutations([existing_path] * (len(conf_data['path']) - 1) + [wrong_path])) for perm in permutations: for i, path_name in enumerate(conf_data['path']): conf_data['path'][path_name] = perm[i] with open(conf_file, 'w') as fd: json.dump(conf_data, fd) with pytest.raises(MlVToolConfException): MlVToolConf.load_from_file(conf_file, working_directory=work_dir)
def conf(): return MlVToolConf(top_directory='./')
def test_should_raise_if_conf_file_does_not_exist(): """ Test raise if conf file does not exist""" with pytest.raises(MlVToolConfException) as e: MlVToolConf.load_from_file('./does_not.exist', working_directory='./') assert isinstance(e.value.__cause__, FileNotFoundError)