diff --git a/SpiffWorkflow/bpmn/PythonScriptEngineEnvironment.py b/SpiffWorkflow/bpmn/PythonScriptEngineEnvironment.py index d90f21727..b0dd366c6 100644 --- a/SpiffWorkflow/bpmn/PythonScriptEngineEnvironment.py +++ b/SpiffWorkflow/bpmn/PythonScriptEngineEnvironment.py @@ -18,7 +18,6 @@ # 02110-1301 USA import copy -import warnings class BasePythonScriptEngineEnvironment: @@ -78,82 +77,3 @@ def check_for_overwrite(self, context, external_methods): f"function(s). Please change the following variable or " \ f"field name(s) to something else: {func_overwrites}" raise ValueError(msg) - - -class Box(dict): - """ - Example: - m = Box({'first_name': 'Eduardo'}, last_name='Pool', age=24, sports=['Soccer']) - """ - - def __init__(self, *args, **kwargs): - warnings.warn('The usage of Box has been deprecated.', DeprecationWarning, stacklevel=2) - super(Box, self).__init__(*args, **kwargs) - for arg in args: - if isinstance(arg, dict): - for k, v in arg.items(): - if isinstance(v, dict): - self[k] = Box(v) - else: - self[k] = v - - if kwargs: - for k, v in kwargs.items(): - if isinstance(v, dict): - self[k] = Box(v) - else: - self[k] = v - - def __deepcopy__(self, memodict=None): - if memodict is None: - memodict = {} - my_copy = Box() - for k, v in self.items(): - my_copy[k] = copy.deepcopy(v) - return my_copy - - def __getattr__(self, attr): - try: - output = self[attr] - except Exception: - raise AttributeError( - "Dictionary has no attribute '%s' " % str(attr)) - return output - - def __setattr__(self, key, value): - self.__setitem__(key, value) - - def __setitem__(self, key, value): - super(Box, self).__setitem__(key, value) - self.__dict__.update({key: value}) - - def __getstate__(self): - return self.__dict__ - - def __setstate__(self, state): - self.__init__(state) - - def __delattr__(self, item): - self.__delitem__(item) - - def __delitem__(self, key): - super(Box, self).__delitem__(key) - del self.__dict__[key] - - @classmethod - def convert_to_box(cls, data): - if isinstance(data, dict): - for key, value in data.items(): - if not isinstance(value, Box): - data[key] = cls.convert_to_box(value) - return Box(data) - if isinstance(data, list): - for idx, value in enumerate(data): - data[idx] = cls.convert_to_box(value) - return data - return data - -class BoxedTaskDataEnvironment(TaskDataEnvironment): - def _prepare_context(self, context): - Box.convert_to_box(context) - diff --git a/tests/SpiffWorkflow/bpmn/BoxDeepCopyTest.py b/tests/SpiffWorkflow/bpmn/BoxDeepCopyTest.py deleted file mode 100644 index c0b3cc790..000000000 --- a/tests/SpiffWorkflow/bpmn/BoxDeepCopyTest.py +++ /dev/null @@ -1,26 +0,0 @@ -import unittest - -from SpiffWorkflow.bpmn.PythonScriptEngineEnvironment import Box - - -class BoxDeepCopyTest(unittest.TestCase): - - def test_deep_copy_of_box(self): - data = {"foods": { - "spam": {"delicious": False} - }, - "hamsters": ['your', 'mother'] - } - data = Box(data) - data2 = data.__deepcopy__() - self.assertEqual(data, data2) - data.foods.spam.delicious = True - data.hamsters = ['your', 'father'] - self.assertFalse(data2.foods.spam.delicious) - self.assertEqual(['your', 'mother'], data2.hamsters) - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(BoxDeepCopyTest) - -if __name__ == '__main__': - unittest.TextTestRunner(verbosity=2).run(suite()) diff --git a/tests/SpiffWorkflow/bpmn/FeelExpressionEngineTest.py b/tests/SpiffWorkflow/bpmn/FeelExpressionEngineTest.py index d7d38da5b..e17cce80a 100644 --- a/tests/SpiffWorkflow/bpmn/FeelExpressionEngineTest.py +++ b/tests/SpiffWorkflow/bpmn/FeelExpressionEngineTest.py @@ -1,8 +1,7 @@ -# -*- coding: utf-8 -*- import datetime from SpiffWorkflow.bpmn.FeelLikeScriptEngine import FeelLikeScriptEngine, FeelInterval -from SpiffWorkflow.bpmn.PythonScriptEngineEnvironment import BoxedTaskDataEnvironment +from SpiffWorkflow.bpmn.PythonScriptEngineEnvironment import TaskDataEnvironment from .BpmnWorkflowTestCase import BpmnWorkflowTestCase @@ -12,7 +11,7 @@ class FeelExpressionTest(BpmnWorkflowTestCase): def setUp(self): - self.expressionEngine = FeelLikeScriptEngine(environment=BoxedTaskDataEnvironment()) + self.expressionEngine = FeelLikeScriptEngine(environment=TaskDataEnvironment()) def testRunThroughExpressions(self): tests = [("string length('abcd')", 4, {}), @@ -41,8 +40,6 @@ def testRunThroughExpressions(self): {}), ("day of week('2020-05-07')", 4, {}), ("day of week(a)", 0, {'a': datetime.datetime(2020, 5, 3)}), - ("list contains(a.b,'x')", True, {'a': {'b': ['a', 'x']}}), # combo - ("list contains(a.b,'c')", False, {'a': {'b': ['a', 'x']}}), ("list contains(a.keys(),'b')", True, {'a': {'b': ['a', 'x']}}), ("list contains(a.keys(),'c')", False, {'a': {'b': ['a', 'x']}}), ] diff --git a/tests/SpiffWorkflow/camunda/MultiInstanceDMNTest.py b/tests/SpiffWorkflow/camunda/MultiInstanceDMNTest.py index c7de85276..6fe5824f1 100644 --- a/tests/SpiffWorkflow/camunda/MultiInstanceDMNTest.py +++ b/tests/SpiffWorkflow/camunda/MultiInstanceDMNTest.py @@ -1,8 +1,6 @@ -import unittest - from SpiffWorkflow.bpmn.workflow import BpmnWorkflow from SpiffWorkflow.bpmn.PythonScriptEngine import PythonScriptEngine -from SpiffWorkflow.bpmn.PythonScriptEngineEnvironment import BoxedTaskDataEnvironment +from SpiffWorkflow.bpmn.PythonScriptEngineEnvironment import TaskDataEnvironment from .BaseTestCase import BaseTestCase @@ -12,7 +10,7 @@ def setUp(self): self.spec, subprocesses = self.load_workflow_spec( 'DMNMultiInstance.bpmn', 'Process_1', 'test_integer_decision_multi.dmn') self.workflow = BpmnWorkflow(self.spec) - self.script_engine = PythonScriptEngine(environment=BoxedTaskDataEnvironment()) + self.script_engine = PythonScriptEngine(environment=TaskDataEnvironment()) self.workflow.script_engine = self.script_engine def testDmnHappy(self): @@ -31,12 +29,3 @@ def testDmnSaveRestore(self): self.workflow.do_engine_steps() self.save_restore() self.assertEqual(self.workflow.data['stuff']['E']['y'], 'D') - - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(MultiInstanceDMNTest) - - -if __name__ == '__main__': - unittest.TextTestRunner(verbosity=2).run(suite()) diff --git a/tests/SpiffWorkflow/camunda/data/dmn/test_integer_decision_multi.dmn b/tests/SpiffWorkflow/camunda/data/dmn/test_integer_decision_multi.dmn index a24c84000..c168c4378 100644 --- a/tests/SpiffWorkflow/camunda/data/dmn/test_integer_decision_multi.dmn +++ b/tests/SpiffWorkflow/camunda/data/dmn/test_integer_decision_multi.dmn @@ -1,10 +1,10 @@ - + - item.x + item['x'] diff --git a/tests/SpiffWorkflow/dmn/feel_engine/FeelDictDecisionTest.py b/tests/SpiffWorkflow/dmn/feel_engine/FeelDictDecisionTest.py index 95c539c8e..115dc6380 100644 --- a/tests/SpiffWorkflow/dmn/feel_engine/FeelDictDecisionTest.py +++ b/tests/SpiffWorkflow/dmn/feel_engine/FeelDictDecisionTest.py @@ -1,7 +1,5 @@ import unittest -from SpiffWorkflow.bpmn.PythonScriptEngineEnvironment import Box - from .FeelDecisionRunner import FeelDecisionRunner @@ -19,7 +17,6 @@ def test_string_decision_string_output1(self): "PEANUTS": {"delicious": True}, "SPAM": {"delicious": False} }} - Box.convert_to_box(data) res = self.runner.decide(data) self.assertEqual(res.description, 'They are allergic to peanuts') diff --git a/tests/SpiffWorkflow/dmn/feel_engine/FeelDictDotNotationDecisionTest.py b/tests/SpiffWorkflow/dmn/feel_engine/FeelDictDotNotationDecisionTest.py deleted file mode 100644 index 6978fa9fe..000000000 --- a/tests/SpiffWorkflow/dmn/feel_engine/FeelDictDotNotationDecisionTest.py +++ /dev/null @@ -1,39 +0,0 @@ -import unittest - -from SpiffWorkflow.bpmn.PythonScriptEngineEnvironment import Box - -from .FeelDecisionRunner import FeelDecisionRunner - - -class FeelDictDotNotationDecisionTestClass(unittest.TestCase): - - @classmethod - def setUpClass(cls): - cls.runner = FeelDecisionRunner('dict_dot_notation_decision_feel.dmn') - - def test_string_decision_string_output1(self): - data = {"foods": { - "spam": {"delicious": False} - }} - res = self.runner.decide(Box(data)) - self.assertEqual(res.description, 'This person has a tongue, brain ' - 'or sense of smell.') - - data = {"foods": { - "spam": {"delicious": False} - }} - def test_string_decision_string_output2(self): - data = {"foods": { - "spam": {"delicious": True} - }} - res = self.runner.decide(Box(data)) - self.assertEqual(res.description, 'This person is lacking many ' - 'critical decision making skills, ' - 'or is a viking.') - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(FeelDictDotNotationDecisionTestClass) - -if __name__ == '__main__': - unittest.TextTestRunner(verbosity=2).run(suite()) diff --git a/tests/SpiffWorkflow/dmn/feel_engine/data/dict_dot_notation_decision_feel.dmn b/tests/SpiffWorkflow/dmn/feel_engine/data/dict_dot_notation_decision_feel.dmn deleted file mode 100644 index 81aca89f3..000000000 --- a/tests/SpiffWorkflow/dmn/feel_engine/data/dict_dot_notation_decision_feel.dmn +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - foods.spam.delicious - - - - - This person is lacking many critical decision making skills, or is a viking. - - mGender Description - True - - - "wrong" - - - - This person has a tongue, brain or sense of smell. - - False - - - "correct, spam is not delicious" - - - - - diff --git a/tests/SpiffWorkflow/dmn/python_engine/DictDotNotationDecisionTest.py b/tests/SpiffWorkflow/dmn/python_engine/DictDotNotationDecisionTest.py deleted file mode 100644 index a9e9e2d5b..000000000 --- a/tests/SpiffWorkflow/dmn/python_engine/DictDotNotationDecisionTest.py +++ /dev/null @@ -1,46 +0,0 @@ -import unittest - -from SpiffWorkflow.bpmn.PythonScriptEngineEnvironment import Box - -from .PythonDecisionRunner import PythonDecisionRunner - -class DictDotNotationDecisionTestClass(unittest.TestCase): - - @classmethod - def setUpClass(cls): - dmn_files =[ - 'dict_dot_notation_decision.dmn', - 'dict_dot_notation_decision_v1_3.dmn', - ] - cls.runners = [PythonDecisionRunner(d) for d in dmn_files] - - def test_string_decision_string_output1(self): - for runner in self.runners: - data = {"foods": { - "spam": {"delicious": False} - }} - data = Box(data) - res = runner.decide(data) - self.assertEqual(res.description, 'This person has a tongue, brain ' - 'or sense of smell.') - - data = Box({"foods": { - "spam": {"delicious": False} - }}) - - def test_string_decision_string_output2(self): - for runner in self.runners: - data = {"foods": { - "spam": {"delicious": True} - }} - res = runner.decide(Box(data)) - self.assertEqual(res.description, 'This person is lacking many ' - 'critical decision making skills, ' - 'or is a viking.') - - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase(DictDotNotationDecisionTestClass) - -if __name__ == '__main__': - unittest.TextTestRunner(verbosity=2).run(suite()) diff --git a/tests/SpiffWorkflow/dmn/python_engine/DictDotNotationDecisionWeirdCharactersTest.py b/tests/SpiffWorkflow/dmn/python_engine/DictDotNotationDecisionWeirdCharactersTest.py deleted file mode 100644 index df569ccd8..000000000 --- a/tests/SpiffWorkflow/dmn/python_engine/DictDotNotationDecisionWeirdCharactersTest.py +++ /dev/null @@ -1,36 +0,0 @@ -import unittest - -from SpiffWorkflow.bpmn.PythonScriptEngineEnvironment import Box - -from .PythonDecisionRunner import PythonDecisionRunner - - -class DictDotNotationDecisionWeirdCharactersTestClass(unittest.TestCase): - - @classmethod - def setUpClass(cls): - dmn_files =[ - 'dict_dot_notation_decision_weird_characters.dmn', - 'dict_dot_notation_decision_weird_characters_v1_3.dmn', - ] - cls.runners = [PythonDecisionRunner(d) for d in dmn_files] - - def test_string_decision_string_output1(self): - for runner in self.runners: - data = {"odd_foods": { - "SPAM_LIKE": {"delicious": False} - }} - res = runner.decide(Box(data)) - self.assertEqual(res.description, 'This person has a tongue, brain ' - 'or sense of smell.') - - data = {"foods": { - "spam": {"delicious": False} - }} - -def suite(): - return unittest.TestLoader().loadTestsFromTestCase( - DictDotNotationDecisionWeirdCharactersTestClass) - -if __name__ == '__main__': - unittest.TextTestRunner(verbosity=2).run(suite()) diff --git a/tests/SpiffWorkflow/dmn/python_engine/data/dict_dot_notation_decision.dmn b/tests/SpiffWorkflow/dmn/python_engine/data/dict_dot_notation_decision.dmn deleted file mode 100644 index 42e75fbf1..000000000 --- a/tests/SpiffWorkflow/dmn/python_engine/data/dict_dot_notation_decision.dmn +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - foods.spam.delicious - - - - - This person is lacking many critical decision making skills, or is a viking. - - mGender Description - True - - - "wrong" - - - - This person has a tongue, brain or sense of smell. - - False - - - "correct, spam is not delicious" - - - - - diff --git a/tests/SpiffWorkflow/dmn/python_engine/data/dict_dot_notation_decision_v1_3.dmn b/tests/SpiffWorkflow/dmn/python_engine/data/dict_dot_notation_decision_v1_3.dmn deleted file mode 100644 index 69da25695..000000000 --- a/tests/SpiffWorkflow/dmn/python_engine/data/dict_dot_notation_decision_v1_3.dmn +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - foods.spam.delicious - - - - - This person is lacking many critical decision making skills, or is a viking. - - mGender Description - True - - - "wrong" - - - - This person has a tongue, brain or sense of smell. - - False - - - "correct, spam is not delicious" - - - - - - - - - - - - diff --git a/tests/SpiffWorkflow/dmn/python_engine/data/dict_dot_notation_decision_weird_characters.dmn b/tests/SpiffWorkflow/dmn/python_engine/data/dict_dot_notation_decision_weird_characters.dmn deleted file mode 100644 index 3ebb9dc4e..000000000 --- a/tests/SpiffWorkflow/dmn/python_engine/data/dict_dot_notation_decision_weird_characters.dmn +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - odd_foods.SPAM_LIKE.delicious - - - - - This person is lacking many critical decision making skills, or is a viking. - - mGender Description - True - - - "wrong" - - - - This person has a tongue, brain or sense of smell. - - False - - - "correct, spam is not delicious" - - - - - diff --git a/tests/SpiffWorkflow/dmn/python_engine/data/dict_dot_notation_decision_weird_characters_v1_3.dmn b/tests/SpiffWorkflow/dmn/python_engine/data/dict_dot_notation_decision_weird_characters_v1_3.dmn deleted file mode 100644 index 864ea180a..000000000 --- a/tests/SpiffWorkflow/dmn/python_engine/data/dict_dot_notation_decision_weird_characters_v1_3.dmn +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - odd_foods.SPAM_LIKE.delicious - - - - - This person is lacking many critical decision making skills, or is a viking. - - mGender Description - True - - - "wrong" - - - - This person has a tongue, brain or sense of smell. - - False - - - "correct, spam is not delicious" - - - - - - - - - - - -