-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests and integrate CI (#5)
* Bunch of small fixes to types, tiny bugfix to get_moves * Implement test suite for Game class * Renaming of get_tag_value to shorter get_tag * Add Travis CI support * Replace unsupported f-string * Remove Python 3.5 support * Minor README update
- Loading branch information
Showing
11 changed files
with
200 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
language: python | ||
python: | ||
- "3.6" | ||
- "3.7" | ||
- "3.8" | ||
install: | ||
- pip install -r requirements.txt | ||
script: | ||
- make test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
.PHONY: clean-pyc clean-build clean-test docs clean test lint help | ||
|
||
help: | ||
@echo "clean - remove all build, test, coverage and Python artifacts" | ||
@echo "clean-build - remove build artifacts" | ||
@echo "clean-pyc - remove Python file artifacts" | ||
@echo "clean-test - remove test and coverage artifacts" | ||
@echo "lint - check style with flake8" | ||
@echo "test - run tests quickly with the default Python" | ||
@echo "test-all - run tests on every Python version with tox" | ||
@echo "release - package and upload a release" | ||
@echo "dist - package" | ||
@echo "install - install the package to the active Python's site-packages" | ||
|
||
clean: clean-build clean-pyc clean-test | ||
|
||
clean-build: | ||
rm -fr build/ | ||
rm -fr dist/ | ||
rm -fr .eggs/ | ||
find . -name '*.egg-info' -exec rm -fr {} + | ||
find . -name '*.egg' -exec rm -f {} + | ||
|
||
clean-pyc: | ||
find . -name '*.pyc' -exec rm -f {} + | ||
find . -name '*.pyo' -exec rm -f {} + | ||
find . -name '*~' -exec rm -f {} + | ||
find . -name '__pycache__' -exec rm -fr {} + | ||
|
||
clean-test: | ||
rm -f .coverage | ||
rm -fr htmlcov/ | ||
rm -rf .pytest_cache | ||
|
||
lint: | ||
flake8 pypgn | ||
|
||
test: | ||
python -m pytest -v --maxfail=2 | ||
|
||
test-all: | ||
test | ||
|
||
release: clean | ||
python setup.py sdist upload | ||
python setup.py bdist_wheel upload | ||
|
||
dist: clean | ||
python setup.py sdist | ||
python setup.py bdist_wheel | ||
ls -l dist | ||
|
||
install: clean | ||
python setup.py install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from pypgn.game import Game | ||
from pypgn.game import Game |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
attrs==19.3.0 | ||
entrypoints==0.3 | ||
flake8==3.7.9 | ||
importlib-metadata==0.23 | ||
mccabe==0.6.1 | ||
more-itertools==7.2.0 | ||
packaging==19.2 | ||
pluggy==0.13.1 | ||
py==1.8.0 | ||
pycodestyle==2.5.0 | ||
pyflakes==2.1.1 | ||
pyparsing==2.4.5 | ||
pytest==5.3.0 | ||
six==1.13.0 | ||
wcwidth==0.1.7 | ||
zipp==0.6.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import pytest | ||
import os | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def game_obj(): | ||
from pypgn.game import Game | ||
from pathlib import Path | ||
pgn_file_path = Path('test/resources') if 'test' not in os.getcwd() else Path('resources') | ||
|
||
return Game(str(pgn_file_path / 'test.pgn')) | ||
|
||
|
||
class TestGame: | ||
def test_get_pgn_list(self, game_obj): | ||
assert len(game_obj.get_pgn_list()) == 20 | ||
|
||
def test_get_tags(self, game_obj): | ||
assert type(game_obj.get_tags()) == dict | ||
|
||
def test_get_tag_value(self, game_obj): | ||
assert game_obj.get_tag('Event') == "Rated Blitz game" | ||
assert game_obj.get_tag('Site') == "https://lichess.org/#" | ||
assert game_obj.get_tag('UTCDate') == "2019.11.06" | ||
|
||
def test_get_move(self, game_obj): | ||
assert game_obj.get_move(4) == ["4.", "d4", "Nc6"] | ||
|
||
def test_get_moves(self, game_obj): | ||
moves = game_obj.get_moves() | ||
assert type(moves) == list | ||
assert moves[0] == ["1.", "e4", "c6"] | ||
|
||
def test_get_ply(self, game_obj): | ||
for i in range(1, game_obj.get_move_count()): | ||
move = game_obj.get_move(i) | ||
assert move[1] == game_obj.get_ply(i, 'w') \ | ||
and move[2] == game_obj.get_ply(i, 'b'), \ | ||
"Non-matching ply pair at move %s !" % str(i) | ||
|
||
def test_get_move_count(self, game_obj): | ||
assert game_obj.get_move_count() == len(game_obj.get_moves()) | ||
|
||
def test_get_result(self, game_obj): | ||
assert game_obj.get_result() == game_obj.get_tag('Result') | ||
|
||
def test_get_date(self, game_obj): | ||
assert game_obj.get_date() == game_obj.get_tag('UTCDate') | ||
|
||
def test_get_move_range(self, game_obj): | ||
assert game_obj.get_move_range(1, 28) == game_obj.get_moves() |