Skip to content

Commit

Permalink
Merge pull request #360 from sartography/feature/remove-box
Browse files Browse the repository at this point in the history
remove Box and associated tests
  • Loading branch information
essweine authored Oct 25, 2023
2 parents f59ad47 + 2b1fd2c commit c9786c5
Show file tree
Hide file tree
Showing 14 changed files with 6 additions and 433 deletions.
80 changes: 0 additions & 80 deletions SpiffWorkflow/bpmn/PythonScriptEngineEnvironment.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
# 02110-1301 USA

import copy
import warnings


class BasePythonScriptEngineEnvironment:
Expand Down Expand Up @@ -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)

26 changes: 0 additions & 26 deletions tests/SpiffWorkflow/bpmn/BoxDeepCopyTest.py

This file was deleted.

7 changes: 2 additions & 5 deletions tests/SpiffWorkflow/bpmn/FeelExpressionEngineTest.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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, {}),
Expand Down Expand Up @@ -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']}}),
]
Expand Down
15 changes: 2 additions & 13 deletions tests/SpiffWorkflow/camunda/MultiInstanceDMNTest.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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):
Expand All @@ -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())
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="https://www.omg.org/spec/DMN/20191111/MODEL/" xmlns:camunda="http://camunda.org/schema/1.0/dmn" xmlns:biodi="http://bpmn.io/schema/dmn/biodi/2.0" id="definitions_1jblnbx" name="definitions" namespace="http://camunda.org/schema/1.0/dmn" exporter="Camunda Modeler" exporterVersion="5.0.0">
<definitions xmlns="https://www.omg.org/spec/DMN/20191111/MODEL/" xmlns:camunda="http://camunda.org/schema/1.0/dmn" xmlns:biodi="http://bpmn.io/schema/dmn/biodi/2.0" id="definitions_1jblnbx" name="definitions" namespace="http://camunda.org/schema/1.0/dmn" exporter="Camunda Modeler" exporterVersion="4.11.1">
<decision id="IntegerDecisionStringOutputTable" name="IntegerDecisionStringOutput">
<decisionTable id="decisionTable">
<input id="InputClause_1tm0ceq" label="x" biodi:width="192" camunda:inputVariable="">
<inputExpression id="LiteralExpression_04o7chw" typeRef="integer">
<text>item.x</text>
<text>item['x']</text>
</inputExpression>
</input>
<output id="output1" label="They Label Y" name="item.y" typeRef="string" />
Expand Down
3 changes: 0 additions & 3 deletions tests/SpiffWorkflow/dmn/feel_engine/FeelDictDecisionTest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import unittest

from SpiffWorkflow.bpmn.PythonScriptEngineEnvironment import Box

from .FeelDecisionRunner import FeelDecisionRunner


Expand All @@ -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')

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit c9786c5

Please sign in to comment.