From 1f6ee22ee9ce24ce971c1bec5d24791c38c7a123 Mon Sep 17 00:00:00 2001 From: olli <144932831+OLILHR@users.noreply.github.com> Date: Wed, 31 Jul 2024 07:33:52 +0200 Subject: [PATCH] =?UTF-8?q?=E2=96=B6=EF=B8=8F=20Set=20up=20CI=20pipeline?= =?UTF-8?q?=20for=20unittesting=20(#3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/coverage.yml | 27 +++++++++++++++++++++++++++ .github/workflows/unittesting.yml | 27 +++++++++++++++++++++++++++ .gitignore | 3 ++- tox.ini | 10 +++++----- unittests/.pylintrc | 10 ++++++++++ unittests/__init__.py | 0 unittests/conftest.py | 11 +++++++++++ unittests/data/.alloyignore | 2 ++ unittests/data/__init__.py | 0 unittests/data/dummy.md | 8 ++++++++ unittests/data/dummy.png | Bin 0 -> 294 bytes unittests/data/dummy.py | 8 ++++++++ unittests/data/dummy.txt | 6 ++++++ unittests/data/dummy/dummy.svg | 9 +++++++++ unittests/data/dummy/dummy.yml | 6 ++++++ unittests/test_file_collector.py | 25 +++++++++++++++++++++++++ 16 files changed, 146 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/coverage.yml create mode 100644 .github/workflows/unittesting.yml create mode 100644 unittests/.pylintrc create mode 100644 unittests/__init__.py create mode 100644 unittests/conftest.py create mode 100644 unittests/data/.alloyignore create mode 100644 unittests/data/__init__.py create mode 100644 unittests/data/dummy.md create mode 100644 unittests/data/dummy.png create mode 100644 unittests/data/dummy.py create mode 100644 unittests/data/dummy.txt create mode 100644 unittests/data/dummy/dummy.svg create mode 100644 unittests/data/dummy/dummy.yml create mode 100644 unittests/test_file_collector.py diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 0000000..17457a8 --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,27 @@ +name: "Coverage" + +on: + push: + branches: + - main + pull_request: {} +jobs: + coverage: + runs-on: ${{ matrix.os }} + strategy: + matrix: + python-version: ["3.12"] + os: [ubuntu-latest] + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install tox + - name: Run tests and determine coverage + run: | + tox -e coverage \ No newline at end of file diff --git a/.github/workflows/unittesting.yml b/.github/workflows/unittesting.yml new file mode 100644 index 0000000..08a449e --- /dev/null +++ b/.github/workflows/unittesting.yml @@ -0,0 +1,27 @@ +name: "Unittesting" + +on: + push: + branches: + - main + pull_request: {} +jobs: + pytest: + runs-on: ${{ matrix.os }} + strategy: + matrix: + python-version: ["3.12"] + os: [ubuntu-latest] + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install tox + - name: Run unittests via tox + run: | + tox -e testing \ No newline at end of file diff --git a/.gitignore b/.gitignore index 3605d6b..ae294ad 100644 --- a/.gitignore +++ b/.gitignore @@ -2,10 +2,11 @@ !*.example .coverage -__pycache__/ .idea/ .pytest_cache/ .tox/ +__pycache__/ +htmlcov/ # OS .DS_Store diff --git a/tox.ini b/tox.ini index d0123e1..3775a13 100644 --- a/tox.ini +++ b/tox.ini @@ -1,9 +1,9 @@ [tox] envlist = - # coverage + coverage linting spellchecking - # testing + testing tytpechecking isolated_build = True skip_missing_interpreters = True @@ -29,7 +29,7 @@ deps = setenv = PYTHONPATH = {toxinidir} commands = pylint alloy - # pylint unittests --rcfile=unittests/.pylintrc + pylint unittests --rcfile=unittests/.pylintrc [testenv:spellchecking] setenv = PYTHONPATH = {toxinidir} @@ -38,7 +38,7 @@ deps = -r dev_requirements/requirements-spellchecking.txt commands = codespell alloy/ - # codespell unittests/ + codespell unittests/ codespell README.md [testenv:testing] @@ -55,7 +55,7 @@ deps = -r dev_requirements/requirements-typechecking.txt commands = mypy --show-error-codes alloy --strict - # mypy --show-error-codes unittests --strict + mypy --show-error-codes unittests --strict [testenv:dev] deps = diff --git a/unittests/.pylintrc b/unittests/.pylintrc new file mode 100644 index 0000000..90e79da --- /dev/null +++ b/unittests/.pylintrc @@ -0,0 +1,10 @@ +[pylint] +disable = + C0114, # disable missing-module-docstring + C0115, # disable missing-class-docstring + C0116, # disable missing-function-docstring + R0903, # disable too-few-public-methods + W0621, # disable redefined-outer-name + R0801, # disable duplicate-code +[pylint."MESSAGES CONTROL"] +max-line-length = 120 diff --git a/unittests/__init__.py b/unittests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/unittests/conftest.py b/unittests/conftest.py new file mode 100644 index 0000000..94475a5 --- /dev/null +++ b/unittests/conftest.py @@ -0,0 +1,11 @@ +import os + +import pytest + + +@pytest.fixture +def setup_paths(request): + unittests_dir = os.path.dirname(request.module.__file__) + return { + "test_data": os.path.join(unittests_dir, "data"), + } diff --git a/unittests/data/.alloyignore b/unittests/data/.alloyignore new file mode 100644 index 0000000..6aba92a --- /dev/null +++ b/unittests/data/.alloyignore @@ -0,0 +1,2 @@ +.png +.svg \ No newline at end of file diff --git a/unittests/data/__init__.py b/unittests/data/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/unittests/data/dummy.md b/unittests/data/dummy.md new file mode 100644 index 0000000..03eb4e9 --- /dev/null +++ b/unittests/data/dummy.md @@ -0,0 +1,8 @@ +## lorem ipsum + +Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore +magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd +gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing +elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos +et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor +sit amet. diff --git a/unittests/data/dummy.png b/unittests/data/dummy.png new file mode 100644 index 0000000000000000000000000000000000000000..e68bb5ab08d3c615faa13484c8c2c3345b806ef3 GIT binary patch literal 294 zcmeAS@N?(olHy`uVBq!ia0vp^zCi55!3HEXLajuB6k~CayA#8@b22Z19F}xPUq=Rp zjs4tz5?O(K&H|6fVg?4j!ywFfJby(BP;j@Wi(^Pd+}jHqc@H@7FdNo?yKnhZiTg*E tkieDuGiQG9YkgiX=E6PbVD#*t48Qg + + + + + + + \ No newline at end of file diff --git a/unittests/data/dummy/dummy.yml b/unittests/data/dummy/dummy.yml new file mode 100644 index 0000000..789cac9 --- /dev/null +++ b/unittests/data/dummy/dummy.yml @@ -0,0 +1,6 @@ +Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore +magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd +gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing +elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos +et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor +sit amet. diff --git a/unittests/test_file_collector.py b/unittests/test_file_collector.py new file mode 100644 index 0000000..677b2ce --- /dev/null +++ b/unittests/test_file_collector.py @@ -0,0 +1,25 @@ +from alloy.collector import consolidate, read_alloyignore + + +def test_consolidate_excludes_png_and_svg(setup_paths): + codebase = consolidate(setup_paths["test_data"]) + + assert "dummy.md" in codebase + assert "dummy.txt" in codebase + assert "dummy.py" in codebase + assert "dummy.yml" in codebase + + assert "dummy.png" not in codebase + assert "dummy.svg" not in codebase + + +def test_read_alloyignore(setup_paths): + exclude = read_alloyignore(setup_paths["test_data"]) + + assert exclude("test.png") is True + assert exclude("test.svg") is True + + assert exclude("test.md") is False + assert exclude("test.txt") is False + assert exclude("test.py") is False + assert exclude("test.yml") is False