rewrite to python: implement validator
This commit is contained in:
@@ -1,27 +1,200 @@
|
||||
from minecraft_kartverket.marker_sets import WORLDS
|
||||
from minecraft_kartverket.lib_marker import Point, Track
|
||||
|
||||
|
||||
def validate_marker_data() -> None:
|
||||
# TODO: print [V] checkmarks for each test
|
||||
...
|
||||
for test_name, test_f in _tests.items():
|
||||
results = test_f()
|
||||
if len(results) > 0:
|
||||
print(f"[X] {test_name}")
|
||||
for result in results:
|
||||
print(f" {result}")
|
||||
else:
|
||||
print(f"[✓] {test_name}")
|
||||
|
||||
|
||||
def validate_no_non_included_files() -> None: ...
|
||||
def validate_no_non_included_files() -> list:
|
||||
# TODO: Implement this function
|
||||
return []
|
||||
|
||||
|
||||
def validate_no_invalid_y_values() -> None: ...
|
||||
def validate_no_invalid_y_values() -> list:
|
||||
result = []
|
||||
|
||||
for world_name, marker_sets in WORLDS.items():
|
||||
for marker_set in marker_sets:
|
||||
for marker in marker_set.markers:
|
||||
if isinstance(marker, Point):
|
||||
if marker.y < 0 or marker.y > 255:
|
||||
result.append(
|
||||
{
|
||||
"error_type": "invalid_y_value",
|
||||
"full_marker_name": (
|
||||
world_name,
|
||||
marker_set.name,
|
||||
marker.name,
|
||||
),
|
||||
"y_value": marker.y,
|
||||
}
|
||||
)
|
||||
elif isinstance(marker, Track):
|
||||
for i, point in enumerate(marker.points):
|
||||
_, y, _ = point
|
||||
if y < 0 or y > 255:
|
||||
result.append(
|
||||
{
|
||||
"error_type": "invalid_y_value",
|
||||
"full_marker_name": (
|
||||
world_name,
|
||||
marker_set.name,
|
||||
marker.name,
|
||||
),
|
||||
"index": i,
|
||||
"y_value": y,
|
||||
}
|
||||
)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def validate_no_duplicate_points_in_tracks() -> None: ...
|
||||
def validate_no_duplicate_points_in_tracks() -> list:
|
||||
result = []
|
||||
|
||||
for world_name, marker_sets in WORLDS.items():
|
||||
for marker_set in marker_sets:
|
||||
for marker in marker_set.markers:
|
||||
if isinstance(marker, Track):
|
||||
points = {}
|
||||
for point in marker.points:
|
||||
if point in points:
|
||||
result.append(
|
||||
{
|
||||
"error_type": "duplicate_point",
|
||||
"point_a": points[point],
|
||||
"point_b": (
|
||||
world_name,
|
||||
marker_set.name,
|
||||
marker.name,
|
||||
),
|
||||
"coordinates": point,
|
||||
}
|
||||
)
|
||||
points[point] = (world_name, marker_set.name, marker.name)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def validate_no_duplicate_names_in_markers() -> None: ...
|
||||
def validate_no_duplicate_marker_names() -> list:
|
||||
result = []
|
||||
|
||||
marker_names = set()
|
||||
for world_name, marker_sets in WORLDS.items():
|
||||
for marker_set in marker_sets:
|
||||
for marker in marker_set.markers:
|
||||
full_name = (world_name, marker_set.name, marker.name)
|
||||
if full_name in marker_names:
|
||||
result.append(
|
||||
{
|
||||
"error_type": "duplicate_marker_name",
|
||||
"full_marker_name": full_name,
|
||||
}
|
||||
)
|
||||
marker_names.add(full_name)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def validate_no_duplicate_names_in_marker_sets() -> None: ...
|
||||
def validate_no_duplicate_marker_set_names() -> list:
|
||||
result = []
|
||||
|
||||
marker_set_names = set()
|
||||
for world_name, marker_sets in WORLDS.items():
|
||||
for marker_set in marker_sets:
|
||||
if (world_name, marker_set.name) in marker_set_names:
|
||||
result.append(
|
||||
{
|
||||
"error_type": "duplicate_marker_set_name",
|
||||
"full_marker_set_name": (world_name, marker_set.name),
|
||||
}
|
||||
)
|
||||
marker_set_names.add((world_name, marker_set.name))
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def validate_no_unused_icons() -> None: ...
|
||||
def validate_no_unused_icons() -> list:
|
||||
# TODO: Implement this function
|
||||
return []
|
||||
|
||||
|
||||
def validate_no_duplicate_points() -> None: ...
|
||||
def validate_no_duplicate_points() -> list:
|
||||
result = []
|
||||
|
||||
for world_name, marker_sets in WORLDS.items():
|
||||
points = {}
|
||||
for marker_set in marker_sets:
|
||||
for marker in marker_set.markers:
|
||||
if isinstance(marker, Point):
|
||||
point = (marker.x, marker.y, marker.z)
|
||||
if point in points:
|
||||
result.append(
|
||||
{
|
||||
"error_type": "duplicate_point",
|
||||
"point_a": points[point],
|
||||
"point_b": (world_name, marker_set.name, marker.name),
|
||||
"coordinates": point,
|
||||
}
|
||||
)
|
||||
points[point] = (world_name, marker_set.name, marker.name)
|
||||
elif isinstance(marker, Track):
|
||||
for i, point in enumerate(marker.points):
|
||||
if point in points:
|
||||
result.append(
|
||||
{
|
||||
"error_type": "duplicate_point",
|
||||
"point_a": points[point],
|
||||
"point_b": (
|
||||
world_name,
|
||||
marker_set.name,
|
||||
marker.name,
|
||||
),
|
||||
"index": i,
|
||||
"coordinates": point,
|
||||
}
|
||||
)
|
||||
points[point] = (world_name, marker_set.name, marker.name)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def validate_all_tracks_have_at_least_two_points() -> None: ...
|
||||
def validate_all_tracks_have_at_least_two_points() -> list:
|
||||
result = []
|
||||
|
||||
for world_name, marker_sets in WORLDS.items():
|
||||
for marker_set in marker_sets:
|
||||
for marker in marker_set.markers:
|
||||
if isinstance(marker, Track) and len(marker.points) < 2:
|
||||
result.append(
|
||||
{
|
||||
"error_type": "track_too_short",
|
||||
"full_marker_name": (
|
||||
world_name,
|
||||
marker_set.name,
|
||||
marker.name,
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
_tests = {
|
||||
"No non-included files": validate_no_non_included_files,
|
||||
"No invalid y coordinates": validate_no_invalid_y_values,
|
||||
"No duplicate points in tracks": validate_no_duplicate_points_in_tracks,
|
||||
"No duplicate marker names": validate_no_duplicate_marker_names,
|
||||
"No duplicate marker-set names": validate_no_duplicate_marker_set_names,
|
||||
"No unused icons": validate_no_unused_icons,
|
||||
"No duplicate points": validate_no_duplicate_points,
|
||||
"All tracks have at least two points": validate_all_tracks_have_at_least_two_points,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user