add backend tests

This commit is contained in:
Alberto Xamin 2021-06-29 14:30:05 +02:00
parent afe14909b0
commit 2c794723c7
No known key found for this signature in database
GPG Key ID: 4F026F48309500A2
4 changed files with 70 additions and 0 deletions

28
.github/workflows/test-backend.yml vendored Normal file
View File

@ -0,0 +1,28 @@
name: Python package
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7]
defaults:
run:
working-directory: ./backend
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Test with pytest
run: |
pytest

View File

@ -5,3 +5,4 @@ greenlet==1.1.0
python-engineio==3.14.2
python-socketio==4.6.1
six==1.16.0
pytest==6.2.4

View File

@ -0,0 +1,37 @@
from dummy_socket import DummySocket
from bang.deck import Deck
from bang.game import Game
def test_card_flip():
g = Game('test', DummySocket())
g.deck = Deck(g)
l = len(g.deck.cards)
assert g.deck.pick_and_scrap() != None
assert len(g.deck.cards) == l - 1
assert len(g.deck.scrap_pile) == 1
def test_draw():
g = Game('test', DummySocket())
g.deck = Deck(g)
l = len(g.deck.cards)
assert g.deck.draw() != None
assert len(g.deck.cards) == l - 1
assert len(g.deck.scrap_pile) == 0
def test_reshuffle():
g = Game('test', DummySocket())
g.deck = Deck(g)
l = len(g.deck.cards)
for i in range(80):
assert g.deck.pick_and_scrap() != None
assert len(g.deck.cards) == 79
assert len(g.deck.scrap_pile) == 1
def test_draw_from_scrap():
g = Game('test', DummySocket())
g.deck = Deck(g)
l = len(g.deck.cards)
assert g.deck.pick_and_scrap() != None
assert g.deck.draw_from_scrap_pile() != None
assert len(g.deck.cards) == 79
assert len(g.deck.scrap_pile) == 0

View File

@ -0,0 +1,4 @@
class DummySocket():
def emit(self, event, data=None, to=None, room=None, skip_sid=None, namespace=None, callback=None, **kwargs):
return True