panda-pytest-assertions 0.1.0__tar.gz → 0.2.0__tar.gz

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.
Files changed (68) hide show
  1. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/PKG-INFO +1 -1
  2. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_context/__init__.py +2 -1
  3. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_context/_assert_context.py +50 -19
  4. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/_converters/expectation_from_yaml.py +1 -1
  5. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/pyproject.toml +8 -8
  6. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/LICENSE +0 -0
  7. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/README.md +0 -0
  8. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/__init__.py +0 -0
  9. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/__init__.py +0 -0
  10. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/_assert_object.py +0 -0
  11. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/_asserter_factories/__init__.py +0 -0
  12. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/_asserter_factories/asserter_factory.py +0 -0
  13. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/_asserter_factories/built_in_asserter_factory.py +0 -0
  14. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/_converters/__init__.py +0 -0
  15. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/_converters/expectation_to_yaml.py +0 -0
  16. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/_expectation_modificators/__init__.py +0 -0
  17. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/_expectation_modificators/mapping_subset.py +0 -0
  18. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/_expectation_modificators/object_attibutes.py +0 -0
  19. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/_expectation_modificators/stringified.py +0 -0
  20. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/_expectation_modificators/unordered.py +0 -0
  21. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/_expectation_modificators/with_type.py +0 -0
  22. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/_objects_asserters/__init__.py +0 -0
  23. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/_objects_asserters/asserter.py +0 -0
  24. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/_objects_asserters/equality_asserter.py +0 -0
  25. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/_objects_asserters/mapping_asserter.py +0 -0
  26. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/_objects_asserters/mapping_subset_asserter.py +0 -0
  27. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/_objects_asserters/object_attributes_asserter.py +0 -0
  28. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/_objects_asserters/ordered_elements_asserter.py +0 -0
  29. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/_objects_asserters/stringified_asserter.py +0 -0
  30. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/_objects_asserters/unordered_elements_asserter.py +0 -0
  31. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/_objects_asserters/with_type_asserter.py +0 -0
  32. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/_protocols.py +0 -0
  33. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/__init__.py +0 -0
  34. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_expectation_definitions/__init__.py +0 -0
  35. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_expectation_definitions/equality.py +0 -0
  36. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_expectation_definitions/mapping.py +0 -0
  37. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_expectation_definitions/mapping_subset.py +0 -0
  38. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_expectation_definitions/object_attributes.py +0 -0
  39. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_expectation_definitions/of_type.py +0 -0
  40. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_expectation_definitions/stringified.py +0 -0
  41. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_expectation_definitions/uniform_mapping.py +0 -0
  42. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_expectation_definitions/uniform_mapping_subset.py +0 -0
  43. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_expectation_definitions/uniform_ordered.py +0 -0
  44. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_expectation_definitions/uniform_unordered.py +0 -0
  45. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_expectation_definitions/union.py +0 -0
  46. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_expectation_definitions/with_type.py +0 -0
  47. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_generate_expectation.py +0 -0
  48. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_generator_factories/__init__.py +0 -0
  49. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_generator_factories/built_in_generator_factory.py +0 -0
  50. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_generator_factories/generator_factory.py +0 -0
  51. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_generators/__init__.py +0 -0
  52. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_generators/equality_generator.py +0 -0
  53. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_generators/equality_key_mapping_generator.py +0 -0
  54. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_generators/exceptions.py +0 -0
  55. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_generators/generator.py +0 -0
  56. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_generators/mapping_generator.py +0 -0
  57. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_generators/mapping_subset_generator.py +0 -0
  58. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_generators/object_attributes_generator.py +0 -0
  59. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_generators/of_type_generator.py +0 -0
  60. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_generators/ordered_generator.py +0 -0
  61. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_generators/stringified_generator.py +0 -0
  62. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_generators/uniform_mapping_generator.py +0 -0
  63. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_generators/uniform_mapping_subset_generator.py +0 -0
  64. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_generators/uniform_ordered_generator.py +0 -0
  65. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_generators/union_generator.py +0 -0
  66. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_generators/unordered_generator.py +0 -0
  67. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/assert_object/generators/_generators/with_type_generator.py +0 -0
  68. {panda_pytest_assertions-0.1.0 → panda_pytest_assertions-0.2.0}/panda_pytest_assertions/py.typed +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: panda-pytest-assertions
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: Complex assertions that can be used when writing test with pytest
5
5
  Home-page: https://github.com/KRunchPL/panda-pytest-assertions
6
6
  License: Apache-2.0
@@ -6,10 +6,11 @@ pytest.register_assert_rewrite(__name__ + '._assert_context')
6
6
  # isort: on
7
7
 
8
8
 
9
- from ._assert_context import assert_context, AssertContext
9
+ from ._assert_context import assert_context, AssertContext, ExceptionMatch
10
10
 
11
11
 
12
12
  __all__ = [
13
13
  'assert_context',
14
14
  'AssertContext',
15
+ 'ExceptionMatch',
15
16
  ]
