def test_create_parent_dir(self): with TempDirectory() as test_dir: file_path = os.path.join(test_dir.path, 'hello/world/does/not/exit/foo.yml') self.assertFalse(os.path.exists(file_path)) self.assertFalse(os.path.exists(os.path.dirname(file_path))) create_parent_dir(file_path) self.assertFalse(os.path.exists(file_path)) self.assertTrue(os.path.exists(os.path.dirname(file_path)))
def write_to_pickle_file(self, pickle_filename): """Write the workflow list in a pickle format to file Parameters ---------- pickle_filename : str Name of file to write (eg: step-runner-results.pkl) Raises ------ Raises a RuntimeError if the file cannot be dumped """ try: create_parent_dir(pickle_filename) with open(pickle_filename, 'wb') as file: pickle.dump(self, file) except Exception as error: raise RuntimeError( f'error dumping {pickle_filename}: {error}') from error
def write_results_to_json_file(self, json_filename): """Write the workflow list in a json format to file. Parameters ---------- json_filename : str Name of file to write (eg: step-runner-results.json) Raises ------ Raises a RuntimeError if the file cannot be dumped """ try: create_parent_dir(json_filename) with open(json_filename, 'w', encoding='utf-8') as file: results = self.__get_all_step_results_dict() json.dump(results, file, indent=4) except Exception as error: raise RuntimeError( f'error dumping {json_filename}: {error}') from error
def write_results_to_yml_file(self, yml_filename): """Write the workflow list in a yaml format to file Parameters ---------- yml_filename : str Name of file to write (eg: step-runner-results/step-runner-results.yml) Raises ------ Raises a RuntimeError if the file cannot be dumped """ try: create_parent_dir(yml_filename) with open(yml_filename, 'w') as file: results = self.__get_all_step_results_dict() yaml.dump(results, file, indent=4) except Exception as error: raise RuntimeError( f'error dumping {yml_filename}: {error}') from error
def load_from_pickle_file(pickle_filename): """Return the contents of a pickled file. The file is expected to contain WorkflowResult instances Parameters ---------- pickle_filename: str Name of the file to load Raises ------ Raises a StepRunnerException if the file cannot be loaded Raises a StepRunnerException if the file contains non WorkflowResult instances """ try: create_parent_dir(pickle_filename) # if the file does not exist return empty object if not os.path.isfile(pickle_filename): return WorkflowResult() # if the file is empty return empty object if os.path.getsize(pickle_filename) == 0: return WorkflowResult() # check that the file has Workflow object with open(pickle_filename, 'rb') as file: workflow_result = pickle.load(file) if not isinstance(workflow_result, WorkflowResult): raise StepRunnerException( f'error {pickle_filename} has invalid data') return workflow_result except Exception as error: raise StepRunnerException( f'error loading {pickle_filename}: {error}') from error
def write_effective_pom_mock_side_effect(pom_file_path, output_path, profiles): create_parent_dir(pom_file_path) copyfile(pom_file_path, output_path)