diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..26f3464 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,35 @@ +# .coveragerc to control coverage.py +[run] +branch = False +source = src + +omit = + */tests/* + */assets/* + */src/styles/* + */__init__.py + +disable_warnings = include-ignored + +[report] +# Regexes for lines to exclude from consideration +exclude_lines = + # Have to re-enable the standard pragma + pragma: no cover + + # Don't complain about missing debug-only code: + def __repr__ + def __str__ + def main + if self\.debug + + # Don't complain if tests don't hit defensive assertion code: + raise AssertionError + raise NotImplementedError + + # Don't complain if non-runnable code isn't run: + if 0: + if __name__ == .__main__.: + +ignore_errors = True +show_missing = True diff --git a/.github/ci.yml b/.github/ci.yml new file mode 100644 index 0000000..e5bd2f5 --- /dev/null +++ b/.github/ci.yml @@ -0,0 +1,31 @@ +name: Python package + +on: + pull_request: + branches: [ main ] +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [ "3.10" ] + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Display Python version + run: python -c "import sys; print(sys.version)" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements_server.txt + pip install -r requirements_dev.txt + - name: Log in with sourcery + run: + sourcery login --token ${{ secrets.SOURCERY_TOKEN }} + - name: Run pre-commit checks + run: pre-commit run --all-files -a + - name: Run tests + run: pytest diff --git a/pyproject.toml b/pyproject.toml index 5c79b2e..ca4b6c1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,6 +28,7 @@ exclude = [".bzr", ".idea", ".streamlit", ] +extend-exclude = ["tests", "assets", "src/styles"] per-file-ignores = { } # Allow unused variables when underscore-prefixed. diff --git a/requirements_dev.txt b/requirements_dev.txt new file mode 100644 index 0000000..09e499a --- /dev/null +++ b/requirements_dev.txt @@ -0,0 +1,4 @@ +pytest==7.3.0 +ruff==0.0.261 +pre_commit==3.2.2 +pytest-cov==4.0.0 diff --git a/src/utils/helpers.py b/src/utils/helpers.py index 3b60772..a6a41cd 100644 --- a/src/utils/helpers.py +++ b/src/utils/helpers.py @@ -20,5 +20,5 @@ def get_files_in_dir(path: Path) -> List[str]: return files -def get_random_img(my_list: list) -> str: - return random.choice(my_list) +def get_random_img(img_names: list[str]) -> str: + return random.choice(img_names) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_helpers.py b/tests/test_helpers.py new file mode 100644 index 0000000..d75ff19 --- /dev/null +++ b/tests/test_helpers.py @@ -0,0 +1,6 @@ +from src.utils.helpers import get_random_img + + +def test_get_random_img(): + img_names = ["img/1.png", "img/2.png", "img/3.png"] + assert get_random_img(img_names) in img_names