mockito-python icon indicating copy to clipboard operation
mockito-python copied to clipboard

InOrder Implementation

Open cMancio00 opened this issue 3 months ago • 2 comments

Hello @kaste, as we discussed in in issue #97 there isn't an implementation for InOrder. I would like to implement it but I need your opinion.

I think we should be able write something like this:

in_order: inOrder = inOrder(first_mock, second_mock)
in_order.verify(first_mock.a_method())
in_order.verify(second_mock.other_method())

The idea is to use the in_order object as a container to remember the invocations during the test of differents mocks using the methods already implemented in verify and the data structure of Mock that remembers the invocations.

What do you think?

cMancio00 avatar Sep 23 '25 12:09 cMancio00

in_order.verify(first_mock.a_method()) calls rv = first.method() and then calls in_order.verify(rv).

How do you want to implement that?

kaste avatar Sep 23 '25 13:09 kaste

in_order.verify(first_mock.a_method()) calls rv = first.method() and then calls in_order.verify(rv). I made a mistake, the call is the same as the actual verify

in_order.verify(first_mock).a_method()

I have extended the Mock to be Observable, so every time the invocations list gets updated it notifies the Observer i.e. the inOrder object. I wrote two tests, one with a correct order specification and one with the wrong specification. Both are green and all other tests too (6 tests are ignored even before my edits). This is just a poc for now since I have to think of more cases. I will open the PR just to let you know what I'm doing

Best Regards

cMancio00 avatar Sep 23 '25 22:09 cMancio00