Skip to content

Commit cbaea6a

Browse files
authored
Implements a warning if input is not set (set to None) (#26)
Added warnings UserWarning if an input is None and skipped creating an input file containing null for it.
1 parent 6326cf5 commit cbaea6a

File tree

3 files changed

+38
-20
lines changed

3 files changed

+38
-20
lines changed

knime.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@
2323
import tempfile
2424
import subprocess
2525
import shlex
26+
import warnings
2627
import logging
2728
import os
2829

2930

3031
__author__ = "Appliomics, LLC"
31-
__copyright__ = "Copyright 2018-2019, KNIME AG"
32+
__copyright__ = "Copyright 2018-2020, KNIME AG"
3233
__credits__ = [ "Davin Potts", "Greg Landrum" ]
33-
__version__ = "0.9.6"
34+
__version__ = "0.10.0"
3435

3536

3637
__all__ = [ "Workflow", "LocalWorkflow", "RemoteWorkflow", "executable_path" ]
@@ -39,7 +40,7 @@
3940
if os.name == "nt":
4041
executable_path = os.getenv("KNIME_EXEC", r"C:\Program Files\KNIME\knime.exe")
4142
else:
42-
executable_path = os.getenv("KNIME_EXEC", "/opt/local/knime_4.0.0/knime")
43+
executable_path = os.getenv("KNIME_EXEC", "/opt/local/knime_4.2.0/knime")
4344

4445

4546
KEYPHRASE_LOCKED = b"Workflow is locked by another KNIME instance"
@@ -211,6 +212,10 @@ def run_workflow_using_multiple_service_tables(
211212

212213
option_flags_input_service_table_nodes = []
213214
for node_id, data in zip(input_service_table_node_ids, input_datas):
215+
if data is None:
216+
warnings.warn(f'No input set for node_id={node_id}', UserWarning)
217+
continue
218+
214219
input_json_filename = input_json_filename_pattern % node_id
215220
input_json_filepath = Path(temp_dir, input_json_filename)
216221

setup.py

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ def test_discovery():
3939
"Intended Audience :: End Users/Desktop",
4040
"Programming Language :: Python :: 3.6",
4141
"Programming Language :: Python :: 3.7",
42+
"Programming Language :: Python :: 3.8",
43+
"Programming Language :: Python :: 3.9",
4244
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
4345
],
4446
project_urls={

tests/test_core.py

+28-17
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import threading
77
import time
88
import unittest
9+
import warnings
910
try:
1011
import pandas as pd
1112
import numpy as np
@@ -96,6 +97,7 @@ def test_workflow_locked_by_other_instance(self):
9697
)
9798
t.join()
9899

100+
99101
def test_container_1_input_1_output_dict_input_with_pandas(self):
100102
if pd is None:
101103
self.skipTest("pandas not available")
@@ -163,9 +165,10 @@ def test_container_1_input_1_output_DataFrame_input_no_DataFrame_output(self):
163165

164166

165167
def test_container_1_input_1_output_no_input_data_without_pandas(self):
166-
results = self.templated_test_container_1_input_1_output(
167-
output_as_pandas_dataframes=False,
168-
)
168+
with self.assertWarns(UserWarning):
169+
results = self.templated_test_container_1_input_1_output(
170+
output_as_pandas_dataframes=False,
171+
)
169172
self.assertEqual(len(results), 1)
170173
self.assertTrue(isinstance(results[0], dict))
171174
returned_table_spec = (list(d)[0] for d in results[0]["table-spec"])
@@ -176,9 +179,10 @@ def test_container_1_input_1_output_no_input_data_without_pandas(self):
176179

177180

178181
def test_container_1_input_1_output_no_input_data(self):
179-
results = self.templated_test_container_1_input_1_output(
180-
output_as_pandas_dataframes=None,
181-
)
182+
with self.assertWarns(UserWarning):
183+
results = self.templated_test_container_1_input_1_output(
184+
output_as_pandas_dataframes=None,
185+
)
182186
self.assertEqual(len(results), 1)
183187
if pd is not None:
184188
self.assertTrue(isinstance(results[0], pd.DataFrame))
@@ -189,9 +193,10 @@ def test_container_1_input_1_output_no_input_data(self):
189193
def test_container_1_input_1_output_no_input_data_with_pandas(self):
190194
if pd is None:
191195
self.skipTest("pandas not available")
192-
results = self.templated_test_container_1_input_1_output(
193-
output_as_pandas_dataframes=True,
194-
)
196+
with self.assertWarns(UserWarning):
197+
results = self.templated_test_container_1_input_1_output(
198+
output_as_pandas_dataframes=True,
199+
)
195200
self.assertEqual(len(results), 1)
196201
df = results[0]
197202
self.assertTrue(isinstance(df, pd.DataFrame))
@@ -298,7 +303,6 @@ def test_container_1_input_1_output_mismatched_input_datatypes(self):
298303
)
299304

