From b5588d08e2be870b37c6a5ff3279b0dc0f95d7a3 Mon Sep 17 00:00:00 2001 From: Kirstin Rohwer Date: Tue, 9 Apr 2024 13:15:18 +0200 Subject: [PATCH 1/2] Fix style of type comparisons in some unit tests --- tests/validators/allow_empty_string_test.py | 4 ++-- tests/validators/none_to_unset_value_test.py | 2 +- tests/validators/noneable_test.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/validators/allow_empty_string_test.py b/tests/validators/allow_empty_string_test.py index 2074b97..02115a6 100644 --- a/tests/validators/allow_empty_string_test.py +++ b/tests/validators/allow_empty_string_test.py @@ -30,7 +30,7 @@ def test_allow_empty_string_valid(input_data, expected_result): validator = AllowEmptyString(DecimalValidator()) result = validator.validate(input_data) - assert type(result) == type(expected_result) + assert isinstance(result, type(expected_result)) assert result == expected_result @staticmethod @@ -46,7 +46,7 @@ def test_allow_empty_string_with_default_valid(input_data, expected_result): validator = AllowEmptyString(DecimalValidator(), default=Decimal('3.1415')) result = validator.validate(input_data) - assert type(result) == type(expected_result) + assert isinstance(result, type(expected_result)) assert result == expected_result @staticmethod diff --git a/tests/validators/none_to_unset_value_test.py b/tests/validators/none_to_unset_value_test.py index 31eb436..98e567a 100644 --- a/tests/validators/none_to_unset_value_test.py +++ b/tests/validators/none_to_unset_value_test.py @@ -31,7 +31,7 @@ def test_valid(input_data, expected_result): validator = NoneToUnsetValue(DecimalValidator()) result = validator.validate(input_data) - assert type(result) == type(expected_result) + assert isinstance(result, type(expected_result)) assert result == expected_result @staticmethod diff --git a/tests/validators/noneable_test.py b/tests/validators/noneable_test.py index 804e3a7..9c5c2c6 100644 --- a/tests/validators/noneable_test.py +++ b/tests/validators/noneable_test.py @@ -31,7 +31,7 @@ def test_noneable_valid(input_data, expected_result): validator = Noneable(DecimalValidator()) result = validator.validate(input_data) - assert type(result) == type(expected_result) + assert isinstance(result, type(expected_result)) assert result == expected_result @staticmethod @@ -47,7 +47,7 @@ def test_noneable_with_default_valid(input_data, expected_result): validator = Noneable(DecimalValidator(), default=Decimal('3.1415')) result = validator.validate(input_data) - assert type(result) == type(expected_result) + assert isinstance(result, type(expected_result)) assert result == expected_result @staticmethod From 5a55fcd1b89e45d585318b84bb89e3e8bcd05a00 Mon Sep 17 00:00:00 2001 From: Kirstin Rohwer Date: Tue, 9 Apr 2024 16:30:59 +0200 Subject: [PATCH 2/2] Compare exact types with 'is' instead of using 'isinstance' (which would also accept subclasses). --- tests/validators/allow_empty_string_test.py | 4 ++-- tests/validators/none_to_unset_value_test.py | 2 +- tests/validators/noneable_test.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/validators/allow_empty_string_test.py b/tests/validators/allow_empty_string_test.py index 02115a6..0ad3228 100644 --- a/tests/validators/allow_empty_string_test.py +++ b/tests/validators/allow_empty_string_test.py @@ -30,7 +30,7 @@ def test_allow_empty_string_valid(input_data, expected_result): validator = AllowEmptyString(DecimalValidator()) result = validator.validate(input_data) - assert isinstance(result, type(expected_result)) + assert type(result) is type(expected_result) assert result == expected_result @staticmethod @@ -46,7 +46,7 @@ def test_allow_empty_string_with_default_valid(input_data, expected_result): validator = AllowEmptyString(DecimalValidator(), default=Decimal('3.1415')) result = validator.validate(input_data) - assert isinstance(result, type(expected_result)) + assert type(result) is type(expected_result) assert result == expected_result @staticmethod diff --git a/tests/validators/none_to_unset_value_test.py b/tests/validators/none_to_unset_value_test.py index 98e567a..bd5eab7 100644 --- a/tests/validators/none_to_unset_value_test.py +++ b/tests/validators/none_to_unset_value_test.py @@ -31,7 +31,7 @@ def test_valid(input_data, expected_result): validator = NoneToUnsetValue(DecimalValidator()) result = validator.validate(input_data) - assert isinstance(result, type(expected_result)) + assert type(result) is type(expected_result) assert result == expected_result @staticmethod diff --git a/tests/validators/noneable_test.py b/tests/validators/noneable_test.py index 9c5c2c6..9073f28 100644 --- a/tests/validators/noneable_test.py +++ b/tests/validators/noneable_test.py @@ -31,7 +31,7 @@ def test_noneable_valid(input_data, expected_result): validator = Noneable(DecimalValidator()) result = validator.validate(input_data) - assert isinstance(result, type(expected_result)) + assert type(result) is type(expected_result) assert result == expected_result @staticmethod @@ -47,7 +47,7 @@ def test_noneable_with_default_valid(input_data, expected_result): validator = Noneable(DecimalValidator(), default=Decimal('3.1415')) result = validator.validate(input_data) - assert isinstance(result, type(expected_result)) + assert type(result) is type(expected_result) assert result == expected_result @staticmethod