From a412d73c57b3c9eeae3c271ad1765045dd239d8e Mon Sep 17 00:00:00 2001 From: dmb225 Date: Fri, 4 Oct 2024 11:45:14 +0200 Subject: [PATCH] Add continuous integration workflow --- .github/workflows/python-ci.yml | 44 +++++++++++++++++++ pyproject.toml | 5 ++- src/tests/unit/application/__init__.py | 0 .../unit/application/entities/__init__.py | 0 .../{ => application/entities}/test_user.py | 10 ++--- 5 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/python-ci.yml create mode 100644 src/tests/unit/application/__init__.py create mode 100644 src/tests/unit/application/entities/__init__.py rename src/tests/unit/{ => application/entities}/test_user.py (83%) diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml new file mode 100644 index 0000000..1818648 --- /dev/null +++ b/.github/workflows/python-ci.yml @@ -0,0 +1,44 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python CI + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +permissions: + contents: read + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python 3.12 + uses: actions/setup-python@v3 + with: + python-version: "3.12" + - name: Install dependencies + run: pip install .[develop] + - name: Run ruff + run: ruff check src + - name: Run mypy + run: mypy src + + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python 3.12 + uses: actions/setup-python@v3 + with: + python-version: "3.12" + - name: Install dependencies + run: pip install .[develop] + - name: Run tests with coverage + run: | + coverage run -m pytest src/tests/unit + coverage report diff --git a/pyproject.toml b/pyproject.toml index 4eb448f..d255a63 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,10 +13,11 @@ build-backend = "setuptools.build_meta" [project.optional-dependencies] develop = [ - "pytest==8.3.3", "mypy==1.11.2", - "pre-commit==3.8.0", "ruff==0.6.8", + "pre-commit==3.8.0", + "pytest==8.3.3", + "coverage==7.6.1", ] [tool.mypy] diff --git a/src/tests/unit/application/__init__.py b/src/tests/unit/application/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/tests/unit/application/entities/__init__.py b/src/tests/unit/application/entities/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/tests/unit/test_user.py b/src/tests/unit/application/entities/test_user.py similarity index 83% rename from src/tests/unit/test_user.py rename to src/tests/unit/application/entities/test_user.py index 0995666..919dc94 100644 --- a/src/tests/unit/test_user.py +++ b/src/tests/unit/application/entities/test_user.py @@ -1,9 +1,9 @@ from uuid import UUID -from core.entities.user import User +from application.entities.user import User -def test_user_creation(): +def test_user_creation() -> None: user = User( name="Alice Smith", email="alice@example.com", password="securepassword", confirmed=False ) @@ -15,7 +15,7 @@ def test_user_creation(): assert isinstance(user.id, UUID) -def test_user_default_id(): +def test_user_default_id() -> None: user1 = User( name="Alice Smith", email="alice@example.com", password="securepassword", confirmed=False ) @@ -26,7 +26,7 @@ def test_user_default_id(): assert user1.id != user2.id -def test_user_email_format(): +def test_user_email_format() -> None: user = User( name="Alice Smith", email="alice@example.com", password="securepassword", confirmed=False ) @@ -35,7 +35,7 @@ def test_user_email_format(): assert "." in user.email.split("@")[-1] -def test_user_confirmation(): +def test_user_confirmation() -> None: user = User( name="Alice Smith", email="alice@example.com", password="securepassword", confirmed=True )