Пример #1
0
 def test_get_prepared_action_twice(monkeypatch):
     monkeypatch.setattr(InfoStreamer, "send_info", MagicMock())
     monkeypatch.setattr(StatefullAction, "_check_kwargs_for_action",
                         MagicMock())
     monkeypatch.setattr(StatefullAction, "add_context_manager",
                         MagicMock())
     action = StatefullAction(["input"], lambda state: state["input"])
     prepared = action.get_prepared_action(input=20)
     prepared2 = action.get_prepared_action(input=30)
     assert prepared.do() == 20
     assert prepared2.do() == 30
Пример #2
0
 def test_get_prepared_action_add_context_manager(monkeypatch):
     monkeypatch.setattr(InfoStreamer, "send_info", MagicMock())
     monkeypatch.setattr(StatefullAction, "_check_kwargs_for_action",
                         MagicMock())
     action = StatefullAction(["input"], lambda state: 10)
     prepared = action.get_prepared_action(input=20)
     context_manager_mock = MagicMock()
     prepared.add_context_manager("action", context_manager_mock)
     prepared2 = action.get_prepared_action(input=20)
     context_manager_mock2 = MagicMock()
     prepared2.add_context_manager("action", context_manager_mock2)
     prepared.do()
     assert context_manager_mock.called and not context_manager_mock2.called
     prepared2.do()
     assert context_manager_mock.call_count == 1 and context_manager_mock2.called
Пример #3
0
 def test_notify_no_rollback(monkeypatch):
     notify_mock = MagicMock()
     monkeypatch.setattr(Action, "notify", notify_mock)
     act = StatefullAction([], lambda state: 10)
     prep = act.get_prepared_action()
     prep.notify("rollback", "begin")
     assert not notify_mock.called
Пример #4
0
 def test_get_prepared_action_already_prepared(monkeypatch):
     monkeypatch.setattr(InfoStreamer, "send_info", MagicMock())
     monkeypatch.setattr(StatefullAction, "_check_kwargs_for_action",
                         MagicMock())
     monkeypatch.setattr(StatefullAction, "add_context_manager",
                         MagicMock())
     action = StatefullAction(["input"], lambda state: state["input"])
     prepared = action.get_prepared_action(input=10)
     with pytest.raises(ActionException):
         prepared.get_prepared_action()
Пример #5
0
 def test_get_prepared_action_change_name(monkeypatch):
     monkeypatch.setattr(InfoStreamer, "send_info", MagicMock())
     monkeypatch.setattr(StatefullAction, "_check_kwargs_for_action",
                         MagicMock())
     monkeypatch.setattr(StatefullAction, "add_context_manager",
                         MagicMock())
     action = StatefullAction(["input"], lambda state: 10, name="base_name")
     prepared = action.get_prepared_action(input=20)
     prepared.name = "prepared_action_name"
     assert action.name == "base_name"
     assert prepared.name == "prepared_action_name"
Пример #6
0
 def test_get_prepared_action_no_action():
     action = StatefullAction()
     with pytest.raises(ActionException):
         action.get_prepared_action()