def test_get_prefix_direct(self, mock_mkdtemp): self.setup_mkdtemp(mock_mkdtemp) loader = BespinWorkflowLoader(self.direct_workflow_version) prefix = loader.get_prefix() # Does not use tmpdir self.assertEqual(prefix, 'file:///direct/') self.assertFalse(mock_mkdtemp.called)
def test__download_workflow(self, mock_urlretrieve, mock_mkdtemp): self.setup_mkdtemp(mock_mkdtemp) loader = BespinWorkflowLoader(self.zipped_workflow_version) loader._download_workflow() self.assertEqual( mock_urlretrieve.call_args, call(self.zipped_workflow_version.url, loader.download_path))
def test__handle_download_zipped(self, mock_zipfile, mock_mkdtemp): self.setup_mkdtemp(mock_mkdtemp) loader = BespinWorkflowLoader(self.zipped_workflow_version) loader._handle_download() self.assertTrue(mock_zipfile.called) self.assertEqual( mock_zipfile.return_value.__enter__.return_value.extractall. call_args, call(loader.download_dir))
def test__get_tool_path_raises(self, mock_mkdtemp): self.setup_mkdtemp(mock_mkdtemp) self.workflow_version.workflow_type = 'other' loader = BespinWorkflowLoader(self.workflow_version) with self.assertRaises(InvalidWorkflowFileException) as context: tool_path = loader._get_tool_path() self.assertIn('Workflow type other is not supported', str(context.exception))
def test__load_downloaded_workflow(self, mock_context, mock_get_tool_path, mock_load_tool, mock_mkdtemp): self.setup_mkdtemp(mock_mkdtemp) mock_get_tool_path.return_value = 'tool-path' loader = BespinWorkflowLoader(self.workflow_version) loaded = loader._load_downloaded_workflow() self.assertEqual(loaded, mock_load_tool.return_value) self.assertEqual(mock_load_tool.call_args, call('tool-path', mock_context.return_value))
def __init__(self, workflow_version): loader = BespinWorkflowLoader(workflow_version) parser = BespinWorkflowParser(loader.load()) prefix = loader.get_prefix() builder = ToolDetailsBuilder(prefix) builder.accept(parser.loaded_workflow) self.version = parser.version self.tag = parser.tag self.contents = builder.build()
def test_init_direct(self, mock_mkdtemp): self.setup_mkdtemp(mock_mkdtemp) loader = BespinWorkflowLoader(self.direct_workflow_version) self.assertFalse(mock_mkdtemp.called) self.assertEqual(loader.workflow_version, self.direct_workflow_version) self.assertFalse(hasattr(loader, 'download_path')) self.assertFalse(hasattr(loader, 'download_dir'))
def test_load(self, mock_cleanup, mock_load_downloaded_workflow, mock_handle_download, mock_download_workflow, mock_mkdtemp): self.setup_mkdtemp(mock_mkdtemp) loader = BespinWorkflowLoader(self.workflow_version) manager = Mock() manager.attach_mock(mock_download_workflow, 'download') manager.attach_mock(mock_handle_download, 'handle') manager.attach_mock(mock_load_downloaded_workflow, 'load_downloaded') manager.attach_mock(mock_cleanup, 'cleanup') loaded = loader.load() self.assertEqual(manager.mock_calls, [ call.download(), call.handle(), call.load_downloaded(), call.cleanup() ]) # Make sure we assert this check after the order, because it interferes with the calls self.assertEqual(loaded, mock_load_downloaded_workflow.return_value)
def test_init_common(self, mock_mkdtemp): self.setup_mkdtemp(mock_mkdtemp) loader = BespinWorkflowLoader(self.workflow_version) self.assertEqual(loader.download_dir, mock_mkdtemp.return_value) self.assertEqual(loader.workflow_version, self.workflow_version) self.assertEqual(loader.download_path, '/tmpdir/workflow.cwl')
def test_get_prefix_zipped(self, mock_mkdtemp): self.setup_mkdtemp(mock_mkdtemp) loader = BespinWorkflowLoader(self.zipped_workflow_version) prefix = loader.get_prefix() self.assertEqual(prefix, 'file:///tmpdir/unzipped/')
def test__cleanup_direct(self, mock_rmtree, mock_mkdtemp): self.setup_mkdtemp(mock_mkdtemp) loader = BespinWorkflowLoader(self.direct_workflow_version) loader._cleanup() self.assertFalse(mock_rmtree.called)
def test__get_tool_path_direct(self, mock_mkdtemp): self.setup_mkdtemp(mock_mkdtemp) loader = BespinWorkflowLoader(self.direct_workflow_version) tool_path = loader._get_tool_path() self.assertEqual(tool_path, 'file:///direct/direct.cwl')
def test__get_tool_path_zipped(self, mock_mkdtemp): self.setup_mkdtemp(mock_mkdtemp) loader = BespinWorkflowLoader(self.zipped_workflow_version) tool_path = loader._get_tool_path() self.assertEqual(tool_path, '/tmpdir/unzipped/workflow.cwl')
def test__get_tool_path_packed(self, mock_mkdtemp): self.setup_mkdtemp(mock_mkdtemp) loader = BespinWorkflowLoader(self.packed_workflow_version) tool_path = loader._get_tool_path() self.assertEqual(tool_path, '/tmpdir/packed.cwl#main')
def test__handle_download_packed(self, mock_zipfile, mock_mkdtemp): self.setup_mkdtemp(mock_mkdtemp) loader = BespinWorkflowLoader(self.packed_workflow_version) loader._handle_download() self.assertFalse(mock_zipfile.called)
def test__no_download_direct(self, mock_urlretriefve, mock_mkdtemp): self.setup_mkdtemp(mock_mkdtemp) loader = BespinWorkflowLoader(self.direct_workflow_version) loader._download_workflow() self.assertFalse(mock_mkdtemp.called) self.assertFalse(mock_urlretriefve.called)
def test__cleanup_zipped(self, mock_rmtree, mock_mkdtemp): self.setup_mkdtemp(mock_mkdtemp) loader = BespinWorkflowLoader(self.zipped_workflow_version) loader._cleanup() self.assertEqual(mock_rmtree.call_args, call(loader.download_dir))