Skip to content

Commit

Permalink
▶️ Set up CI pipeline for unittesting (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
OLILHR authored Jul 31, 2024
1 parent 3789acf commit 1f6ee22
Show file tree
Hide file tree
Showing 16 changed files with 146 additions and 6 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions .github/workflows/unittesting.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
!*.example

.coverage
__pycache__/
.idea/
.pytest_cache/
.tox/
__pycache__/
htmlcov/

# OS
.DS_Store
Expand Down
10 changes: 5 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[tox]
envlist =
# coverage
coverage
linting
spellchecking
# testing
testing
tytpechecking
isolated_build = True
skip_missing_interpreters = True
Expand All @@ -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}
Expand All @@ -38,7 +38,7 @@ deps =
-r dev_requirements/requirements-spellchecking.txt
commands =
codespell alloy/
# codespell unittests/
codespell unittests/
codespell README.md

[testenv:testing]
Expand All @@ -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 =
Expand Down
10 changes: 10 additions & 0 deletions unittests/.pylintrc
Original file line number Diff line number Diff line change
@@ -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
Empty file added unittests/__init__.py
Empty file.
11 changes: 11 additions & 0 deletions unittests/conftest.py
Original file line number Diff line number Diff line change
@@ -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"),
}
2 changes: 2 additions & 0 deletions unittests/data/.alloyignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.png
.svg
Empty file added unittests/data/__init__.py
Empty file.
8 changes: 8 additions & 0 deletions unittests/data/dummy.md
Original file line number Diff line number Diff line change
@@ -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.
Binary file added unittests/data/dummy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions unittests/data/dummy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
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.
"""
6 changes: 6 additions & 0 deletions unittests/data/dummy.txt
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 9 additions & 0 deletions unittests/data/dummy/dummy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions unittests/data/dummy/dummy.yml
Original file line number Diff line number Diff line change
@@ -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.
25 changes: 25 additions & 0 deletions unittests/test_file_collector.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1f6ee22

Please sign in to comment.