Pylinting in tests

This commit is contained in:
Samuel Roach 2022-07-06 20:30:23 +01:00
parent 4176ed60bb
commit 41daf93395
6 changed files with 85 additions and 40 deletions

View File

@ -6,7 +6,6 @@ authors = ["Samuel Roach <samuelroach.2000@gmail.com>"]
repository = "https://github.com/Samuel-Roach/ergast-py"
license = "GPL-3.0-only"
readme = "README.md"
include = ["img/banner.png"]
[tool.poetry.dependencies]
python = "^3.10"

View File

@ -1,3 +1,5 @@
""" List of constants for use in testing """
ALONSO = {
"driverId":"alonso",
"permanentNumber":"14",

View File

@ -1,3 +1,5 @@
""" Tests for the Ergast class """
import ergast_py
class TestErgast():
@ -8,16 +10,17 @@ class TestErgast():
e = ergast_py.Ergast()
def test_filters_add(self):
# Test that when I add all the filters the params has them all
""" Assert adding filters adds them to the Ergast class """
pass
def test_paging(self):
# Test that paging works when querying large data amounts
""" Assert that paging changes the results pages """
pass
def test_reset(self):
# Test that when I've run a query the params are reset
""" Assert the function resetting works """
pass
def test_full(self):
""" Assert the full Ergast class works """
pass

View File

@ -1,3 +1,5 @@
""" Tests for Ergast Py """
from ergast_py import __version__
@ -7,4 +9,9 @@ class TestErgastPy():
"""
def test_version(self):
""" Assert the version of the system """
assert __version__ == '0.3.0'
def test_ergast(self):
""" Basic test to check Ergast functions """
pass

View File

@ -1,8 +1,10 @@
import pytest
""" Tests for the Requester class """
import tests.test_constants as test_constants
import pytest
from ergast_py.requester import Requester
from tests import test_constants
class TestRequester():
"""
@ -13,13 +15,14 @@ class TestRequester():
r = Requester()
def _construct_test_params(self, season=None, seasons=None, round=None, driver=None, constructor=None, grid=None,
qualifying=None, sprint=None, result=None, fastest=None, circuit=None, status=None,
standing=None, races=None, limit=None, offset=None, lap=None, pit_stop=None):
def _construct_test_params(self, season=None, seasons=None, round_no=None, driver=None,
constructor=None, grid=None, qualifying=None, sprint=None,
result=None, fastest=None, circuit=None, status=None, standing=None,
races=None, limit=None, offset=None, lap=None, pit_stop=None):
return {
"season": season,
"seasons": seasons,
"round": round,
"round": round_no,
"driver": driver,
"constructor": constructor,
"grid": grid,
@ -38,24 +41,30 @@ class TestRequester():
}
def test_run_request(self):
self.r.run_request(season=2008, round_no=5, criteria=["drivers", "alonso"], resource="driverStandings")
def test_run_request_doesnt_fail(self):
""" Assert a valid request doesn't fail """
self.r.run_request(season=2008, round_no=5, criteria=["drivers", "alonso"],
resource="driverStandings")
def test_run_request_fails(self):
""" Assert an invalid request fails """
with pytest.raises(Exception):
self.r.run_request(season=2008, round_no=5, criteria=["drivers", "alonso"], resource="bad request")
self.r.run_request(season=2008, round_no=5, criteria=["drivers", "alonso"],
resource="bad request")
def test_get_circuit(self):
""" Test the get_circuit function """
expected = [test_constants.ISTANBUL]
params = self._construct_test_params(season=2008, round=5)
params = self._construct_test_params(season=2008, round_no=5)
assert self.r.get_circuits(params) == expected
def test_get_constructors(self):
""" Test the get_constructors function """
expected = [test_constants.FERRARI]
params = self._construct_test_params(constructor="ferrari")
@ -64,6 +73,7 @@ class TestRequester():
def test_get_drivers(self):
""" Test the get_drivers function """
expected = [test_constants.ALONSO]
params = self._construct_test_params(driver="alonso")
@ -72,6 +82,7 @@ class TestRequester():
def test_get_qualifying(self):
""" Test the get_qualifying function """
expected = [
{
"season":"2008",
@ -95,12 +106,13 @@ class TestRequester():
}
]
params = self._construct_test_params(season=2008, round=5, qualifying=7)
params = self._construct_test_params(season=2008, round_no=5, qualifying=7)
assert self.r.get_qualifying(params) == expected
def test_get_sprints(self):
""" Test the get_sprints function """
expected = [
{
"season":"2021",
@ -136,12 +148,13 @@ class TestRequester():
}
]
params = self._construct_test_params(season=2021, round=10, sprint=7)
params = self._construct_test_params(season=2021, round_no=10, sprint=7)
assert self.r.get_sprints(params) == expected
def test_get_results(self):
""" Test the get_results function """
expected = [
{
"season":"2021",
@ -178,12 +191,13 @@ class TestRequester():
}
]
params = self._construct_test_params(season=2021, round=16, result=16)
params = self._construct_test_params(season=2021, round_no=16, result=16)
assert self.r.get_results(params) == expected
def test_get_races(self):
""" Test the get_races function """
expected = [
{
"season":"2021",
@ -208,12 +222,13 @@ class TestRequester():
}
]
params = self._construct_test_params(season=2021, round=16)
params = self._construct_test_params(season=2021, round_no=16)
assert self.r.get_races(params) == expected
def test_get_seasons(self):
""" Test the get_seasons function """
expected = [
{
"season":"2021",
@ -227,6 +242,7 @@ class TestRequester():
def test_get_statuses(self):
""" Test the get_statuses function """
expected = [
{
"statusId":"11",
@ -235,12 +251,13 @@ class TestRequester():
}
]
params = self._construct_test_params(season=2021, round=16, result=16)
params = self._construct_test_params(season=2021, round_no=16, result=16)
assert self.r.get_statuses(params) == expected
def test_get_driver_standings(self):
""" Test the get_driver_standings function """
expected = [
{
"season":"2021",
@ -260,12 +277,13 @@ class TestRequester():
}
]
params = self._construct_test_params(season=2021, round=16, driver="alonso")
params = self._construct_test_params(season=2021, round_no=16, driver="alonso")
assert self.r.get_driver_standings(params) == expected
def test_get_constructor_standings(self):
""" Test the get_constructor_standi function """
expected = [
{
"season":"2021",
@ -282,12 +300,13 @@ class TestRequester():
}
]
params = self._construct_test_params(season=2021, round=16, standing=5)
params = self._construct_test_params(season=2021, round_no=16, standing=5)
assert self.r.get_constructor_standings(params) == expected
def test_get_laps(self):
""" Test the get_laps function """
expected = [
{
"season":"2008",
@ -312,12 +331,13 @@ class TestRequester():
}
]
params = self._construct_test_params(season=2008, round=5, driver="alonso", lap=1)
params = self._construct_test_params(season=2008, round_no=5, driver="alonso", lap=1)
assert self.r.get_laps(params) == expected
def test_get_pit_stops(self):
""" Test the get_pit_stops function """
expected = [
{
"season":"2021",
@ -339,6 +359,6 @@ class TestRequester():
}
]
params = self._construct_test_params(season=2021, round=16, driver="alonso", pit_stop=1)
params = self._construct_test_params(season=2021, round_no=16, driver="alonso", pit_stop=1)
assert self.r.get_pit_stops(params) == expected

View File

@ -1,15 +1,15 @@
from copyreg import constructor
import datetime
from this import d
from ergast_py.constants import expected
from ergast_py.models.average_speed import AverageSpeed
""" Tests for the Type Constructor class """
import datetime
from ergast_py.models.average_speed import AverageSpeed
from ergast_py.models.circuit import Circuit
from ergast_py.models.constructor import Constructor
from ergast_py.models.constructor_standing import ConstructorStanding
from ergast_py.models.driver import Driver
from ergast_py.models.driver_standing import DriverStanding
from ergast_py.models.fastest_lap import FastestLap
from ergast_py.models.lap import Lap
from ergast_py.models.location import Location
from ergast_py.models.pit_stop import PitStop
from ergast_py.models.race import Race
@ -18,11 +18,10 @@ from ergast_py.models.season import Season
from ergast_py.models.standings_list import StandingsList
from ergast_py.models.status import Status
from ergast_py.models.timing import Timing
from ergast_py.models.lap import Lap
from ergast_py.requester import Requester
from ergast_py.type_constructor import TypeConstructor
import tests.test_constants as test_constants
from tests import test_constants
class TestTypeConstructor():
@ -38,6 +37,7 @@ class TestTypeConstructor():
#
def test_construct_circuit(self):
""" Assert construct_circuit function works"""
params = [test_constants.BAHRAIN]
location = Location(latitude=26.0325,
@ -53,6 +53,7 @@ class TestTypeConstructor():
assert expected == self.t.construct_circuits(params)
def test_construct_constructor(self):
""" Assert construct_constructor function works"""
params = [test_constants.ALPINE]
expected = [Constructor(constructor_id="alpine",
@ -63,6 +64,7 @@ class TestTypeConstructor():
assert expected == self.t.construct_constructors(params)
def test_construct_driver(self):
""" Assert construct_driver function works"""
params = [test_constants.ALONSO]
expected = [Driver(driver_id="alonso",
@ -78,6 +80,7 @@ class TestTypeConstructor():
assert expected == self.t.construct_drivers(params)
def test_construct_races(self):
""" Assert construct_races function works"""
params = [{
"season":"2022",
"round":"1",
@ -116,19 +119,25 @@ class TestTypeConstructor():
expected = [Race(
season=2022, round_no=1, url="http://en.wikipedia.org/wiki/2022_Bahrain_Grand_Prix",
race_name="Bahrain Grand Prix", circuit=bahrain,
date=datetime.datetime(year=2022, month=3, day=20, hour=15, tzinfo=datetime.timezone.utc),
date=datetime.datetime(year=2022, month=3, day=20, hour=15,
tzinfo=datetime.timezone.utc),
results=[],
first_practice=datetime.datetime(year=2022, month=3, day=18, hour=12, tzinfo=datetime.timezone.utc),
second_practice=datetime.datetime(year=2022, month=3, day=18, hour=15, tzinfo=datetime.timezone.utc),
third_practice=datetime.datetime(year=2022, month=3, day=19, hour=12, tzinfo=datetime.timezone.utc),
first_practice=datetime.datetime(year=2022, month=3, day=18, hour=12,
tzinfo=datetime.timezone.utc),
second_practice=datetime.datetime(year=2022, month=3, day=18, hour=15,
tzinfo=datetime.timezone.utc),
third_practice=datetime.datetime(year=2022, month=3, day=19, hour=12,
tzinfo=datetime.timezone.utc),
sprint=None, sprint_results=[],
qualifying=datetime.datetime(year=2022, month=3, day=19, hour=15, tzinfo=datetime.timezone.utc),
qualifying=datetime.datetime(year=2022, month=3, day=19, hour=15,
tzinfo=datetime.timezone.utc),
qualifying_results=[], pit_stops=[], laps=[]
)]
assert expected == self.t.construct_races(params)
def test_construct_results(self):
""" Assert construct_results function works"""
params = [{
"number":"16",
"position":"1",
@ -177,6 +186,7 @@ class TestTypeConstructor():
assert expected == self.t.construct_results(params)
def test_construct_pit_stops(self):
""" Assert construct_pit_stops function works"""
params = [{
"driverId":"alonso",
"lap":"11",
@ -196,6 +206,7 @@ class TestTypeConstructor():
assert expected == self.t.construct_pit_stops(params)
def test_construct_laps(self):
""" Assert construct_laps function works"""
params = [{
"number":"1",
"Timings":[{
@ -215,6 +226,7 @@ class TestTypeConstructor():
assert expected == self.t.construct_laps(params)
def test_construct_seasons(self):
""" Assert construct_seasons function works"""
params = [{
"season":"2022",
"url":"http://en.wikipedia.org/wiki/2022_Formula_One_World_Championship"
@ -228,6 +240,7 @@ class TestTypeConstructor():
assert expected == self.t.construct_seasons(params)
def test_construct_statuses(self):
""" Assert construct_statuses function works"""
params = [{
"statusId":"1",
"count":"1",
@ -243,6 +256,7 @@ class TestTypeConstructor():
assert expected == self.t.construct_statuses(params)
def test_construct_standings_lists(self):
""" Assert construct_standings_lists function works"""
# Check Driver Standings
# Check constructor standings
params = [{