Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bboonstra committed Sep 29, 2024
1 parent 174ce51 commit f4a3a53
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 40 deletions.
40 changes: 21 additions & 19 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
name: Publish to PyPI

on:
push:
tags:
- 'release*' # Only run this workflow when a version tag is pushed
workflow_run:
workflows: ["tests"] # The name of your tests workflow
types:
- completed # This will trigger the workflow when the tests workflow completes

jobs:
build:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' && startsWith(github.ref, 'refs/tags/release') }} # Only run if tests passed and the tag matches

steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8' # Specify the Python version you want to use
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8' # Specify the Python version you want to use

- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel twine
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel twine
- name: Build the package
run: python setup.py sdist bdist_wheel
- name: Build the package
run: python setup.py sdist bdist_wheel

- name: Publish to PyPI
env:
TWINE_USERNAME: __token__ # Use the username __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: twine upload dist/*
- name: Publish to PyPI
env:
TWINE_USERNAME: __token__ # Use the username __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} # Ensure you have this secret set up
run: twine upload dist/*
41 changes: 21 additions & 20 deletions .github/workflows/testpypi.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
name: Publish to TestPyPI

on:
push:
tags:
- 'test*'
- 'release*' # Only run this workflow when a test or release tag is pushed
workflow_run:
workflows: ["tests"] # The name of your tests workflow
types:
- completed # Trigger when the tests workflow completes

jobs:
build:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' && (startsWith(github.ref, 'refs/tags/test') || startsWith(github.ref, 'refs/tags/release')) }} # Only run if tests passed and the tag matches

steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8' # Specify the Python version you want to use
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8' # Specify the Python version you want to use

- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel twine
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel twine
- name: Build the package
run: python setup.py sdist bdist_wheel
- name: Build the package
run: python setup.py sdist bdist_wheel

- name: Publish to TestPyPI
env:
TWINE_USERNAME: __token__ # Use the username __token__
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_TOKEN }}
run: twine upload --repository testpypi dist/*
- name: Publish to TestPyPI
env:
TWINE_USERNAME: __token__ # Use the username __token__
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_TOKEN }}
run: twine upload --repository testpypi dist/*
31 changes: 31 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Unit Tests

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Check out the code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9' # Change this to your project's Python version

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run unit tests
run: |
python -m unittest discover -s tests
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='idlegame',
version='1.4.0',
version='1.5.0',
packages=find_packages(),
install_requires=[
'colorama',
Expand Down
Empty file added tests/__init__.py
Empty file.
22 changes: 22 additions & 0 deletions tests/test_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import unittest
from idlegame.data import AutosavedPlayer

class TestAutosavedPlayer(unittest.TestCase):

def setUp(self):
"""Set up a fresh AutosavedPlayer instance before each test."""
self.player = AutosavedPlayer()

def test_initial_gold(self):
"""Test that a new player starts with 0 gold."""
self.assertEqual(self.player.gold, 0)

def test_add_gold(self):
"""Test adding gold to the player."""
self.player.gold += 50
self.assertEqual(self.player.gold, 50)

# Add more tests here for other functionalities

if __name__ == '__main__':
unittest.main()

0 comments on commit f4a3a53

Please sign in to comment.