Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tests #2

Merged
merged 3 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 39 additions & 6 deletions .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@ on:

jobs:
build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
# os: [ubuntu-latest, macos-13, macos-14] currently only works on Linux
os: [ubuntu-latest]
name: Build wheels
runs-on: ubuntu-latest

steps:
- name: Checkout the repository
Expand All @@ -22,3 +18,40 @@ jobs:

- name: Build wheels
uses: pypa/[email protected]

- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: cibw-wheels-ubuntu-latest
path: wheelhouse/*.whl

run_tests:
name: Run tests locally
runs-on: ubuntu-latest
needs: build_wheels
steps:
- name: Checkout the repository
uses: actions/checkout@v4
with:
submodules: 'recursive'

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: cibw-*
path: dist
merge-multiple: true

- name: Install wheel
run: pip install wheel

- name: Install locally
run: pip install "$(echo dist/swisspair*cp312*manylinux*x86_64*.whl)"[test]

- name: Run tests
run: pytest
29 changes: 26 additions & 3 deletions .github/workflows/deploy_test_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Test PyPI deploy
on:
push:
branches:
- "**"
- master

jobs:
generate_version:
Expand Down Expand Up @@ -82,8 +82,8 @@ jobs:
name: cibw-wheels-${{ matrix.os }}
path: wheelhouse/*.whl

publish:
name: Publish to PyPI
publish_test:
name: Publish to test PyPI
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest

Expand All @@ -106,3 +106,26 @@ jobs:
repository-url: "https://test.pypi.org/legacy/"
user: __token__
password: ${{ secrets.TESTPYPI_TOKEN }}

install_and_run_tests:
name: Install package from Test PyPI and run tests
needs: publish_test
runs-on: ubuntu-latest

steps:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: Download version
uses: actions/download-artifact@v4
with:
name: VERSION
path: .

- name: Wait for package and install it
run: while ! pip install https://test.pypi.org/simple/ --no-cache-dir swisspair[test]==$(cat VERSION); do sleep 5; done

- name: Run tests
run: pytest
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ build/
swisspair.egg-info/
dist/
_build/
__pycache__/
20 changes: 20 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,23 @@ requires=[]
before-all = """
yum -y install gmp-devel || apk add gmp-dev
"""

[tool.cibuildwheel.macos]
before-all = """
brew install gmp pkg-config
"""

[project.optional-dependencies]
test = ["pytest"]

[tool.pytest.ini_options]
minversion = "8.0"
addopts = ["-ra", "--showlocals", "--strict-markers", "--strict-config"]
xfail_strict = true
log_cli_level = "INFO"
filterwarnings = [
"error",
"ignore::pytest.PytestCacheWarning",
]
testpaths = ["tests"]
python_functions = "Given*"
15 changes: 15 additions & 0 deletions tests/test_smoke.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def GivenSwisspairLibrary_WhenImported_ThenNoError():
import swisspair

assert swisspair.__all__


def GivenTwoPlayers_WhenMatchesCreated_ThenPaired():
import swisspair
players = [swisspair.Player("P1", points=3, rank=1), swisspair.Player("P2", points=0, rank=2)]

matches = swisspair.create_matches(players)

assert len(matches) == 1
assert matches[0].p1 == players[0]
assert matches[0].p2 == players[1]