|
|
@@ -0,0 +1,54 @@
|
|
|
+import pytest
|
|
|
+import unittest.mock
|
|
|
+
|
|
|
+import cipy
|
|
|
+import cipy.action
|
|
|
+
|
|
|
+
|
|
|
+class NoOp(cipy.action.Action):
|
|
|
+ def run(self, context: cipy.Context) -> cipy.Status:
|
|
|
+ return cipy.Status.NOT_RUN
|
|
|
+
|
|
|
+
|
|
|
+def mock_action(*, name: str = "Mock", id: str = "") -> unittest.mock.MagicMock:
|
|
|
+ rval = unittest.mock.MagicMock(
|
|
|
+ wraps=NoOp(name=name, id=id), spec=cipy.action.Action
|
|
|
+ )
|
|
|
+ rval.name = name
|
|
|
+ rval.id = id
|
|
|
+ rval.inputs = cipy.Inputs()
|
|
|
+ rval.outputs = cipy.Outputs()
|
|
|
+ return rval
|
|
|
+
|
|
|
+
|
|
|
+def test_action() -> None:
|
|
|
+ action = NoOp(name="Stub")
|
|
|
+ assert action.run(cipy.Context()) is cipy.Status.NOT_RUN
|
|
|
+
|
|
|
+
|
|
|
+def test_call_proxies_functions() -> None:
|
|
|
+ action = mock_action()
|
|
|
+ call = cipy.Call(action)
|
|
|
+
|
|
|
+ call.is_enabled(cipy.Status.NOT_RUN, cipy.Context())
|
|
|
+ action.is_enabled.assert_called_once()
|
|
|
+
|
|
|
+ call.run(cipy.Context())
|
|
|
+ action.run.assert_called_once()
|
|
|
+
|
|
|
+ call.cleanup(cipy.Context())
|
|
|
+ action.cleanup.assert_called_once()
|
|
|
+
|
|
|
+
|
|
|
+def test_call_can_pass_args() -> None:
|
|
|
+ class Inputs(cipy.Inputs):
|
|
|
+ foo: int = cipy.required()
|
|
|
+
|
|
|
+ action = mock_action()
|
|
|
+ action.inputs = Inputs()
|
|
|
+ call = cipy.Call(action, foo=3)
|
|
|
+
|
|
|
+ call.run(cipy.Context())
|
|
|
+
|
|
|
+ action.run.assert_called_once()
|
|
|
+ assert action.inputs.foo == 3
|