Skip to content

Commit

Permalink
Remove dead code from complex testing system
Browse files Browse the repository at this point in the history
Tests are from #306 and code is dead since #515.
  • Loading branch information
PerchunPak committed May 29, 2023
1 parent 3816eab commit 6e1c542
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 54 deletions.
25 changes: 0 additions & 25 deletions tests/status_response/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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
...
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
44 changes: 15 additions & 29 deletions tests/status_response/test_java.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down

0 comments on commit 6e1c542

Please sign in to comment.