Skip to content

Commit

Permalink
Merge pull request #23 from EboMike/master
Browse files Browse the repository at this point in the history
Set up automatic test runs on incoming commits.
  • Loading branch information
spookybear0 authored Mar 23, 2024
2 parents f39dd7e + 51a736e commit d45feb0
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 7 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python application

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest pytest-cov
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
python -m pytest --cov=com --cov-report=xml --cov-report=html
14 changes: 9 additions & 5 deletions db/game.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# flake8: noqa: F821
# Disable "unknown name" because we're using forward references here that flake8 has no love for.

from db.types import Team, IntRole, EventType, PlayerStateType, BallPossessionEvent
from __future__ import annotations

from db.types import Team, IntRole, EventType, PlayerStateType
from tortoise import Model, fields
from db.sm5 import SM5Stats

Expand Down Expand Up @@ -166,9 +170,9 @@ async def get_player(self) -> "Player":

async def get_entity_start(self) -> EntityStarts:
return await self.entity

async def get_sm5_stats(self) -> "SM5Stats":
return SM5Stats.filter(entity__id=self.id).first()
return await SM5Stats.filter(entity__id=(await self.entity).entity_id).first()

async def to_dict(self) -> dict:
final = {}
Expand All @@ -183,7 +187,7 @@ async def to_dict(self) -> dict:
return final

def __str__(self) -> str:
return f"<EntityEnd {self.entity_id} score={self.score}>"
return f"<EntityEnd {self.entity} score={self.score}>"

def __repr__(self) -> str:
return str(self)
5 changes: 5 additions & 0 deletions db/sm5.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# flake8: noqa: F821
# Disable "unknown name" because we're using forward references here that flake8 has no love for.

from __future__ import annotations

try:
from openskill.models import PlackettLuceRating as Rating
except ImportError:
Expand Down
4 changes: 3 additions & 1 deletion stats/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ def laserball_rating(self):

@property
def games(self) -> int:
return IPLPlayer.from_id(self.player_id).games
# TODO: Fix the reference to IPLPlayer
# return IPLPlayer.from_id(self.player_id).games
return 0

async def _get_lifetime_stats(self):
cursor = mydb.cursor()
Expand Down
4 changes: 4 additions & 0 deletions tests/helpers/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ async def setup_test_database():
_TEST_SM5_GAME = await create_sm5_game_1()


async def teardown_test_database():
await Tortoise.close_connections()


async def create_sm5_game_1() -> SM5Game:
events = []
events.extend([await create_zap_event(100, ENTITY_ID_1, ENTITY_ID_2),
Expand Down
5 changes: 4 additions & 1 deletion tests/helpers/statshelper_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

from db.sm5 import SM5Game
from helpers.statshelper import count_zaps
from tests.helpers.environment import setup_test_database, ENTITY_ID_1, ENTITY_ID_2, get_sm5_game_id
from tests.helpers.environment import setup_test_database, ENTITY_ID_1, ENTITY_ID_2, get_sm5_game_id, teardown_test_database


class TestStringMethods(unittest.IsolatedAsyncioTestCase):
async def asyncSetUp(self):
await setup_test_database()

async def asyncTearDown(self):
await teardown_test_database()

async def test_count_zaps(self):
game = await SM5Game.filter(id=get_sm5_game_id()).first()
zaps = await count_zaps(game, ENTITY_ID_1, ENTITY_ID_2)
Expand Down

0 comments on commit d45feb0

Please sign in to comment.