Giter Site home page Giter Site logo

Comments (3)

fgmacedo avatar fgmacedo commented on June 11, 2024 1

Hi @wawa19933 , thanks for reporting this and the extra care on the context and details. I've added pytest-mock as a dependency to the project to be able to reproduce.

from python-statemachine.

wawa19933 avatar wawa19933 commented on June 11, 2024

Here is a dirty workaround:

--- a/signature.py  2023-06-12 04:14:29.750363476 +0200
+++ b/signature.py  2023-06-12 04:14:43.009982670 +0200
@@ -15,6 +15,14 @@
         """Build a wrapper that adapts the received arguments to the inner ``method`` signature"""

         sig = cls.from_callable(method)
+        if not isinstance(sig, SignatureAdapter):
+            n = SignatureAdapter()
+            n._parameters = sig._parameters
+            n.__slots__ = sig.__slots__
+            n._parameter_cls = sig._parameter_cls
+            n._bound_arguments_cls = sig._bound_arguments_cls
+            n.empty = sig.empty
+            sig = n
         sig.method = method
         sig.__name__ = (
             method.func.__name__ if isinstance(method, partial) else method.__name__

from python-statemachine.

wawa19933 avatar wawa19933 commented on June 11, 2024

This doesn't affect underlying unittest.mock patch functions, though.

So, this example works:

    class Observer:
        def on_enter_state(self, event, model, source, target, state):
            ...

    obs = Observer()
    # on_enter_state = mocker.spy(obs, "on_enter_state")
    on_enter_state = mocker.patch.object(obs, "on_enter_state")

    class Machine(StateMachine):
        a = State("Init", initial=True)
        b = State("Fin")

        cycle = a.to(b) | b.to(a)

        def on_exit_state(self, source, target):
            assert source != target

    state = Machine().add_observer(obs)
    assert state.a.is_active

    state.cycle()

    assert state.b.is_active
    on_enter_state.assert_called_once()

from python-statemachine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.