One function

mock in kaste/mockito-python

The author described this change as Fix: support `mock(spec=SomeClass)` usage. It counts as a record because the check below fails on the code as it stood at f2a0d3548 and passes on 519c9c49e, with nothing else changed between the two runs.

Fix saved2022-06-14
Sharing licenceMIT · LICENSE
Change size+2 3

What the code was meant to do, written into the code itself as a docstring

Create 'empty' objects ('Mocks'). Will create an empty unconfigured object, that you can pass around. All interactions (method calls) will be recorded and can be verified using :func:`verify` et.al. A plain `mock()` will be not `strict`, and thus all methods regardless of the arguments will return `None`. .. note:: Technically all attributes will return an internal interface. Because of that a simple `if mock().foo:` will surprisingly pass. If you set strict to `True`: `mock(strict=True)` all unexpected interactions will raise an error instead. You configure a mock using :func:`when`, :func:`when2` or :func:`expect`. You can also very conveniently just pass in a dict here:: response = mock({'text': 'ok', 'raise_for_status': lambda: None}) You can also create an empty Mock which is specced against a given `spec`: `mock(requests.Response)`. These mock are by default strict, thus they raise if you want to stub a method, the spec does not implement. Mockito will also match the function signature. You can pre-configure a specced mock as well:: response = mock({'json': lambda: {'status': 'Ok'}}, spec=requests.Response) Mocks are by default callable. Configure the callable behavior using `when`:: dummy = mock() when(dummy).__call__(1).thenReturn(2) All other magic methods must be configured this way or they will raise an AttributeError. See :func:`verify` to verify your interactions after usage.

The change

4444 """
4545
4646 if type(config_or_spec) is dict:
47- config = config_or_spec
47+ config, spec = config_or_spec, spec
4848 else:
49- config = {}
50- spec = config_or_spec
49+ config, spec = {}, spec or config_or_spec
5150
5251 if strict is OMITTED:
5352 strict = False if spec is None else True

The check that tells the two apart

failpass·tests/speccing_test.py::TestSpeccing::testShouldPassIsInstanceChecks_2

Check file tests/speccing_test.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before itf2a0d3548d7b92ee8b7618579c5da9926fd1c0f0
Broken version dated2022-06-14
Modulemockito.mocking
Units changedmock
Fingerprint5838631ed190aad6
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in kaste/mockito-python