mirror of
https://github.com/sartography/spiff-arena.git
synced 2025-01-28 18:24:58 +00:00
c237e218b2
0e61be85 Merge pull request #289 from sartography/improvement/execution-and-serialization-cleanup 527684da fix some typos in the class & method docs 0dff44a4 Merge branch 'main' into improvement/execution-and-serialization-cleanup 64737498 Allow for other PythonScriptEngine environments besides task data (#288) dd63e916 remove some unused tests & diagrams 24aae519 clean up various small stuff 3b2dc35d use context when opening files for parsing 69eec3eb update class/method docs 24528dfb move all spec conversion classes to top level 5af33b11 remove some unused methods related to old serializer 931b90fb reorganize serializer 4e81ed29 consolidate pointless serializer classes d62acf02 change task_spec._update_hook to return a boolean indicating whether the task is ready git-subtree-dir: SpiffWorkflow git-subtree-split: 0e61be85c47474a33037e6f398e64c96e02f13ad
78 lines
3.3 KiB
Python
78 lines
3.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
import unittest
|
|
|
|
from SpiffWorkflow.bpmn.FeelLikeScriptEngine import FeelLikeScriptEngine, FeelInterval
|
|
from SpiffWorkflow.bpmn.PythonScriptEngineEnvironment import BoxedTaskDataEnvironment
|
|
from tests.SpiffWorkflow.bpmn.BpmnWorkflowTestCase import BpmnWorkflowTestCase
|
|
import datetime
|
|
|
|
__author__ = 'matth'
|
|
|
|
|
|
class FeelExpressionTest(BpmnWorkflowTestCase):
|
|
|
|
def setUp(self):
|
|
self.expressionEngine = FeelLikeScriptEngine(environment=BoxedTaskDataEnvironment())
|
|
|
|
def testRunThroughExpressions(self):
|
|
tests = [("string length('abcd')", 4, {}),
|
|
("contains('abcXYZdef','XYZ')", True, {}),
|
|
("list contains(x,'b')", True, {'x': ['a', 'b', 'c']}),
|
|
("list contains(x,'z')", False, {'x': ['a', 'b', 'c']}),
|
|
# ("list contains(['a','b','c'],'b')",True,{}), # fails due to parse error
|
|
("all ([True,True,True])", True, {}),
|
|
("all ([True,False,True])", False, {}),
|
|
("any ([False,False,False])", False, {}),
|
|
("any ([True,False,True])", True, {}),
|
|
("PT3S", datetime.timedelta(seconds=3), {}),
|
|
("d[item>1]",[2,3,4],{'d':[1,2,3,4]}),
|
|
("d[x>=2].y",[2,3,4],{'d':[{'x':1,'y':1},
|
|
{'x': 2, 'y': 2},
|
|
{'x': 3, 'y': 3},
|
|
{'x': 4, 'y': 4},
|
|
]}),
|
|
("concatenate(a,b,c)", ['a', 'b', 'c'], {'a': ['a'],
|
|
'b': ['b'],
|
|
'c': ['c'],
|
|
}),
|
|
("append(a,'c')", ['a', 'b', 'c'], {'a': ['a', 'b']}),
|
|
("now()", FeelInterval(datetime.datetime.now() - datetime.timedelta(seconds=1),
|
|
datetime.datetime.now() + datetime.timedelta(seconds=1)),
|
|
{}),
|
|
("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']}}),
|
|
]
|
|
for test in tests:
|
|
self.assertEqual(self.expressionEngine._evaluate(test[0], test[2]),
|
|
test[1], "test --> %s <-- with variables ==> %s <==Fail!" % (test[0], str(test[2])))
|
|
|
|
def testRunThroughDMNExpression(self):
|
|
"""
|
|
Real world test
|
|
"""
|
|
data = {
|
|
"exclusive": [
|
|
{
|
|
"ExclusiveSpaceAMComputingID": None
|
|
}
|
|
]
|
|
}
|
|
x = self.expressionEngine._evaluate(
|
|
"""sum([1 for x in exclusive if x.get('ExclusiveSpaceAMComputingID',None)==None])""",
|
|
data
|
|
)
|
|
self.assertEqual(x, 1)
|
|
|
|
|
|
|
|
def suite():
|
|
return unittest.TestLoader().loadTestsFromTestCase(FeelExpressionTest)
|
|
|
|
if __name__ == '__main__':
|
|
unittest.TextTestRunner(verbosity=2).run(suite())
|