122 lines
2.9 KiB
Python
122 lines
2.9 KiB
Python
|
|
#!/usr/bin/env python
|
||
|
|
|
||
|
|
import defl
|
||
|
|
from defl import Assert, cl, log
|
||
|
|
from defl._action_ import Action
|
||
|
|
from defl.testing_ import Test, Tester, TestState
|
||
|
|
|
||
|
|
tester = Tester(name=__file__)
|
||
|
|
|
||
|
|
|
||
|
|
def pipe(out=False, err=False):
|
||
|
|
return dict(pipe=(out, err))
|
||
|
|
|
||
|
|
|
||
|
|
def func(*args, **kargs):
|
||
|
|
return (args, kargs)
|
||
|
|
|
||
|
|
|
||
|
|
@tester.add()
|
||
|
|
def retTrue():
|
||
|
|
# | dict(raiseOnFail=True, logOnRun=log.debug) | pipe()
|
||
|
|
Assert(Action.Register(func, 1, 2, a=3, b=4)()).eq(((1, 2), {'a': 3, 'b': 4}))
|
||
|
|
|
||
|
|
|
||
|
|
@tester.add()
|
||
|
|
def retTrue():
|
||
|
|
# | dict(raiseOnFail=True, logOnRun=log.debug) | pipe()
|
||
|
|
Assert(Action.Register(func, 1, 2, a=3, b=4) @ Action.Execute).eq(((1, 2), {'a': 3, 'b': 4}))
|
||
|
|
|
||
|
|
|
||
|
|
@tester.add()
|
||
|
|
def retTrue():
|
||
|
|
# | dict(raiseOnFail=True, logOnRun=log.debug) | pipe()
|
||
|
|
a = Action.Register(func)
|
||
|
|
|
||
|
|
Assert(a.func).eq(func)
|
||
|
|
Assert(a.args).eq([])
|
||
|
|
Assert(a.kargs).eq({})
|
||
|
|
Assert(a.encloseExcept).eq(False)
|
||
|
|
Assert(a.log).eq(False)
|
||
|
|
Assert(a._result).eq(defl._action_.ActionNotRun)
|
||
|
|
Assert(a.metadata).eq({})
|
||
|
|
|
||
|
|
|
||
|
|
@tester.add()
|
||
|
|
def retTrue():
|
||
|
|
a = Action.Register(func, 1, 2, 3, 4, a=5, b=6, c=7)
|
||
|
|
res = {
|
||
|
|
"func": func,
|
||
|
|
"args": [1, 2, 3, 4],
|
||
|
|
"kargs": dict(a=5, b=6, c=7),
|
||
|
|
"encloseExcept": False,
|
||
|
|
"log": False,
|
||
|
|
"_result": defl._action_.ActionNotRun,
|
||
|
|
"metadata": {},
|
||
|
|
}
|
||
|
|
[Assert(getattr(a, k)).eq(v) for k, v in res.items()]
|
||
|
|
|
||
|
|
|
||
|
|
@tester.add()
|
||
|
|
def retTrue():
|
||
|
|
a = Action.Register(func)
|
||
|
|
|
||
|
|
b = a / 1
|
||
|
|
|
||
|
|
res = {
|
||
|
|
"func": func,
|
||
|
|
"args": [1],
|
||
|
|
"kargs": {},
|
||
|
|
"encloseExcept": False,
|
||
|
|
"log": False,
|
||
|
|
"_result": defl._action_.ActionNotRun,
|
||
|
|
"metadata": {},
|
||
|
|
}
|
||
|
|
[Assert(getattr(b, k)).eq(v) for k, v in res.items()]
|
||
|
|
|
||
|
|
Assert(id(a)).ne(id(b))
|
||
|
|
|
||
|
|
b = b / 2 / 3 / 4
|
||
|
|
res['args'] = [1, 2, 3, 4]
|
||
|
|
|
||
|
|
[Assert(getattr(b, k)).eq(v) for k, v in res.items()]
|
||
|
|
|
||
|
|
b = b // 5
|
||
|
|
res['args'] = [5]
|
||
|
|
|
||
|
|
[Assert(getattr(b, k)).eq(v) for k, v in res.items()]
|
||
|
|
|
||
|
|
b = b * dict(a=1, b=2)
|
||
|
|
res['kargs'] = dict(a=1, b=2)
|
||
|
|
[Assert(getattr(b, k)).eq(v) for k, v in res.items()]
|
||
|
|
|
||
|
|
b = b * dict(c=3, d=4)
|
||
|
|
res['kargs'] = dict(a=1, b=2, c=3, d=4)
|
||
|
|
[Assert(getattr(b, k)).eq(v) for k, v in res.items()]
|
||
|
|
|
||
|
|
b = b ** dict(a=3, d=4)
|
||
|
|
res['kargs'] = dict(a=3, d=4)
|
||
|
|
[Assert(getattr(b, k)).eq(v) for k, v in res.items()]
|
||
|
|
|
||
|
|
b = b ** [9, 8, 7]
|
||
|
|
res['args'] = [9, 8, 7]
|
||
|
|
[Assert(getattr(b, k)).eq(v) for k, v in res.items()]
|
||
|
|
|
||
|
|
b = b * (9, 8, 7)
|
||
|
|
res['args'] = [9, 8, 7] * 2
|
||
|
|
[Assert(getattr(b, k)).eq(v) for k, v in res.items()]
|
||
|
|
|
||
|
|
b = b ** []
|
||
|
|
|
||
|
|
Assert(b.execute()).eq(((), {'a': 3, 'd': 4}))
|
||
|
|
|
||
|
|
|
||
|
|
log.info(tester.run())
|
||
|
|
tester.exitWithStatus()
|
||
|
|
|
||
|
|
# print('=============================')
|
||
|
|
# print('getObjAsDict(_)', jdumps(getObjAsDict(_)))
|
||
|
|
# print('kargs', jdumps(kargs))
|
||
|
|
# print('getObjAsDict(_) | kargs', jdumps(getObjAsDict(_) | kargs))
|
||
|
|
# print('=============================')
|