Skip to content

Commit

Permalink
Adding some small teste and tox.ini file
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaharia Constantin committed Apr 20, 2022
1 parent 79b7679 commit 70cf2af
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ lint: ## Check code formatting using isort and black.

test: ## Test the code with pytest
@echo "🚀 Testing code: Running pytest"
@pytest --doctest-modules tests
@pytest -s --doctest-modules tests

build: clean-build ## Build wheel file using poetry
@echo "🚀 Creating wheel file"
Expand All @@ -57,7 +57,7 @@ clean-pyc: ## Remove Python file artifacts

publish: ## publish a release to pypi.
@echo "🚀 Publishing: Dry run."
@poetry config pypi-token.pypi $(PYPI_TOKEN)
@poetry config pypi-token.pypi $(PYPI_API_TOKEN)
@poetry publish --dry-run
@echo "🚀 Publishing."
@poetry publish
Expand Down
2 changes: 1 addition & 1 deletion roundbox.json → cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"project_slug": "{{roundbox.project_name|lower|replace('-', '_')}}",
"project_description": "This is a template repository for Python projects that use Poetry for their dependency management.",
"include_github_actions": ["y","n"],
"publish_to": ["pypi", "artifactory", "none"],
"publish_to": ["pypi", "none"],
"mkdocs": ["y", "n"],
"tox": ["y","n"],

Expand Down
96 changes: 96 additions & 0 deletions tests/test_roundbox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# -*- coding: utf-8 -*-
import os
import shlex
import subprocess
import pytest

from contextlib import contextmanager
from pathlib import Path


def file_contains_text(file: Path, text: str) -> bool:
return open(file, "r").read().find(text) != -1


@pytest.fixture(scope="module")
def script_loc(request):
"""Return the directory of the currently running test script
:param request:
:return:
"""

return Path(request.fspath).parent.parent


def test_cicd_contains_pypi_secrets(script_loc):
"""
:return:
"""

assert file_contains_text(script_loc.joinpath(".github/workflows/on-release-main.yml"), "PYPI_API_TOKEN"), \
"The PYPI_API_TOKEN is missing from the GitHub workflow"
assert file_contains_text(script_loc.joinpath("Makefile"), "build-and-publish"), \
"From the Makefile is missing the build-and-publish command"


# def test_dont_publish(script_loc):
# """
#
# :param script_loc:
# :return:
# """
# assert not file_contains_text(
# script_loc.joinpath(".github/workflows/on-release-main.yml"), "make build-and-publish"
# )

def test_mkdocs(script_loc):
"""
:param script_loc:
:return:
"""
assert file_contains_text(script_loc.joinpath(".github/workflows/on-release-main.yml"), "mkdocs gh-deploy")
assert file_contains_text(script_loc.joinpath("Makefile"), "docs:")
assert os.path.isdir(script_loc.joinpath("docs"))

#
# def test_not_mkdocs(cookies, tmp_path):
# with run_within_dir(tmp_path):
# result = cookies.bake(extra_context={"mkdocs": "n"})
# assert not file_contains_text(
# f"{result.project_path}/.github/workflows/on-release-main.yml", "mkdocs gh-deploy"
# )
# assert not file_contains_text(f"{result.project_path}/Makefile", "docs:")
# assert not os.path.isdir(f"{result.project_path}/docs")
#
#


def test_tox(script_loc):
"""
:param script_loc:
:return:
"""
assert file_contains_text(
script_loc.joinpath(".github/workflows/on-release-main.yml"), "poetry add tox-gh-actions"
)
assert file_contains_text(
script_loc.joinpath(".github/workflows/on-merge-to-main.yml"), "poetry add tox-gh-actions"
)
assert file_contains_text(
script_loc.joinpath(".github/workflows/on-pull-request.yml"), "poetry add tox-gh-actions"
)
assert os.path.isfile(script_loc.joinpath("tox.ini"))


#
# def test_not_tox(cookies, tmp_path):
# with run_within_dir(tmp_path):
# result = cookies.bake(extra_context={"tox": "n"})
# assert not file_contains_text(
# f"{result.project_path}/.github/workflows/on-release-main.yml", "poetry add tox-gh-actions"
# )
# assert not os.path.isfile(f"{result.project_path}/tox.ini")
14 changes: 14 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[tox]
skipsdist = true
envlist = py310

[gh-actions]
python =
3.10: py310

[testenv]
passenv = PYTHON_VERSION
whitelist_externals = poetry
commands =
poetry install -v
pytest --doctest-modules tests

0 comments on commit 70cf2af

Please sign in to comment.