300305

301-
302306
def test_non_existent_workflow_execution(self):
303307
with knime.Workflow("tests/knime-workspace/never_gonna_give_you_up") as wf:
304308
pass # There was no execute call and so no problem.
@@ -309,7 +313,8 @@ def test_non_existent_workflow_execution(self):
309313
workflow_path="never_gonna_let_you_down"
310314
) as wf:
311315
# Existence of workflow is only checked in execute().
312-
wf.execute(output_as_pandas_dataframes=False)
316+
with self.assertWarns(UserWarning):
317+
wf.execute(output_as_pandas_dataframes=False)
313318
results = wf.data_table_outputs[:]
314319

315320

@@ -318,15 +323,17 @@ def test_specify_workspace_plus_workflow(self):
318323
workspace_path="tests/knime-workspace",
319324
workflow_path="test_simple_container_table_01"
320325
) as wf:
321-
wf.execute(output_as_pandas_dataframes=False)
326+
with self.assertWarns(UserWarning):
327+
wf.execute(output_as_pandas_dataframes=False)
322328
results = wf.data_table_outputs[:]
323329
self.assertEqual(len(results), 1)
324330

325331
with knime.Workflow(
326332
workspace_path="tests/knime-workspace",
327333
workflow_path="/test_simple_container_table_01"
328334
) as wf:
329-
wf.execute(output_as_pandas_dataframes=False)
335+
with self.assertWarns(UserWarning):
336+
wf.execute(output_as_pandas_dataframes=False)
330337
results = wf.data_table_outputs[:]
331338
self.assertEqual(len(results), 1)
332339

@@ -336,7 +343,8 @@ def test_specify_workspace_plus_workflow(self):
336343
workspace_path="tests/knime-workspace",
337344
workflow_path="never_gonna_run_around_and_desert_you"
338345
) as wf:
339-
wf.execute(output_as_pandas_dataframes=False)
346+
with self.assertWarns(UserWarning):
347+
wf.execute(output_as_pandas_dataframes=False)
340348
results = wf.data_table_outputs[:]
341349

342350
with self.assertRaises(FileNotFoundError):
@@ -345,13 +353,15 @@ def test_specify_workspace_plus_workflow(self):
345353
workspace_path="/tests/knime-workspace",
346354
workflow_path="/test_simple_container_table_01"
347355
) as wf:
348-
wf.execute(output_as_pandas_dataframes=False)
356+
with self.assertWarns(UserWarning):
357+
wf.execute(output_as_pandas_dataframes=False)
349358
results = wf.data_table_outputs[:]
350359

351360

352361
def test_AAAA_nosave_workflow_after_execution_as_default(self):
353362
with knime.Workflow("tests/knime-workspace/test_simple_container_table_01") as wf:
354-
wf.execute(output_as_pandas_dataframes=False)
363+
with self.assertWarns(UserWarning):
364+
wf.execute(output_as_pandas_dataframes=False)
355365
results = wf.data_table_outputs[:]
356366
self.assertEqual(wf.data_table_inputs_parameter_names, ("input",))
357367

@@ -363,7 +373,8 @@ def test_AAAA_nosave_workflow_after_execution_as_default(self):
363373
def test_zzzz_save_workflow_after_execution(self):
364374
with knime.Workflow("tests/knime-workspace/test_simple_container_table_01") as wf:
365375
wf.save_after_execution = True
366-
wf.execute(output_as_pandas_dataframes=False)
376+
with self.assertWarns(UserWarning):
377+
wf.execute(output_as_pandas_dataframes=False)
367378
results = wf.data_table_outputs[:]
368379
self.assertEqual(wf.data_table_inputs_parameter_names, ("input",))
369380

0 commit comments

Comments
 (0)