From 6e1c5423b7147ae91249320b16dbf11121eba5e4 Mon Sep 17 00:00:00 2001 From: PerchunPak Date: Mon, 8 May 2023 15:59:15 +0200 Subject: [PATCH] Remove dead code from complex testing system Tests are from #306 and code is dead since #515. --- tests/status_response/__init__.py | 25 ----------------- tests/status_response/test_java.py | 44 ++++++++++-------------------- 2 files changed, 15 insertions(+), 54 deletions(-) diff --git a/tests/status_response/__init__.py b/tests/status_response/__init__.py index 88dbe635..4308306f 100644 --- a/tests/status_response/__init__.py +++ b/tests/status_response/__init__.py @@ -17,11 +17,6 @@ class BaseStatusResponseTest(abc.ABC): # first element is a list with fields to remove, and attribute that # must be None. a dict is a raw answer to pass into `build` method OPTIONAL_FIELDS: tuple[list[tuple[str, str]], dict[str, Any]] | None = None # noqa: ANN401 - # there should be a ValueError, if we exclude the field from input - # and a TypeError, if specify incorrect type - # second item in tuple is an additional items to test their types, - # but they can be not present. third item in tuple is a raw answer dict - BUILD_METHOD_VALIDATION: tuple[list[str], list[str], dict[str, Any]] | None = None # noqa: ANN401 def _validate(self) -> None: """Perform checks to validate the class.""" @@ -44,14 +39,6 @@ def _validate(self) -> None: if attribute_name in already_checked_attributes: raise ValueError("You can't test the type availability, if already testing its value/type.") - if self.BUILD_METHOD_VALIDATION is not None: - for do_required_item in self.BUILD_METHOD_VALIDATION[1]: - if do_required_item in self.BUILD_METHOD_VALIDATION[0]: - raise ValueError( - "You must specify only required fields, in first tuple's item." - f" Found '{do_required_item}' in first and second items." - ) - @abc.abstractmethod def build(self) -> Any: # noqa: ANN401 ... @@ -81,17 +68,10 @@ def _dependency_table(self) -> dict[str, bool]: "test_types_of_attributes": self.EXPECTED_TYPES is not None, "test_attribute_in": self.ATTRIBUTES_IN is not None, "test_optional_field_turns_into_none": self.OPTIONAL_FIELDS is not None, - "test_value_validating": self.BUILD_METHOD_VALIDATION is not None, - "test_type_validating": self.BUILD_METHOD_VALIDATION is not None, } def _marks_table(self) -> dict[str, tuple[str, tuple[Any, ...]]]: # hooks in conftest.py parses this table - if self.BUILD_METHOD_VALIDATION is not None: - build_method_validation_args = self.BUILD_METHOD_VALIDATION[0].copy() - build_method_validation_args.extend(self.BUILD_METHOD_VALIDATION[1]) - else: - build_method_validation_args = [] # a key in the dict must be a name of a test implementation. # and a value of the dict is a tuple, where first element is @@ -105,11 +85,6 @@ def _marks_table(self) -> dict[str, tuple[str, tuple[Any, ...]]]: "parametrize", ("to_remove,attribute_name", self.OPTIONAL_FIELDS[0] if self.OPTIONAL_FIELDS is not None else ()), ), - "test_value_validating": ( - "parametrize", - ("exclude_field", self.BUILD_METHOD_VALIDATION[0] if self.BUILD_METHOD_VALIDATION is not None else ()), - ), - "test_type_validating": ("parametrize", ("to_change_field", build_method_validation_args)), } @staticmethod diff --git a/tests/status_response/test_java.py b/tests/status_response/test_java.py index bce8cd46..50d04ad3 100644 --- a/tests/status_response/test_java.py +++ b/tests/status_response/test_java.py @@ -14,18 +14,12 @@ class TestJavaStatusResponse(BaseStatusResponseTest): ("latency", 0), ("icon", "data:image/png;base64,foo"), ] - BUILD_METHOD_VALIDATION = ( - ["players", "version", "description"], - [], - { - "players": {"max": 20, "online": 0}, - "version": {"name": "1.8-pre1", "protocol": 44}, - "description": "A Minecraft Server", - "favicon": "data:image/png;base64,foo", - }, - ) - # `BUILD_METHOD_VALIDATION[2]` has the same value, as we need. so why not reuse it? - OPTIONAL_FIELDS = [("favicon", "icon")], BUILD_METHOD_VALIDATION[2] + OPTIONAL_FIELDS = [("favicon", "icon")], { + "players": {"max": 20, "online": 0}, + "version": {"name": "1.8-pre1", "protocol": 44}, + "description": "A Minecraft Server", + "favicon": "data:image/png;base64,foo", + } @fixture(scope="class") def build(self): @@ -53,21 +47,15 @@ class TestJavaStatusPlayers(BaseStatusResponseTest): ], ), ] - BUILD_METHOD_VALIDATION = ( - ["max", "online"], - ["sample"], - { - "max": 20, - "online": 0, - "sample": [ - {"name": "foo", "id": "0b3717c4-f45d-47c8-b8e2-3d9ff6f93a89"}, - {"name": "bar", "id": "61699b2e-d327-4a01-9f1e-0ea8c3f06bc6"}, - {"name": "baz", "id": "40e8d003-8872-412d-b09a-4431a5afcbd4"}, - ], - }, - ) - # `BUILD_METHOD_VALIDATION[2]` has the same value, as we need. so why not reuse it? - OPTIONAL_FIELDS = [("sample", "sample")], BUILD_METHOD_VALIDATION[2] + OPTIONAL_FIELDS = [("sample", "sample")], { + "max": 20, + "online": 0, + "sample": [ + {"name": "foo", "id": "0b3717c4-f45d-47c8-b8e2-3d9ff6f93a89"}, + {"name": "bar", "id": "61699b2e-d327-4a01-9f1e-0ea8c3f06bc6"}, + {"name": "baz", "id": "40e8d003-8872-412d-b09a-4431a5afcbd4"}, + ], + } @fixture(scope="class") def build(self): @@ -90,7 +78,6 @@ def test_empty_sample_turns_into_empty_list(self): @BaseStatusResponseTest.construct class TestJavaStatusPlayer(BaseStatusResponseTest): EXPECTED_VALUES = [("name", "foo"), ("id", "0b3717c4-f45d-47c8-b8e2-3d9ff6f93a89")] - BUILD_METHOD_VALIDATION = ["name", "id"], [], {"name": "bar", "id": "61699b2e-d327-4a01-9f1e-0ea8c3f06bc6"} @fixture(scope="class") def build(self): @@ -107,7 +94,6 @@ def test_id_field_the_same_as_uuid(self): @BaseStatusResponseTest.construct class TestJavaStatusVersion(BaseStatusResponseTest): EXPECTED_VALUES = [("name", "1.8-pre1"), ("protocol", 44)] - BUILD_METHOD_VALIDATION = ["name", "protocol"], [], {"name": "1.8-pre1", "protocol": 44} @fixture(scope="class") def build(self):