diff --git a/ergast_py/models/average_speed.py b/ergast_py/models/average_speed.py index f10530f..5199ab6 100644 --- a/ergast_py/models/average_speed.py +++ b/ergast_py/models/average_speed.py @@ -20,3 +20,9 @@ class AverageSpeed(): def __repr__(self) -> str: members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) return f"{type(self).__name__}({members})" + + def __eq__(self, __o: object) -> bool: + return isinstance(__o, AverageSpeed) and ( + self.units == __o.units and + self.speed == __o.speed + ) diff --git a/ergast_py/models/circuit.py b/ergast_py/models/circuit.py index e0e80a6..46bfb19 100644 --- a/ergast_py/models/circuit.py +++ b/ergast_py/models/circuit.py @@ -26,3 +26,11 @@ class Circuit(): def __repr__(self) -> str: members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) return f"{type(self).__name__}({members})" + + def __eq__(self, __o: object) -> bool: + return isinstance(__o, Circuit) and ( + self.circuit_id == __o.circuit_id and + self.url == __o.url and + self.circuit_name == __o.circuit_name and + self.location == __o.location + ) diff --git a/ergast_py/models/constructor.py b/ergast_py/models/constructor.py index 709477f..d721af4 100644 --- a/ergast_py/models/constructor.py +++ b/ergast_py/models/constructor.py @@ -24,3 +24,11 @@ class Constructor(): def __repr__(self) -> str: members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) return f"{type(self).__name__}({members})" + + def __eq__(self, __o: object) -> bool: + return isinstance(__o, Constructor) and ( + self.constructor_id == __o.constructor_id and + self.url == __o.url and + self.name == __o.name and + self.nationality == __o.nationality + ) diff --git a/ergast_py/models/constructor_standing.py b/ergast_py/models/constructor_standing.py index 357d456..1d9b6b0 100644 --- a/ergast_py/models/constructor_standing.py +++ b/ergast_py/models/constructor_standing.py @@ -29,3 +29,12 @@ class ConstructorStanding(): def __repr__(self) -> str: members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) return f"{type(self).__name__}({members})" + + def __eq__(self, __o: object) -> bool: + return isinstance(__o, ConstructorStanding) and ( + self.position == __o.position and + self.position_text == __o.position_text and + self.points == __o.points and + self.wins == __o.wins and + self.constructor == __o.constructor + ) diff --git a/ergast_py/models/driver.py b/ergast_py/models/driver.py index 6b404ab..3c2d00f 100644 --- a/ergast_py/models/driver.py +++ b/ergast_py/models/driver.py @@ -34,3 +34,15 @@ class Driver(): def __repr__(self) -> str: members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) return f"{type(self).__name__}({members})" + + def __eq__(self, __o: object) -> bool: + return isinstance(__o, Driver) and ( + self.driver_id == __o.driver_id and + self.permanent_number == __o.permanent_number and + self.code == __o.code and + self.url == __o.url and + self.given_name == __o.given_name and + self.family_name == __o.family_name and + self.date_of_birth == __o.date_of_birth and + self.nationality == __o.nationality + ) diff --git a/ergast_py/models/driver_standing.py b/ergast_py/models/driver_standing.py index 619e43b..be7f0bb 100644 --- a/ergast_py/models/driver_standing.py +++ b/ergast_py/models/driver_standing.py @@ -32,3 +32,13 @@ class DriverStanding(): def __repr__(self) -> str: members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) return f"{type(self).__name__}({members})" + + def __eq__(self, __o: object) -> bool: + return isinstance(__o, DriverStanding) and ( + self.position == __o.position and + self.position_text == __o.position_text and + self.points == __o.points and + self.wins == __o.wins and + self.driver == __o.driver and + self.constructors == __o.constructors + ) diff --git a/ergast_py/models/fastest_lap.py b/ergast_py/models/fastest_lap.py index 37f99b9..7ce742b 100644 --- a/ergast_py/models/fastest_lap.py +++ b/ergast_py/models/fastest_lap.py @@ -28,3 +28,11 @@ class FastestLap(): def __repr__(self) -> str: members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) return f"{type(self).__name__}({members})" + + def __eq__(self, __o: object) -> bool: + return isinstance(__o, FastestLap) and ( + self.rank == __o.rank and + self.lap == __o.lap and + self.time == __o.time and + self.average_speed == __o.average_speed + ) diff --git a/ergast_py/models/lap.py b/ergast_py/models/lap.py index eb4931d..c3387b3 100644 --- a/ergast_py/models/lap.py +++ b/ergast_py/models/lap.py @@ -22,3 +22,9 @@ class Lap(): def __repr__(self) -> str: members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) return f"{type(self).__name__}({members})" + + def __eq__(self, __o: object) -> bool: + return isinstance(__o, Lap) and ( + self.number == __o.number and + self.timings == __o.timings + ) diff --git a/ergast_py/models/location.py b/ergast_py/models/location.py index e82c0d1..eefe836 100644 --- a/ergast_py/models/location.py +++ b/ergast_py/models/location.py @@ -24,3 +24,11 @@ class Location(): def __repr__(self) -> str: members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) return f"{type(self).__name__}({members})" + + def __eq__(self, __o: object) -> bool: + return isinstance(__o, Location) and ( + self.latitude == __o.latitude and + self.longitude == __o.longitude and + self.locality == __o.locality and + self.country == __o.country + ) diff --git a/ergast_py/models/pit_stop.py b/ergast_py/models/pit_stop.py index 8d4cc79..3406ca1 100644 --- a/ergast_py/models/pit_stop.py +++ b/ergast_py/models/pit_stop.py @@ -28,3 +28,12 @@ class PitStop(): def __repr__(self) -> str: members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) return f"{type(self).__name__}({members})" + + def __eq__(self, __o: object) -> bool: + return isinstance(__o, PitStop) and ( + self.driver_id == __o.driver_id and + self.lap == __o.lap and + self.stop == __o.stop and + self.local_time == __o.local_time and + self.duration == __o.duration + ) diff --git a/ergast_py/models/race.py b/ergast_py/models/race.py index f784c6e..874771d 100644 --- a/ergast_py/models/race.py +++ b/ergast_py/models/race.py @@ -59,3 +59,23 @@ class Race(): def __repr__(self) -> str: members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) return f"{type(self).__name__}({members})" + + def __eq__(self, __o: object) -> bool: + return isinstance(__o, Race) and ( + self.season == __o.season and + self.round_no == __o.round_no and + self.url == __o.url and + self.race_name == __o.race_name and + self.circuit == __o.circuit and + self.date == __o.date and + self.results == __o.results and + self.first_practice == __o.first_practice and + self.second_practice == __o.second_practice and + self.third_practice == __o.third_practice and + self.sprint == __o.sprint and + self.sprint_results == __o.sprint_results and + self.qualifying == __o.qualifying and + self.qualifying_results == __o.qualifying_results and + self.pit_stops == __o.pit_stops and + self.laps == __o.laps + ) diff --git a/ergast_py/models/result.py b/ergast_py/models/result.py index 73ce1c9..4aaf5c7 100644 --- a/ergast_py/models/result.py +++ b/ergast_py/models/result.py @@ -52,3 +52,21 @@ class Result(): def __repr__(self) -> str: members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) return f"{type(self).__name__}({members})" + + def __eq__(self, __o: object) -> bool: + return isinstance(__o, Result) and ( + self.number == __o.number and + self.position == __o.position and + self.position_text == __o.position_text and + self.points == __o.points and + self.driver == __o.driver and + self.constructor == __o.constructor and + self.grid == __o.grid and + self.laps == __o.laps and + self.status == __o.status and + self.time == __o.time and + self.fastest_lap == __o.fastest_lap and + self.qual_1 == __o.qual_1 and + self.qual_2 == __o.qual_2 and + self.qual_3 == __o.qual_3 + ) diff --git a/ergast_py/models/season.py b/ergast_py/models/season.py index 1964294..99f4415 100644 --- a/ergast_py/models/season.py +++ b/ergast_py/models/season.py @@ -20,3 +20,9 @@ class Season(): def __repr__(self) -> str: members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) return f"{type(self).__name__}({members})" + + def __eq__(self, __o: object) -> bool: + return isinstance(__o, Season) and ( + self.season == __o.season and + self.url == __o.url + ) diff --git a/ergast_py/models/standings_list.py b/ergast_py/models/standings_list.py index e078de1..c8d43d7 100644 --- a/ergast_py/models/standings_list.py +++ b/ergast_py/models/standings_list.py @@ -28,3 +28,11 @@ class StandingsList(): def __repr__(self) -> str: members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) return f"{type(self).__name__}({members})" + + def __eq__(self, __o: object) -> bool: + return isinstance(__o, StandingsList) and ( + self.season == __o.season and + self.round_no == __o.round_no and + self.driver_standings == __o.driver_standings and + self.constructor_standings == __o.constructor_standings + ) diff --git a/ergast_py/models/status.py b/ergast_py/models/status.py index 6356868..ede04b7 100644 --- a/ergast_py/models/status.py +++ b/ergast_py/models/status.py @@ -22,3 +22,10 @@ class Status(): def __repr__(self) -> str: members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) return f"{type(self).__name__}({members})" + + def __eq__(self, __o: object) -> bool: + return isinstance(__o, Status) and ( + self.status_id == __o.status_id and + self.count == __o.count and + self.status == __o.status + ) diff --git a/ergast_py/models/timing.py b/ergast_py/models/timing.py index c1aa1e1..849b426 100644 --- a/ergast_py/models/timing.py +++ b/ergast_py/models/timing.py @@ -22,3 +22,10 @@ class Timing(): def __repr__(self) -> str: members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items()) return f"{type(self).__name__}({members})" + + def __eq__(self, __o: object) -> bool: + return isinstance(__o, Timing) and ( + self.driver_id == __o.driver_id and + self.position == __o.position and + self.time == __o.time + ) diff --git a/tests/test_type_constructor.py b/tests/test_type_constructor.py index fb44518..f3c8706 100644 --- a/tests/test_type_constructor.py +++ b/tests/test_type_constructor.py @@ -1,5 +1,6 @@ from copyreg import constructor import datetime +from this import d from ergast_py.models.average_speed import AverageSpeed from ergast_py.models.circuit import Circuit @@ -22,66 +23,12 @@ class TestTypeConstructor(): t = TypeConstructor() r = Requester() - def _assert_locations(self, expected: Location, actual: Location): - assert actual.latitude == expected.latitude - assert actual.longitude == expected.longitude - assert actual.locality == expected.locality - assert actual.country == expected.country - - def _assert_circuits(self, expected: Circuit, actual: Circuit): - assert actual.circuit_id == expected.circuit_id - assert actual.url == expected.url - assert actual.circuit_name == expected.circuit_name - self._assert_locations(expected.location, actual.location) - - def _assert_constructors(self, expected: Constructor, actual: Constructor): - assert actual.constructor_id == expected.constructor_id - assert actual.url == expected.url - assert actual.name == expected.name - assert actual.nationality == expected.nationality - - def _assert_drivers(self, expected: Driver, actual: Driver): - assert actual.driver_id == expected.driver_id - assert actual.code == expected.code - assert actual.url == expected.url - assert actual.given_name == expected.given_name - assert actual.family_name == expected.family_name - assert actual.date_of_birth == expected.date_of_birth - assert actual.nationality == expected.nationality - assert actual.permanent_number == expected.permanent_number - - def _assert_average_speeds(self, expected: AverageSpeed, actual: AverageSpeed): - assert actual.units == expected.units - assert actual.speed == expected.speed - - def _assert_fastest_laps(self, expected: FastestLap, actual: FastestLap): - assert actual.rank == expected.rank - assert actual.lap == expected.lap - assert actual.time == expected.time - assert actual.average_speed == expected.average_speed - - def _assert_results(self, expected: Result, actual: Result): - assert actual.number == expected.number - assert actual.position == expected.position - assert actual.position_text == expected.position_text - assert actual.points == expected.points - self._assert_drivers(expected.driver, actual.driver) - self._assert_constructors(expected.constructor, actual.constructor) - assert actual.grid == expected.grid - assert actual.laps == expected.laps - assert actual.status == expected.status - assert actual.time == expected.time - self._assert_fastest_laps(expected.fastest_lap, actual.fastest_lap) - assert actual.qual_1 == expected.qual_1 - assert actual.qual_2 == expected.qual_2 - assert actual.qual_3 == expected.qual_3 - # # Tests # def test_construct_circuit(self): - params = { + params = [{ "circuitId":"bahrain", "url":"http://en.wikipedia.org/wiki/Bahrain_International_Circuit", "circuitName":"Bahrain International Circuit", @@ -91,36 +38,34 @@ class TestTypeConstructor(): "locality":"Sakhir", "country":"Bahrain" } - } + }] location = Location(latitude=26.0325, longitude=50.5106, locality="Sakhir", country="Bahrain") - expected = Circuit(circuit_id="bahrain", + expected = [Circuit(circuit_id="bahrain", url="http://en.wikipedia.org/wiki/Bahrain_International_Circuit", circuit_name="Bahrain International Circuit", - location=location) + location=location)] - actual = self.t.construct_circuit(params) - self._assert_circuits(expected, actual) + assert expected == self.t.construct_circuits(params) def test_construct_constructor(self): - params = test_constants.ALPINE + params = [test_constants.ALPINE] - expected = Constructor(constructor_id="alpine", + expected = [Constructor(constructor_id="alpine", url="http://en.wikipedia.org/wiki/Alpine_F1_Team", name="Alpine F1 Team", - nationality="French") + nationality="French")] - actual = self.t.construct_constructor(params) - self._assert_constructors(expected, actual) + assert expected == self.t.construct_constructors(params) def test_construct_driver(self): - params = test_constants.ALONSO + params = [test_constants.ALONSO] - expected = Driver(driver_id="alonso", + expected = [Driver(driver_id="alonso", code="ALO", url="http://en.wikipedia.org/wiki/Fernando_Alonso", given_name="Fernando", @@ -128,16 +73,15 @@ class TestTypeConstructor(): date_of_birth=datetime.date(year=1981, month=7, day=29), nationality="Spanish", permanent_number=14 - ) + )] - actual = self.t.construct_driver(params) - self._assert_drivers(expected, actual) + assert expected == self.t.construct_drivers(params) def test_construct_races(self): pass def test_construct_results(self): - params ={ + params = [{ "number":"16", "position":"1", "positionText":"1", @@ -162,7 +106,7 @@ class TestTypeConstructor(): "speed":"206.018" } } - } + }] avg_speed = AverageSpeed(units="kph", speed=206.018) fastest_lap = FastestLap(rank=1, lap=51, @@ -177,13 +121,12 @@ class TestTypeConstructor(): url="http://en.wikipedia.org/wiki/Scuderia_Ferrari", name="Ferrari", nationality="Italian") - expected = Result(number=16, position=1, position_text="1", points=26, driver=driver, + expected = [Result(number=16, position=1, position_text="1", points=26, driver=driver, constructor=constructor, grid=1, laps=57, status=1, time=datetime.time(hour=1, minute=37, second=33, microsecond=584000), - fastest_lap=fastest_lap, qual_1=None, qual_2=None, qual_3=None) + fastest_lap=fastest_lap, qual_1=None, qual_2=None, qual_3=None)] - actual = self.t.construct_result(params) - self._assert_results(expected, actual) + assert expected == self.t.construct_results(params) def test_construct_pit_stops(self): pass @@ -201,4 +144,4 @@ class TestTypeConstructor(): def test_construct_standings_lists(self): # Check Driver Standings # Check constructor standings - pass + pass \ No newline at end of file