def test_no_existing_source_file(self): """ should succeed even if the step has no source file """ support.create_project(self, 'richfield') support.add_step(self, 'first') project = cauldron.project.get_internal_project() step = project.steps[0] r = Response() self.assertTrue( systems.remove(step.source_path), 'should have removed source file' ) result = step_actions.modify_step( response=r, project=project, name=step.filename, new_name='solo', title='Only Step' ) new_step = project.steps[0] self.assertTrue(result) self.assertTrue(os.path.exists(new_step.source_path))
def initialize_results_path(results_path: str): """ :param results_path: :return: """ dest_path = environ.paths.clean(results_path) if not os.path.exists(dest_path): os.makedirs(dest_path) web_src_path = environ.paths.resources('web') for item in os.listdir(web_src_path): item_path = os.path.join(web_src_path, item) out_path = os.path.join(dest_path, item) systems.remove(out_path) if os.path.isdir(item_path): shutil.copytree(item_path, out_path) else: shutil.copy2(item_path, out_path)
def test_remove_folder_success(self): """ should remove file when os.remove succeeds """ path = 'NOT-REAL-PATH' with ExitStack() as stack: exists = stack.enter_context(patch('os.path.exists')) exists.return_value = True is_file = stack.enter_context(patch('os.path.isfile')) is_file.return_value = False remove_tree = stack.enter_context(patch('shutil.rmtree')) remove_tree.return_value = True self.assertTrue(systems.remove(path)) exists.assert_called_with(path) self.assertEqual(remove_tree.call_count, 1)
def test_remove_folder_fail(self): """ should fail to remove folder when os.remove fails """ path = 'NOT-REAL-PATH' with ExitStack() as stack: exists = stack.enter_context(patch('os.path.exists')) exists.return_value = True is_file = stack.enter_context(patch('os.path.isfile')) is_file.return_value = False remove_tree = stack.enter_context(patch('shutil.rmtree')) remove_tree.side_effect = IOError('FAKE ERROR') self.assertFalse(systems.remove(path)) exists.assert_called_with(path) self.assertEqual(remove_tree.call_count, 3)
def test_no_existing_source_file(self): """ should succeed even if the step has no source file """ support.create_project(self, 'richfield') support.add_step(self, 'first') project = cauldron.project.get_internal_project() step = project.steps[0] r = Response() self.assertTrue(systems.remove(step.source_path), 'should have removed source file') result = step_actions.modify_step(response=r, project=project, name=step.filename, new_name='solo', title='Only Step') new_step = project.steps[0] self.assertTrue(result) self.assertTrue(os.path.exists(new_step.source_path))
def test_remove_no_path(self): """ should abort removal if path is None """ self.assertFalse(systems.remove(None))