From 0ecadd1bc739a35866227f720e75e16deca5e247 Mon Sep 17 00:00:00 2001 From: Samuel Roach Date: Mon, 6 Jun 2022 12:20:48 +0100 Subject: [PATCH] Removed Model base class --- ergast_py/models/average_speed.py | 8 +++++--- ergast_py/models/circuit.py | 7 +++++-- ergast_py/models/constructor.py | 8 +++++--- ergast_py/models/constructor_standing.py | 7 +++++-- ergast_py/models/driver.py | 8 +++++--- ergast_py/models/driver_standing.py | 7 +++++-- ergast_py/models/fastest_lap.py | 7 +++++-- ergast_py/models/lap.py | 7 +++++-- ergast_py/models/location.py | 8 +++++--- ergast_py/models/model.py | 14 -------------- ergast_py/models/pit_stop.py | 8 +++++--- ergast_py/models/race.py | 7 +++++-- ergast_py/models/result.py | 7 +++++-- ergast_py/models/season.py | 8 +++++--- ergast_py/models/standings_list.py | 7 +++++-- ergast_py/models/status.py | 8 +++++--- ergast_py/models/timing.py | 8 +++++--- tests/test_requester.py | 4 +++- 18 files changed, 83 insertions(+), 55 deletions(-) delete mode 100644 ergast_py/models/model.py diff --git a/ergast_py/models/average_speed.py b/ergast_py/models/average_speed.py index f5f461d..f10530f 100644 --- a/ergast_py/models/average_speed.py +++ b/ergast_py/models/average_speed.py @@ -2,11 +2,9 @@ from dataclasses import dataclass -from ergast_py.models.model import Model - @dataclass -class AverageSpeed(Model): +class AverageSpeed(): """ Representation of a Drivers Average Speed @@ -18,3 +16,7 @@ class AverageSpeed(Model): def __init__(self, units: str, speed: float) -> None: self.units = units self.speed = speed + + def __repr__(self) -> str: + members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) + return f"{type(self).__name__}({members})" diff --git a/ergast_py/models/circuit.py b/ergast_py/models/circuit.py index 03cd9ae..e0e80a6 100644 --- a/ergast_py/models/circuit.py +++ b/ergast_py/models/circuit.py @@ -3,11 +3,10 @@ from dataclasses import dataclass from ergast_py.models.location import Location -from ergast_py.models.model import Model @dataclass -class Circuit(Model): +class Circuit(): """ Representation of a Formula One Circuit @@ -23,3 +22,7 @@ class Circuit(Model): self.url = url self.circuit_name = circuit_name self.location = location + + def __repr__(self) -> str: + members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) + return f"{type(self).__name__}({members})" diff --git a/ergast_py/models/constructor.py b/ergast_py/models/constructor.py index a9ecb63..709477f 100644 --- a/ergast_py/models/constructor.py +++ b/ergast_py/models/constructor.py @@ -2,11 +2,9 @@ from dataclasses import dataclass -from ergast_py.models.model import Model - @dataclass -class Constructor(Model): +class Constructor(): """ Representation of a Formula One Team @@ -22,3 +20,7 @@ class Constructor(Model): self.url = url self.name = name self.nationality = nationality + + def __repr__(self) -> str: + members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) + return f"{type(self).__name__}({members})" diff --git a/ergast_py/models/constructor_standing.py b/ergast_py/models/constructor_standing.py index 516ceca..357d456 100644 --- a/ergast_py/models/constructor_standing.py +++ b/ergast_py/models/constructor_standing.py @@ -3,11 +3,10 @@ from dataclasses import dataclass from ergast_py.models.constructor import Constructor -from ergast_py.models.model import Model @dataclass -class ConstructorStanding(Model): +class ConstructorStanding(): """ Representation of a Formula One Constructor's standing in a Season @@ -26,3 +25,7 @@ class ConstructorStanding(Model): self.points = points self.wins = wins self.constructor = constructor + + def __repr__(self) -> str: + members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) + return f"{type(self).__name__}({members})" diff --git a/ergast_py/models/driver.py b/ergast_py/models/driver.py index 265e065..6b404ab 100644 --- a/ergast_py/models/driver.py +++ b/ergast_py/models/driver.py @@ -3,11 +3,9 @@ import datetime from dataclasses import dataclass -from ergast_py.models.model import Model - @dataclass -class Driver(Model): +class Driver(): """ Representation of a Formula One driver @@ -32,3 +30,7 @@ class Driver(Model): self.family_name = family_name self.date_of_birth = date_of_birth self.nationality = nationality + + def __repr__(self) -> str: + members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) + return f"{type(self).__name__}({members})" diff --git a/ergast_py/models/driver_standing.py b/ergast_py/models/driver_standing.py index 07ab218..619e43b 100644 --- a/ergast_py/models/driver_standing.py +++ b/ergast_py/models/driver_standing.py @@ -4,11 +4,10 @@ from dataclasses import dataclass from ergast_py.models.constructor import Constructor from ergast_py.models.driver import Driver -from ergast_py.models.model import Model @dataclass -class DriverStanding(Model): +class DriverStanding(): """ Representation of a Formula One Driver's standing in a Season @@ -29,3 +28,7 @@ class DriverStanding(Model): self.wins = wins self.driver = driver self.constructors = constructors + + def __repr__(self) -> str: + members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) + return f"{type(self).__name__}({members})" diff --git a/ergast_py/models/fastest_lap.py b/ergast_py/models/fastest_lap.py index 04cf207..37f99b9 100644 --- a/ergast_py/models/fastest_lap.py +++ b/ergast_py/models/fastest_lap.py @@ -4,11 +4,10 @@ import datetime from dataclasses import dataclass from ergast_py.models.average_speed import AverageSpeed -from ergast_py.models.model import Model @dataclass -class FastestLap(Model): +class FastestLap(): """ Representation of a Fastest Lap for a Formula One Driver @@ -25,3 +24,7 @@ class FastestLap(Model): self.lap = lap self.time = time self.average_speed = average_speed + + def __repr__(self) -> str: + members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) + return f"{type(self).__name__}({members})" diff --git a/ergast_py/models/lap.py b/ergast_py/models/lap.py index fb5509f..eb4931d 100644 --- a/ergast_py/models/lap.py +++ b/ergast_py/models/lap.py @@ -2,12 +2,11 @@ from dataclasses import dataclass -from ergast_py.models.model import Model from ergast_py.models.timing import Timing @dataclass -class Lap(Model): +class Lap(): """ Representation of a single Lap from a Formula One race @@ -19,3 +18,7 @@ class Lap(Model): def __init__(self, number: int, timings: list[Timing]) -> None: self.number = number self.timings = timings + + def __repr__(self) -> str: + members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) + return f"{type(self).__name__}({members})" diff --git a/ergast_py/models/location.py b/ergast_py/models/location.py index c2f9e11..e82c0d1 100644 --- a/ergast_py/models/location.py +++ b/ergast_py/models/location.py @@ -2,11 +2,9 @@ from dataclasses import dataclass -from ergast_py.models.model import Model - @dataclass -class Location(Model): +class Location(): """ Representation of a Location for a Formula One Circuit @@ -22,3 +20,7 @@ class Location(Model): self.longitude = longitude self.locality = locality self.country = country + + def __repr__(self) -> str: + members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) + return f"{type(self).__name__}({members})" diff --git a/ergast_py/models/model.py b/ergast_py/models/model.py deleted file mode 100644 index bb1ce19..0000000 --- a/ergast_py/models/model.py +++ /dev/null @@ -1,14 +0,0 @@ -""" Model class """ - -class Model(): - """ - Base class for Models within Ergast-py - """ - - def __str__(self) -> str: - members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) - return f"{type(self).__name__}({members})" - - def __repr__(self) -> str: - members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) - return f"{type(self).__name__}({members})" diff --git a/ergast_py/models/pit_stop.py b/ergast_py/models/pit_stop.py index acd3b31..8d4cc79 100644 --- a/ergast_py/models/pit_stop.py +++ b/ergast_py/models/pit_stop.py @@ -3,11 +3,9 @@ import datetime from dataclasses import dataclass -from ergast_py.models.model import Model - @dataclass -class PitStop(Model): +class PitStop(): """ Representation of a single Pit Stop from a Formula One race @@ -26,3 +24,7 @@ class PitStop(Model): self.stop = stop self.local_time = local_time self.duration = duration + + def __repr__(self) -> str: + members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) + return f"{type(self).__name__}({members})" diff --git a/ergast_py/models/race.py b/ergast_py/models/race.py index 1684173..f784c6e 100644 --- a/ergast_py/models/race.py +++ b/ergast_py/models/race.py @@ -5,13 +5,12 @@ from dataclasses import dataclass from ergast_py.models.circuit import Circuit from ergast_py.models.lap import Lap -from ergast_py.models.model import Model from ergast_py.models.pit_stop import PitStop from ergast_py.models.result import Result @dataclass -class Race(Model): +class Race(): """ Representation of a single Race from a Formula One season @@ -56,3 +55,7 @@ class Race(Model): self.qualifying_results = qualifying_results self.pit_stops = pit_stops self.laps = laps + + def __repr__(self) -> str: + members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) + return f"{type(self).__name__}({members})" diff --git a/ergast_py/models/result.py b/ergast_py/models/result.py index ce832d1..73ce1c9 100644 --- a/ergast_py/models/result.py +++ b/ergast_py/models/result.py @@ -6,11 +6,10 @@ from dataclasses import dataclass from ergast_py.models.constructor import Constructor from ergast_py.models.driver import Driver from ergast_py.models.fastest_lap import FastestLap -from ergast_py.models.model import Model @dataclass -class Result(Model): +class Result(): """ Representation of a single Result from a Formula One race @@ -49,3 +48,7 @@ class Result(Model): self.qual_1 = qual_1 self.qual_2 = qual_2 self.qual_3 = qual_3 + + def __repr__(self) -> str: + members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) + return f"{type(self).__name__}({members})" diff --git a/ergast_py/models/season.py b/ergast_py/models/season.py index a734541..1964294 100644 --- a/ergast_py/models/season.py +++ b/ergast_py/models/season.py @@ -2,11 +2,9 @@ from dataclasses import dataclass -from ergast_py.models.model import Model - @dataclass -class Season(Model): +class Season(): """ Representation of a single Season in Formula One @@ -18,3 +16,7 @@ class Season(Model): def __init__(self, season: int, url: str) -> None: self.season = season self.url = url + + def __repr__(self) -> str: + members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) + return f"{type(self).__name__}({members})" diff --git a/ergast_py/models/standings_list.py b/ergast_py/models/standings_list.py index 5724b95..e078de1 100644 --- a/ergast_py/models/standings_list.py +++ b/ergast_py/models/standings_list.py @@ -4,11 +4,10 @@ from dataclasses import dataclass from ergast_py.models.constructor_standing import ConstructorStanding from ergast_py.models.driver_standing import DriverStanding -from ergast_py.models.model import Model @dataclass -class StandingsList(Model): +class StandingsList(): """ Representation of a set of Standings from a time in Formula One @@ -25,3 +24,7 @@ class StandingsList(Model): self.round_no = round_no self.driver_standings = driver_standings self.constructor_standings = constructor_standings + + def __repr__(self) -> str: + members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) + return f"{type(self).__name__}({members})" diff --git a/ergast_py/models/status.py b/ergast_py/models/status.py index ae9aa2b..6356868 100644 --- a/ergast_py/models/status.py +++ b/ergast_py/models/status.py @@ -2,11 +2,9 @@ from dataclasses import dataclass -from ergast_py.models.model import Model - @dataclass -class Status(Model): +class Status(): """ Representation of the finishing status of a Driver in a Race @@ -20,3 +18,7 @@ class Status(Model): self.status_id = status_id self.count = count self.status = status + + def __repr__(self) -> str: + members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) + return f"{type(self).__name__}({members})" diff --git a/ergast_py/models/timing.py b/ergast_py/models/timing.py index 6e1b035..c1aa1e1 100644 --- a/ergast_py/models/timing.py +++ b/ergast_py/models/timing.py @@ -3,11 +3,9 @@ import datetime from dataclasses import dataclass -from ergast_py.models.model import Model - @dataclass -class Timing(Model): +class Timing(): """ Representation of a single timing from a lap in Formula One Timings may contain: @@ -20,3 +18,7 @@ class Timing(Model): self.driver_id = driver_id self.position = position self.time = time + + def __repr__(self) -> str: + members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) + return f"{type(self).__name__}({members})" diff --git a/tests/test_requester.py b/tests/test_requester.py index 852252b..f1cf706 100644 --- a/tests/test_requester.py +++ b/tests/test_requester.py @@ -1,7 +1,9 @@ import ergast_py import pytest + import tests.test_constants as test_constants + class TestRequester(): """ Tests for the Requester class @@ -339,4 +341,4 @@ class TestRequester(): params = self._construct_test_params(season=2021, round=16, driver="alonso", pit_stop=1) - assert self.r.get_pit_stops(params) == expected \ No newline at end of file + assert self.r.get_pit_stops(params) == expected