def test_specify_workspace_plus_workflow(self): with knime.Workflow( workspace_path="tests/knime-workspace", workflow_path="test_simple_container_table_01") as wf: with self.assertWarns(UserWarning): wf.execute(output_as_pandas_dataframes=False) results = wf.data_table_outputs[:] self.assertEqual(len(results), 1) with knime.Workflow( workspace_path="tests/knime-workspace", workflow_path="/test_simple_container_table_01") as wf: with self.assertWarns(UserWarning): wf.execute(output_as_pandas_dataframes=False) results = wf.data_table_outputs[:] self.assertEqual(len(results), 1) with self.assertRaises(FileNotFoundError): # Non-existent workflow. with knime.Workflow( workspace_path="tests/knime-workspace", workflow_path="never_gonna_run_around_and_desert_you" ) as wf: with self.assertWarns(UserWarning): wf.execute(output_as_pandas_dataframes=False) results = wf.data_table_outputs[:] with self.assertRaises(FileNotFoundError): # Non-existent workspace (note the leading slash). with knime.Workflow( workspace_path="/tests/knime-workspace", workflow_path="/test_simple_container_table_01") as wf: with self.assertWarns(UserWarning): wf.execute(output_as_pandas_dataframes=False) results = wf.data_table_outputs[:]
def test_non_existent_workflow_execution(self): with knime.Workflow( "tests/knime-workspace/never_gonna_give_you_up") as wf: pass # There was no execute call and so no problem. with self.assertRaises(FileNotFoundError): with knime.Workflow( workspace_path="tests/knime-workspace", workflow_path="never_gonna_let_you_down") as wf: # Existence of workflow is only checked in execute(). wf.execute(output_as_pandas_dataframes=False) results = wf.data_table_outputs[:]
def test_AAAA_nosave_workflow_after_execution_as_default(self): with knime.Workflow("tests/knime-workspace/test_simple_container_table_01") as wf: with self.assertWarns(UserWarning): wf.execute(output_as_pandas_dataframes=False) results = wf.data_table_outputs[:] self.assertEqual(wf.data_table_inputs_parameter_names, ("input",)) with open(wf.path_to_knime_workflow / ".savedWithData") as fp: contents_hash = hashlib.md5(fp.read().encode('utf8')).hexdigest() self.assertEqual(contents_hash, "ac23b46d2e75be6a9ce5f479104de658")
def test_obtain_remote_workflow_svg(self): workspace_path = self.knime_server_urlroot workflow_path = f"{self.knime_server_testdir}/test20190410" wf = knime.Workflow( workspace_path=workspace_path, workflow_path=workflow_path, username=self.knime_server_username, password=self.knime_server_password ) image = wf._adjust_svg() self.assertTrue("clip" in image)
def templated_test_container_1_input_1_output( input_data_table=None, output_as_pandas_dataframes=None): with knime.Workflow( "tests/knime-workspace/test_simple_container_table_01") as wf: if input_data_table is not None: wf.data_table_inputs[0] = input_data_table if output_as_pandas_dataframes is not None: wf.execute( output_as_pandas_dataframes=output_as_pandas_dataframes) else: wf.execute() results = wf.data_table_outputs[:] return results
def test_absent_remote_workflow_behavior(self): workspace_path = self.knime_server_urlroot workflow_path = f"{self.knime_server_testdir}/not_there_00" wf = knime.Workflow( workspace_path=workspace_path, workflow_path=workflow_path, username=self.knime_server_username, password=self.knime_server_password ) with self.assertRaises(LookupError), self.assertLogs(level=ERROR): _image = wf._adjust_svg() with self.assertRaises(LookupError), self.assertLogs(level=ERROR): _inputs_list = wf.data_table_inputs with self.assertRaises(LookupError), self.assertLogs(level=ERROR): # Triggers LookupError not RuntimeError because execute() attempts # to access self.data_table_inputs first. wf.execute()
def test_no_inputs_remote_workflow_execution(self): workflow_url_via_webportal = \ f"{self.knime_server_urlroot}/#/{self.knime_server_testdir.strip('/')}/quick_ip_address" with knime.Workflow( workflow_url_via_webportal, # Verify webportal-style urls work. username=self.knime_server_username, password=self.knime_server_password ) as wf: self.assertEqual(len(wf.data_table_inputs), 0) wf.execute(timeout_ms=10000) output_table = wf.data_table_outputs[0] if pd is not None: # Verify if pandas is available that it is being used. content_type = output_table.iloc[0, 1] else: # Verify if pandas is not available that we get a list. content_type = output_table[0][1] self.assertEqual(content_type, "application/json")
def test_basic_remote_workflow_execution_missing_input(self): workspace_path = self.knime_server_urlroot workflow_path = f"{self.knime_server_testdir}/test20190410" # This workflow will return the default table from Container Input # when no input data is otherwise supplied. with knime.Workflow( workspace_path=workspace_path, workflow_path=workflow_path, username=self.knime_server_username, password=self.knime_server_password ) as wf: self.assertEqual(len(wf.data_table_inputs), 1) with self.assertWarns(UserWarning): wf.execute( reset=True, output_as_pandas_dataframes=False, timeout_ms=10000 ) self.assertEqual(len(wf.data_table_outputs), 1)
def test_basic_remote_workflow_execution_with_pandas(self): simple_input_df = pd.DataFrame( [['blau', 42], ['gelb', -1]], columns=['colors', 'vote'] ) workspace_path = self.knime_server_urlroot workflow_path = f"{self.knime_server_testdir}/test20190410" with knime.Workflow( workspace_path=workspace_path, workflow_path=workflow_path, username=self.knime_server_username, password=self.knime_server_password ) as wf: self.assertEqual(len(wf.data_table_inputs), 1) wf.data_table_inputs[:] = [simple_input_df] wf.execute(reset=True, timeout_ms=10000) self.assertEqual(len(wf.data_table_outputs), 1) output_table = wf.data_table_outputs[0] self.assertTrue(output_table.equals(simple_input_df))
def test_trigger_timeout_on_remote_workflow_execution(self): simple_input_dict = { 'table-spec': [{'colors': 'string'}, {'rank': 'double'}], 'table-data': [['blau', 42.7], ['gelb', -1.1]] } workspace_path = self.knime_server_urlroot workflow_path = f"{self.knime_server_testdir}/test20190410" with self.assertLogs(level=ERROR): with self.assertRaises(RuntimeError): with knime.Workflow( workspace_path=workspace_path, workflow_path=workflow_path, username=self.knime_server_username, password=self.knime_server_password ) as wf: wf.data_table_inputs[:] = [simple_input_dict] wf.execute( reset=True, timeout_ms=0 ) self.assertEqual(wf._last_status_code, 504)
def test_basic_remote_workflow_execution_without_pandas(self): simple_input_dict = { 'table-spec': [{'colors': 'string'}, {'vote': 'long'}], 'table-data': [['blau', 42], ['gelb', -1]] } workspace_path = self.knime_server_urlroot workflow_path = f"{self.knime_server_testdir}/test20190410" with knime.Workflow( workspace_path=workspace_path, workflow_path=workflow_path, username=self.knime_server_username, password=self.knime_server_password ) as wf: self.assertEqual(len(wf.data_table_inputs), 1) wf.data_table_inputs[:] = [simple_input_dict] wf.execute( reset=True, output_as_pandas_dataframes=False, timeout_ms=10000 ) self.assertEqual(len(wf.data_table_outputs), 1) output_table = wf.data_table_outputs[0] self.assertEqual(output_table, simple_input_dict['table-data'])
def test_obtain_local_workflow_svg(self): wf = knime.Workflow( "tests/knime-workspace/test_simple_container_table_01") image = wf._adjust_svg() self.assertTrue("clip" in image)