@@ -1,6 +1,6 @@
1
1
  from collections.abc import Generator
2
2
  from contextlib import contextmanager, ExitStack, nullcontext
3
- from typing import Any, overload
3
+ from typing import Any, NamedTuple, overload
4
4
 
5
5
  import pytest
6
6
 
@@ -32,18 +32,29 @@ class AssertContext:
32
32
  assert expected_result == self._result
33
33
 
34
34
 
35
+ class ExceptionMatch(NamedTuple):
36
+ #: type of expected exception
37
+ type_: type[BaseException]
38
+ #: match parameter passed to pytest.raises
39
+ match_: str
40
+
41
+
35
42
  @overload
36
43
  @contextmanager
37
44
  def assert_context( # noqa: D418
38
45
  *,
39
- exception: type[Exception] | _Unset = ...,
46
+ exception: type[BaseException] | ExceptionMatch | None | _Unset = ...,
40
47
  result: Any | _Unset = ..., # noqa: ANN401
41
48
  ) -> Generator[AssertContext, None, None]:
42
49
  """
43
50
  Context manager that makes sure `with` block behaved according to the arguments.
44
51
 
45
- If the `exception` parameter is set, the `with` block is expected to raise an exception of provided type.
46
- If it is NOT set, the `with` block is expected NOT TO raise any exceptions.
52
+ If the `exception` parameter is set to exception type, the `with` block is expected to raise an exception
53
+ of provided type. If the `exception` parameter is set to an instance of `ExceptionMatch` class, the `with`
54
+ block is expected to raise an exception of type specified in `type_` field and the value that matches the
55
+ string specified in `match_` field. For exact matching logic see `match` parameter of the `pytest.raises`.
56
+ If the `exception` parameter is NOT set or is set to `None`, the `with` block is expected NOT TO raise
57
+ any exceptions.
47
58
 
48
59
  If the `result` parameter is set, its value is expected to be equal to `with` block result. The `with`
49
60
  block result is set with the `set` method of an object yielded by the context manager. The comparison
@@ -51,7 +62,7 @@ def assert_context( # noqa: D418
51
62
  If the `result` parameter is NOT set, the `set` method of yielded object is expected
52
63
  not to be called at all.
53
64
 
54
- :param exception: type of exception, expected to be raised
65
+ :param exception: specification of exception, expected to be raised
55
66
  :param result: value expected to be set with `set` method of yielded object
56
67
  """
57
68
 
