add backend tests
This commit is contained in:
parent
afe14909b0
commit
2c794723c7
28
.github/workflows/test-backend.yml
vendored
Normal file
28
.github/workflows/test-backend.yml
vendored
Normal 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
|
@ -5,3 +5,4 @@ greenlet==1.1.0
|
|||||||
python-engineio==3.14.2
|
python-engineio==3.14.2
|
||||||
python-socketio==4.6.1
|
python-socketio==4.6.1
|
||||||
six==1.16.0
|
six==1.16.0
|
||||||
|
pytest==6.2.4
|
37
backend/tests/deck_test.py
Normal file
37
backend/tests/deck_test.py
Normal 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
|
4
backend/tests/dummy_socket.py
Normal file
4
backend/tests/dummy_socket.py
Normal 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
|
Loading…
Reference in New Issue
Block a user