Skip to content

Commit

Permalink
Merge pull request #266 from seapagan/add_ci_test_action
Browse files Browse the repository at this point in the history
Add a testing stage to CI with coverage reports from codacy
  • Loading branch information
seapagan authored Feb 15, 2024
2 parents 47dea28 + ee348e5 commit 47f2899
Show file tree
Hide file tree
Showing 13 changed files with 474 additions and 221 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Tests

on:
push:
branches: ["main", "develop"]
pull_request:
branches: ["main", "develop"]
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
# ---------------------------------------------------------------------- #
# checkout repo and setup Python #
# ---------------------------------------------------------------------- #
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
# ---------------------------------------------------------------------- #
# install and configure poetry #
# ---------------------------------------------------------------------- #
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
# ---------------------------------------------------------------------- #
# load cached venv if cache exists #
# ---------------------------------------------------------------------- #
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: .venv
key:
venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version
}}-${{ hashFiles('**/poetry.lock') }}
# ---------------------------------------------------------------------- #
# install dependencies if cache does not exist #
# ---------------------------------------------------------------------- #
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root

# ---------------------------------------------------------------------- #
# run Pytest #
# ---------------------------------------------------------------------- #
- name: Test with pytest
run: |
poetry run pytest --cov-report=xml
- name: Run codacy-coverage-reporter
uses: codacy/codacy-coverage-reporter-action@v1
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
coverage-reports: ./coverage.xml
1 change: 1 addition & 0 deletions py_maker/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class ExitErrors(IntEnum):
USER_ABORT = 6
OS_ERROR = 7
INVALID_ACTION = 8
TOML_ERROR = 9


MKDOCS_CONFIG = """
Expand Down
20 changes: 15 additions & 5 deletions py_maker/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,17 @@ def get_author_and_email_from_git() -> tuple[str, str]:
"""Get the author name and email from git."""
config = GitConfigParser()

return (
str(config.get_value("user", "name", "")),
str(config.get_value("user", "email", "")),
)
try:
author_name = str(config.get_value("user", "name", ""))
except KeyError:
author_name = ""

try:
author_email = str(config.get_value("user", "email", ""))
except KeyError:
author_email = ""

return author_name, author_email


def get_file_list(template_dir: Union[Traversable, Path]) -> list[Path]:
Expand Down Expand Up @@ -112,7 +119,7 @@ def exists_on_pypi(package_name: str) -> bool:
url = f"https://pypi.org/pypi/{package_name}/json"
try:
response = requests.get(url, timeout=5)
except requests.exceptions.Timeout:
except (requests.exceptions.Timeout, requests.exceptions.ConnectionError):
return False
return response.status_code == SUCCESS_RESPONSE

Expand Down Expand Up @@ -145,6 +152,9 @@ def get_app_version() -> str:
except (KeyError, OSError) as exc:
print(f"Problem getting the Version : {exc}")
sys.exit(ExitErrors.OS_ERROR)
except rtoml.TomlParsingError as exc:
print(f"Invalid 'pyproject.toml' file : {exc}")
sys.exit(ExitErrors.TOML_ERROR)
else:
return version
else:
Expand Down
2 changes: 1 addition & 1 deletion py_maker/prompt/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def process_response(self, value: str) -> PromptType: # type: ignore
value = value.strip()
try:
return_value: PromptType = self.response_type(value) # type: ignore
except ValueError as exc:
except ValueError as exc: # pragma: no cover
raise InvalidResponse(self.validate_error_message) from exc

if self.choices is not None:
Expand Down
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ module = "tests.*"
addopts = ["--cov", "--cov-report", "term-missing", "--cov-report", "html"]
filterwarnings = []
mock_use_standalone_module = true
# pythonpath = "py_maker"

[tool.coverage.run]
# source = []
omit = ["*/tests/*"]
source = ["py_maker"]

[tool.coverage.report]
show_missing = true
30 changes: 0 additions & 30 deletions tests/test_config.py

This file was deleted.

29 changes: 0 additions & 29 deletions tests/test_constants.py

This file was deleted.

Loading

0 comments on commit 47f2899

Please sign in to comment.