From 9422e62b8103b2c95042b006141c9e81cdd5f7cf Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Mon, 11 Jul 2022 13:26:40 +0300 Subject: [PATCH 01/11] fix: non-cloudevents values must not equal to cloudevents values (#171) Signed-off-by: Alexander Tkachev --- cloudevents/http/event.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cloudevents/http/event.py b/cloudevents/http/event.py index 83adf398..eda591dc 100644 --- a/cloudevents/http/event.py +++ b/cloudevents/http/event.py @@ -67,8 +67,11 @@ def __init__(self, attributes: typing.Dict[str, str], data: typing.Any = None): f"Missing required keys: {required_set - self._attributes.keys()}" ) - def __eq__(self, other): - return self.data == other.data and self._attributes == other._attributes + def __eq__(self, other: typing.Any) -> bool: + if isinstance(other, CloudEvent): + return self.data == other.data and self._attributes == other._attributes + else: + return False # Data access is handled via `.data` member # Attribute access is managed via Mapping type From 6c6508b11d1db6822b09fa6d75bb930b623466ce Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Mon, 11 Jul 2022 13:36:30 +0300 Subject: [PATCH 02/11] test: refactor move fixtures to beginning Signed-off-by: Alexander Tkachev --- cloudevents/tests/test_http_cloudevent.py | 24 +++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/cloudevents/tests/test_http_cloudevent.py b/cloudevents/tests/test_http_cloudevent.py index 19bbbb55..11337e05 100644 --- a/cloudevents/tests/test_http_cloudevent.py +++ b/cloudevents/tests/test_http_cloudevent.py @@ -33,6 +33,18 @@ def your_dummy_data(): return '{"name":"paul"}' +@pytest.fixture() +def dummy_event(dummy_attributes, my_dummy_data): + return CloudEvent(attributes=dummy_attributes, data=my_dummy_data) + + +@pytest.fixture() +def non_exiting_attribute_name(dummy_event): + result = "nonexisting" + assert result not in dummy_event + return result + + def test_http_cloudevent_equality(dummy_attributes, my_dummy_data, your_dummy_data): data = my_dummy_data event1 = CloudEvent(dummy_attributes, data) @@ -131,18 +143,6 @@ def test_none_json_or_string(): assert _json_or_string(None) is None -@pytest.fixture() -def dummy_event(dummy_attributes, my_dummy_data): - return CloudEvent(attributes=dummy_attributes, data=my_dummy_data) - - -@pytest.fixture() -def non_exiting_attribute_name(dummy_event): - result = "nonexisting" - assert result not in dummy_event - return result - - def test_get_operation_on_non_existing_attribute_must_not_raise_exception( dummy_event, non_exiting_attribute_name ): From 494170b997175ca0ce71ebc91f5f35d1f9a0896c Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Mon, 11 Jul 2022 14:05:24 +0300 Subject: [PATCH 03/11] test: cloudevent equality bug regression (#171) Signed-off-by: Alexander Tkachev --- cloudevents/tests/test_http_cloudevent.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/cloudevents/tests/test_http_cloudevent.py b/cloudevents/tests/test_http_cloudevent.py index 11337e05..fd409f12 100644 --- a/cloudevents/tests/test_http_cloudevent.py +++ b/cloudevents/tests/test_http_cloudevent.py @@ -45,6 +45,18 @@ def non_exiting_attribute_name(dummy_event): return result +@pytest.fixture( + params=( + 1, + None, + object(), + "Hello World", + ) +) +def non_cloudevent_value(request): + return request.param + + def test_http_cloudevent_equality(dummy_attributes, my_dummy_data, your_dummy_data): data = my_dummy_data event1 = CloudEvent(dummy_attributes, data) @@ -69,6 +81,16 @@ def test_http_cloudevent_equality(dummy_attributes, my_dummy_data, your_dummy_da assert event1 != event2 and event3 != event1 +def test_http_cloudevent_equality_must_not_throw(dummy_event, non_cloudevent_value): + assert isinstance(dummy_event == non_cloudevent_value, bool) + + +def test_http_cloudevent_must_not_equal_to_non_cloudevent_value( + dummy_event, non_cloudevent_value +): + assert not dummy_event == non_cloudevent_value + + def test_http_cloudevent_mutates_equality( dummy_attributes, my_dummy_data, your_dummy_data ): From 202c98766c5b654a5320daedf633c64862387e33 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Tue, 12 Jul 2022 20:18:11 +0300 Subject: [PATCH 04/11] style: remove redundent else Signed-off-by: Alexander Tkachev --- cloudevents/http/event.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cloudevents/http/event.py b/cloudevents/http/event.py index eda591dc..629f111f 100644 --- a/cloudevents/http/event.py +++ b/cloudevents/http/event.py @@ -70,8 +70,7 @@ def __init__(self, attributes: typing.Dict[str, str], data: typing.Any = None): def __eq__(self, other: typing.Any) -> bool: if isinstance(other, CloudEvent): return self.data == other.data and self._attributes == other._attributes - else: - return False + return False # Data access is handled via `.data` member # Attribute access is managed via Mapping type From 8f98d6579518aef928459ce673583dac882bf318 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Tue, 12 Jul 2022 20:20:21 +0300 Subject: [PATCH 05/11] test: remove redundent test Signed-off-by: Alexander Tkachev --- cloudevents/tests/test_http_cloudevent.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/cloudevents/tests/test_http_cloudevent.py b/cloudevents/tests/test_http_cloudevent.py index fd409f12..43dae6c1 100644 --- a/cloudevents/tests/test_http_cloudevent.py +++ b/cloudevents/tests/test_http_cloudevent.py @@ -81,10 +81,6 @@ def test_http_cloudevent_equality(dummy_attributes, my_dummy_data, your_dummy_da assert event1 != event2 and event3 != event1 -def test_http_cloudevent_equality_must_not_throw(dummy_event, non_cloudevent_value): - assert isinstance(dummy_event == non_cloudevent_value, bool) - - def test_http_cloudevent_must_not_equal_to_non_cloudevent_value( dummy_event, non_cloudevent_value ): From 781d914011959220569666778b1291019f55f8e0 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Tue, 12 Jul 2022 20:21:22 +0300 Subject: [PATCH 06/11] test: refactor non_cloudevent_value into a parameterization Signed-off-by: Alexander Tkachev --- cloudevents/tests/test_http_cloudevent.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/cloudevents/tests/test_http_cloudevent.py b/cloudevents/tests/test_http_cloudevent.py index 43dae6c1..16e65c00 100644 --- a/cloudevents/tests/test_http_cloudevent.py +++ b/cloudevents/tests/test_http_cloudevent.py @@ -45,18 +45,6 @@ def non_exiting_attribute_name(dummy_event): return result -@pytest.fixture( - params=( - 1, - None, - object(), - "Hello World", - ) -) -def non_cloudevent_value(request): - return request.param - - def test_http_cloudevent_equality(dummy_attributes, my_dummy_data, your_dummy_data): data = my_dummy_data event1 = CloudEvent(dummy_attributes, data) @@ -81,6 +69,15 @@ def test_http_cloudevent_equality(dummy_attributes, my_dummy_data, your_dummy_da assert event1 != event2 and event3 != event1 +@pytest.mark.parametrize( + "non_cloudevent_value", + ( + 1, + None, + object(), + "Hello World", + ), +) def test_http_cloudevent_must_not_equal_to_non_cloudevent_value( dummy_event, non_cloudevent_value ): From fe3a2d084cc1d6e8b91e6c4afe2f206fe7559d02 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Tue, 12 Jul 2022 20:29:43 +0300 Subject: [PATCH 07/11] docs: update changelog Signed-off-by: Alexander Tkachev --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85ec8537..f7947494 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,9 +9,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added `.get` accessor for even properties ([#165]) +### Fixed +- Fixed event `__eq__` operator raising `AttributeError` on non-CloudEvent values ([#172]) + ### Changed - Code quality and styling tooling is unified and configs compatibility is ensured ([#167]) + ## [1.3.0] — 2022-09-07 ### Added - Python 3.9 support ([#144]) @@ -147,3 +151,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#160]: https://github.com/cloudevents/sdk-python/pull/160 [#165]: https://github.com/cloudevents/sdk-python/pull/165 [#167]: https://github.com/cloudevents/sdk-python/pull/167 +[#167]: https://github.com/cloudevents/sdk-python/pull/167 +[#172]: https://github.com/cloudevents/sdk-python/pull/172 \ No newline at end of file From 39c838a55376f935e41e15187f0cd021ca563d61 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 12 Jul 2022 17:35:32 +0000 Subject: [PATCH 08/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1e22e72..61fbb9ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added `.get` accessor for even properties ([#165]) ### Fixed -- Fixed event `__eq__` operator raising `AttributeError` on non-CloudEvent values ([#172]) +- Fixed event `__eq__` operator raising `AttributeError` on non-CloudEvent values ([#172]) ### Changed - Code quality and styling tooling is unified and configs compatibility is ensured ([#167]) From 5c0af5364dbff8f04e37c79a496b62d4aed8d233 Mon Sep 17 00:00:00 2001 From: Alexander Tkachev Date: Tue, 12 Jul 2022 20:36:13 +0300 Subject: [PATCH 09/11] docs: fix bad merge Signed-off-by: Alexander Tkachev --- CHANGELOG.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61fbb9ac..7cd9ae06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -156,11 +156,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#160]: https://github.com/cloudevents/sdk-python/pull/160 [#165]: https://github.com/cloudevents/sdk-python/pull/165 [#167]: https://github.com/cloudevents/sdk-python/pull/167 -<<<<<<< master -[#167]: https://github.com/cloudevents/sdk-python/pull/167 -[#172]: https://github.com/cloudevents/sdk-python/pull/172 -======= [#168]: https://github.com/cloudevents/sdk-python/pull/168 [#169]: https://github.com/cloudevents/sdk-python/pull/169 [#170]: https://github.com/cloudevents/sdk-python/pull/170 ->>>>>>> master +[#172]: https://github.com/cloudevents/sdk-python/pull/172 + From f55d2478edc045903c3dbe3b04f0b0a374e3aa79 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 12 Jul 2022 17:36:51 +0000 Subject: [PATCH 10/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cd9ae06..6bcb77ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -160,4 +160,3 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#169]: https://github.com/cloudevents/sdk-python/pull/169 [#170]: https://github.com/cloudevents/sdk-python/pull/170 [#172]: https://github.com/cloudevents/sdk-python/pull/172 - From 207c4a8a337a05c317190cf5cc9eceecb9041142 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 13 Jul 2022 18:42:44 +0000 Subject: [PATCH 11/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- cloudevents/http/event.py | 1 - 1 file changed, 1 deletion(-) diff --git a/cloudevents/http/event.py b/cloudevents/http/event.py index 2fd267d8..ee78cff7 100644 --- a/cloudevents/http/event.py +++ b/cloudevents/http/event.py @@ -72,7 +72,6 @@ def __eq__(self, other: typing.Any) -> bool: return self.data == other.data and self._attributes == other._attributes return False - # Data access is handled via `.data` member # Attribute access is managed via Mapping type def __getitem__(self, key: str) -> typing.Any: