decoy 2.2.2__py3-none-any.whl → 2.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
decoy/matchers.py CHANGED
@@ -28,16 +28,17 @@ See the [matchers guide][] for more details.
28
28
  """
29
29
 
30
30
  from re import compile as compile_re
31
- from typing import Any, List, Mapping, Optional, Pattern, Type, TypeVar, cast
32
-
33
- __all__ = [
34
- "Anything",
35
- "Captor",
36
- "ErrorMatching",
37
- "IsA",
38
- "IsNot",
39
- "StringMatching",
40
- ]
31
+ from typing import (
32
+ Any,
33
+ Generic,
34
+ List,
35
+ Mapping,
36
+ Optional,
37
+ Pattern,
38
+ Type,
39
+ TypeVar,
40
+ cast,
41
+ )
41
42
 
42
43
 
43
44
  class _AnythingOrNone:
@@ -361,12 +362,32 @@ def ErrorMatching(error: Type[ErrorT], match: Optional[str] = None) -> ErrorT:
361
362
  return cast(ErrorT, _ErrorMatching(error, match))
362
363
 
363
364
 
364
- class _Captor:
365
+ CapturedT = TypeVar("CapturedT")
366
+
367
+
368
+ class ValueCaptor(Generic[CapturedT]):
369
+ """Match anything, capturing its value for further assertions.
370
+
371
+ Compare against the `matcher` property to capture a value.
372
+ The last captured value is available via `captor.value`,
373
+ while all captured values are stored in `captor.values`.
374
+
375
+ !!! example
376
+ ```python
377
+ captor = ValueCaptor[str]()
378
+ assert "foobar" == captor.matcher
379
+ print(captor.value) # "foobar"
380
+ print(captor.values) # ["foobar"]
381
+ ```
382
+ """
383
+
384
+ _values: List[object]
385
+
365
386
  def __init__(self) -> None:
366
- self._values: List[Any] = []
387
+ self._values = []
367
388
 
368
389
  def __eq__(self, target: object) -> bool:
369
- """Capture compared value, always returning True."""
390
+ """Captors are always "equal" to a given target."""
370
391
  self._values.append(target)
371
392
  return True
372
393
 
@@ -375,11 +396,19 @@ class _Captor:
375
396
  return "<Captor>"
376
397
 
377
398
  @property
378
- def value(self) -> Any:
379
- """Get the captured value.
399
+ def matcher(self) -> CapturedT:
400
+ """Match anything, capturing its value.
401
+
402
+ This method exists as a type-checking convenience.
403
+ """
404
+ return cast(CapturedT, self)
405
+
406
+ @property
407
+ def value(self) -> object:
408
+ """The latest captured value.
380
409
 
381
410
  Raises:
382
- AssertionError: if no value was captured.
411
+ AssertionError: no value has been captured.
383
412
  """
384
413
  if len(self._values) == 0:
385
414
  raise AssertionError("No value captured by captor.")
@@ -387,24 +416,15 @@ class _Captor:
387
416
  return self._values[-1]
388
417
 
389
418
  @property
390
- def values(self) -> List[Any]:
391
- """Get all captured values."""
419
+ def values(self) -> List[object]:
420
+ """All captured values."""
392
421
  return self._values
393
422
 
394
423
 
395
424
  def Captor() -> Any:
396
- """Match anything, capturing its value.
397
-
398
- The last captured value will be set to `captor.value`. All captured
399
- values will be placed in the `captor.values` list, which can be
400
- helpful if a captor needs to be triggered multiple times.
425
+ """Match anything, capturing its value for further assertions.
401
426
 