@@ -60,7 +71,7 @@ def assert_context( # noqa: D418
60
71
  @contextmanager
61
72
  def assert_context( # noqa: D418
62
73
  *,
63
- behaviour: type[Exception] | Any | _Unset = ..., # noqa: ANN401
74
+ behaviour: type[BaseException] | ExceptionMatch | Any | _Unset = ..., # noqa: ANN401
64
75
  ) -> Generator[AssertContext, None, None]:
65
76
  """
66
77
  Context manager that makes sure `with` block behaved according to the arguments.
@@ -68,9 +79,11 @@ def assert_context( # noqa: D418
68
79
  Context manager yields a single object used that provides `set` method used to set the `with`
69
80
  block result that is to be asserted.
70
81
 
71
- If the `behaviour` parameter is set to an exception type, the `with` block is expected
72
- to raise an exception of provided type and the `set` method of yielded object is expected
73
- not to be called at all.
82
+ If the `behaviour` parameter is set to exception type, the `with` block is expected to raise an exception
83
+ of provided type. If the `behaviour` parameter is set to an instance of `ExceptionMatch` class, the `with`
84
+ block is expected to raise an exception of type specified in `type_` field and the value that matches the
85
+ string specified in `match_` field. For exact matching logic see `match` parameter of the `pytest.raises`.
86
+ In both cases the `set` method of yielded object is expected not to be called at all.
74
87
 
75
88
  If the `behaviour` parameter is set to anything else, its value is expected to be equal to `with`
76
89
  block result. The comparison is used with `==` operator, where `result` argument is on the left side and
@@ -86,20 +99,24 @@ def assert_context( # noqa: D418
86
99
  @contextmanager
87
100
  def assert_context(
88
101
  *,
89
- exception: type[Exception] | _Unset = _UNSET,
102
+ exception: type[BaseException] | ExceptionMatch | None | _Unset = _UNSET,
90
103
  result: Any | _Unset = _UNSET,
91
- behaviour: type[Exception] | Any | _Unset = _UNSET,
104
+ behaviour: type[BaseException] | ExceptionMatch | Any | _Unset = _UNSET,
92
105
  ) -> Generator[AssertContext, None, None]:
93
106
  """
94
107
  Context manager that makes sure `with` block behaved according to the arguments.
95
108
 
96
109
  Pair of parameters `exception` and `result` are exclusive with parameter `behaviour`. If `behaviour`
97
- is set to an exception type, it is the same as if `exception` would be set to this value and `result`
98
- would not be set. If `behaviour` is set to any other value, its treated as the value of `result` and the
99
- `exception` remains unset.
110
+ is set to an exception type or `ExceptionMatch` instance, it is the same as if `exception` would be set to
111
+ this value and `result` would not be set. If `behaviour` is set to any other value, its treated as the
112
+ value of `result` and the `exception` remains unset.
100
113
 
101
- If the `exception` parameter is set, the `with` block is expected to raise an exception of provided type.
102
- If it is NOT set, the `with` block is expected NOT TO raise any exceptions.
114
+ If the `exception` parameter is set to exception type, the `with` block is expected to raise an exception
115
+ of provided type. If the `exception` parameter is set to an instance of `ExceptionMatch` class, the `with`
116
+ block is expected to raise an exception of type specified in `type_` field and the value that matches the
117
+ string specified in `match_` field. For exact matching logic see `match` parameter of the `pytest.raises`.
118
+ If the `exception` parameter is NOT set or is set to `None`, the `with` block is expected NOT TO raise
119
+ any exceptions.
103
120
 
104
121
  If the `result` parameter is set, its value is expected to be equal to `with` block result. The `with`
105
122
  block result is set with the `set` method of an object yielded by the context manager. The comparison
@@ -107,7 +124,7 @@ def assert_context(
107
124
  If the `result` parameter is NOT set, the `set` method of yielded object is expected
108
125
  not to be called at all.
109
126
 
110
- :param exception: type of exception, expected to be raised
127
+ :param exception: specification of exception, expected to be raised
111
128
  :param result: value expected to be set with `set` method of yielded object
112
129
  :param behaviour: a common name for `exception` and `result` parameters, exclusive to them
113
130
  :yield: object used to set the result of a `with` block
@@ -115,12 +132,26 @@ def assert_context(
115
132
  if behaviour != _UNSET:
116
133
  assert exception == _UNSET
117
134
  assert result == _UNSET
118
- if isinstance(behaviour, type) and issubclass(behaviour, Exception):
135
+ if isinstance(behaviour, ExceptionMatch) or (
136
+ isinstance(behaviour, type) and issubclass(behaviour, BaseException)
137
+ ):
119
138
  exception = behaviour
120
139
  else:
121
140
  result = behaviour
141
+ if isinstance(exception, ExceptionMatch):
142
+ match_ = exception.match_
143
+ exception = exception.type_
144
+ else:
145
+ match_ = None
122
146
  context = AssertContext()
123
- exception_behaviour = nullcontext() if isinstance(exception, _Unset) else pytest.raises(exception)
147
+ exception_behaviour = (
148
+ nullcontext()
149
+ if isinstance(exception, _Unset | None)
150
+ else pytest.raises(
151
+ exception,
152
+ match=match_,
153
+ )
154
+ )
124
155
 
125
156
  with ExitStack() as behaviours_stack:
126
157
  behaviours_stack.enter_context(context.assert_result_equal(result))
@@ -71,7 +71,7 @@ def _(loader: ExpectationYamlLoader, node: yaml.Node) -> Stringified:
71
71
  problem_mark=node.start_mark,
72
72
  )
73
73
  # I was not able to produce yaml that would return something else than a string
74
- node_data = cast(str, loader.construct_scalar(node))
74
+ node_data = loader.construct_scalar(node)
75
75
  return Stringified(node_data)
76
76
 
77
77
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "panda-pytest-assertions"
3
- version = "0.1.0"
3
+ version = "0.2.0"
4
4
  description = "Complex assertions that can be used when writing test with pytest"
5
5
  authors = ["Cyber Panda <krunchfrompoland@gmail.com>"]
6
6
  readme = "README.md"
@@ -19,18 +19,18 @@ pyyaml = "^6.0.1"
19
19
 
20
20
  [tool.poetry.group.dev.dependencies]
21
21
  darglint = "^1.8.1"
22
- flake8 = "^7.0.0"
23
- ruff = "^0.4.3"
24
- mypy = "~1.10.0"
25
- pytest-cov = "^5.0.0"
22
+ flake8 = "^7.1.1"
23
+ ruff = "^0.7.3"
24
+ mypy = "~1.13.0"
25
+ pytest-cov = "^6.0.0"
26
26
  pytest-mock = "^3.14.0"
27
27
  munch = "^4.0.0"
28
28
  munch-stubs = "^0.1.2"
29
- types-pyyaml = "^6.0.12.20240311"
29
+ types-pyyaml = "^6.0.12.20240917"
30
30
 
31
31
  [tool.poetry.group.docs.dependencies]
32
- mkdocs-material = "^9.5.22"
33
- mike = "^2.1.1"
32
+ mkdocs-material = "^9.5.44"
33
+ mike = "^2.1.3"
34
34
 
35
35
  [build-system]
36
36
  requires = ["poetry-core>=1.0.0"]