402
- !!! example
403
- ```python
404
- captor = Captor()
405
- assert "foobar" == captor
406
- print(captor.value) # "foobar"
407
- print(captor.values) # ["foobar"]
408
- ```
427
+ !!! tip
428
+ Prefer [decoy.matchers.ValueCaptor][], which has better type annotations.
409
429
  """
410
- return _Captor()
430
+ return ValueCaptor()
@@ -1,18 +1,17 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: decoy
3
- Version: 2.2.2
3
+ Version: 2.3.0
4
4
  Summary: Opinionated mocking library for Python
5
- License-Expression: MIT
6
- License-File: LICENSE
7
5
  Author: Michael Cousins
8
- Author-email: michael@cousins.io>
9
- Requires-Python: >=3.7
6
+ Author-email: Michael Cousins <michael@cousins.io>>
7
+ License-Expression: MIT
10
8
  Classifier: Development Status :: 5 - Production/Stable
11
9
  Classifier: Intended Audience :: Developers
12
10
  Classifier: Operating System :: OS Independent
13
11
  Classifier: Topic :: Software Development :: Testing
14
12
  Classifier: Topic :: Software Development :: Testing :: Mocking
15
13
  Classifier: Typing :: Typed
14
+ Requires-Python: >=3.7
16
15
  Project-URL: Changelog, https://github.com/mcous/decoy/releases
17
16
  Project-URL: Documentation, https://michael.cousins.io/decoy/
18
17
  Project-URL: Homepage, https://michael.cousins.io/decoy/
@@ -30,7 +29,7 @@ Description-Content-Type: text/markdown
30
29
  <a title="Code Coverage" href="https://app.codecov.io/gh/mcous/decoy/"><img src="https://img.shields.io/codecov/c/github/mcous/decoy?style=flat-square"></a>
31
30
  <a title="License" href="https://github.com/mcous/decoy/blob/main/LICENSE"><img src="https://img.shields.io/github/license/mcous/decoy?style=flat-square"></a>
32
31
  <a title="PyPI Version"href="https://pypi.org/project/decoy/"><img src="https://img.shields.io/pypi/v/decoy?style=flat-square"></a>
33
- <a title="Supported Python Versions" href="https://pypi.org/project/decoy/"><img src="https://img.shields.io/pypi/pyversions/decoy?style=flat-square"></a>
32
+ <a title="Supported Python Versions" href="https://pypi.org/project/decoy/"><img src="https://img.shields.io/python/required-version-toml?style=flat-square&tomlFilePath=https%3A%2F%2Fraw.githubusercontent.com%2Fmcous%2Fdecoy%2Fmain%2Fpyproject.toml"></a>
34
33
  </p>
35
34
  <p>
36
35
  <a href="https://michael.cousins.io/decoy/" class="decoy-hidden">Usage guide and documentation</a>
@@ -44,14 +43,7 @@ Decoy mocks are **async/await** and **type-checking** friendly. Decoy is heavily
44
43
  ## Install
45
44
 
46
45
  ```bash
47
- # pip
48
46
  pip install decoy
49
-
50
- # poetry
51
- poetry add --dev decoy
52
-
53
- # pipenv
54
- pipenv install --dev decoy
55
47
  ```
56
48
 
57
49
  ## Setup
@@ -171,4 +163,3 @@ See [spying with verify][] for more details.
171
163
  [creating mocks]: https://michael.cousins.io/decoy/usage/create/
172
164
  [stubbing with when]: https://michael.cousins.io/decoy/usage/when/
173
165
  [spying with verify]: https://michael.cousins.io/decoy/usage/verify/
174
-
@@ -3,7 +3,7 @@ decoy/call_handler.py,sha256=fuhWr9VAnh0FUvbfWw11fpdQ_GCUE3Hah-EXvdk3gGw,1512
3
3
  decoy/context_managers.py,sha256=oYsH99ZPmkaCcqjCrOWInueO5ympHm_ICWmbpFoQzqA,1287
4
4
  decoy/core.py,sha256=0YsQFnL4Kw_oDX7jRgOVLw9BGsnNdekymQCd1aq-4sQ,5830
5
5
  decoy/errors.py,sha256=mmUAOoQQyXhCLjMcf_3bHMz3PjU7bingIU6sC3hk2B4,3119
6
- decoy/matchers.py,sha256=TFa3ZLewXPxhuUy_YDktzJWMfdOgfz4jq2TQ9oa6hwk,11298
6
+ decoy/matchers.py,sha256=2zO0F4tbxvLeRlm9BMIAQr_nxX5PBKA4CRJ5Hy5eukU,11724
7
7
  decoy/mypy/__init__.py,sha256=GdJCf-gXpYB4SBr-Rm8zCLZQxAUuLjPyUieIWgLmdwA,86
8
8
  decoy/mypy/plugin.py,sha256=nCfo4XpDxBRDsInDsvCe6h8t7-1OV0ZCJzIJqTsAU0I,1359
9
9
  decoy/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -18,8 +18,7 @@ decoy/types.py,sha256=LXzky6T0RXvS53NoPpVgCi3KVV6KCyB6EvnBl0NaKug,404
18
18
  decoy/verifier.py,sha256=3ZVqaUJPjaNM9Nue3FK6Zzj15qWskX2CEQXoe_yjUEs,1586
19
19
  decoy/warning_checker.py,sha256=OOkcrr_I98Pzs3o9UUNgaihJDHwNiu1LlcEK9hi5ZFs,3577
20
20
  decoy/warnings.py,sha256=DLdX1ABPk6QvhJWt5s98uR7rCQFQdJJjSPPXRSX0nXA,3203
21
- decoy-2.2.2.dist-info/METADATA,sha256=hKPZiHbc6RDbYOJ9iwIZ0wvRhrOn3UYxPSCAqABg9Tc,6855
22
- decoy-2.2.2.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
23
- decoy-2.2.2.dist-info/entry_points.txt,sha256=P2wF8zdthEM-3Yo32kxHDhZDjbW6AE489HPWqnvPLOU,38
24
- decoy-2.2.2.dist-info/licenses/LICENSE,sha256=Rxi19kHgqakAsJNG1jMuORmgKx9bI8Pcu_gtzFkhflQ,1078
25
- decoy-2.2.2.dist-info/RECORD,,
21
+ decoy-2.3.0.dist-info/WHEEL,sha256=KSLUh82mDPEPk0Bx0ScXlWL64bc8KmzIPNcpQZFV-6E,79
22
+ decoy-2.3.0.dist-info/entry_points.txt,sha256=En3V0KZt-83nTeWFpVB5KTotgxuUETePl7HesB81W64,40
23
+ decoy-2.3.0.dist-info/METADATA,sha256=3QTINwIfutMyuMNSY0m7TFMHA8Kt5Bl-ijDIqD1I7jA,6874
24
+ decoy-2.3.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: uv 0.9.22
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,3 @@
1
+ [pytest11]
2
+ decoy = decoy.pytest_plugin
3
+
@@ -1,4 +0,0 @@
1
- Wheel-Version: 1.0
2
- Generator: poetry-core 2.2.1
3
- Root-Is-Purelib: true
4
- Tag: py3-none-any
@@ -1,3 +0,0 @@
1
- [pytest11]
2
- decoy=decoy.pytest_plugin
3
-
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2020-2023, Michael Cousins
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.