Skip to content

Commit

Permalink
Write test files to test directory
Browse files Browse the repository at this point in the history
  • Loading branch information
dstansby committed Oct 22, 2024
1 parent 83c1d7c commit a285ab3
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 35 deletions.
27 changes: 9 additions & 18 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,36 +1,27 @@
[tool.pytest.ini_options]
addopts = [
"--basetemp=pytest_output",
"--color=yes",
"--import-mode=importlib",
"--verbose",
]
testpaths = [
"tests",
]
addopts = ["--color=yes", "--import-mode=importlib", "--verbose"]
testpaths = ["tests"]

[tool.ruff]
fix = true
force-exclude = true
target-version = "py39"
lint.ignore = [
"COM812", # trailing commas (ruff-format recommended)
"D203", # no-blank-line-before-class
"D212", # multi-line-summary-first-line
"D407", # removed dashes lines under sections
"D417", # argument description in docstring (unreliable)
"D203", # no-blank-line-before-class
"D212", # multi-line-summary-first-line
"D407", # removed dashes lines under sections
"D417", # argument description in docstring (unreliable)
"ISC001", # simplify implicit str concatenation (ruff-format recommended)
]
lint.per-file-ignores = {"*tests*" = [
lint.per-file-ignores = { "*tests*" = [
"INP001",
"S101",
], "hooks*" = [
"INP001",
"T201",
]}
lint.select = [
"ALL",
]
] }
lint.select = ["ALL"]
lint.mccabe.max-complexity = 18

[tool.tomlsort]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
key: tox-${{ hashFiles('pyproject.toml') }}

- name: Set up Python
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5
uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5
with:
python-version: "3.x"
cache: "pip"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}

- name: Set up python
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5
uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5
with:
python-version: "3.x"
cache: pip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
strategy:
matrix:
python-version:
- "3.10"
- "3.11"
- "3.12"
- "3.13"

steps:
- name: Checkout source
Expand All @@ -29,7 +29,7 @@ jobs:
key: tox-${{hashFiles('pyproject.toml') }}

- name: Set up python
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5
uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5
with:
python-version: ${{ matrix.python-version }}
cache: pip
Expand Down
6 changes: 3 additions & 3 deletions tests/data/test_package_generation/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.0
rev: v0.6.8
hooks:
- id: ruff
- id: ruff-format
Expand All @@ -13,7 +13,7 @@ repos:
hooks:
- id: toml-sort-fix
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.1
rev: v1.11.2
hooks:
- id: mypy
- repo: https://github.com/pre-commit/mirrors-prettier
Expand All @@ -35,7 +35,7 @@ repos:
- --fix=lf
- id: trailing-whitespace
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.28.6
rev: 0.29.3
hooks:
# Schemas taken from https://www.schemastore.org/json/
- id: check-jsonschema
Expand Down
2 changes: 1 addition & 1 deletion tests/data/test_package_generation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Centre for Advanced Research Computing, University College London

<!-- Any tools or versions of languages needed to run code. For example specific Python or Node versions. Minimum hardware requirements also go here. -->

`cookiecutter-test` requires Python 3.10&ndash;3.12.
`cookiecutter-test` requires Python 3.11&ndash;3.13.

### Installation

Expand Down
8 changes: 4 additions & 4 deletions tests/data/test_package_generation/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ classifiers = [
"Operating System :: POSIX",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Typing :: Typed",
]
dependencies = [
Expand Down Expand Up @@ -45,7 +45,7 @@ optional-dependencies = {dev = [
"pytest-cov",
]}
readme = "README.md"
requires-python = ">=3.10"
requires-python = ">=3.11"
license.file = "LICENSE.md"
urls.homepage = "https://github.com/test-user/cookiecutter-test"

Expand Down Expand Up @@ -113,9 +113,9 @@ overrides."tool.coverage.paths.source".inline_arrays = false
legacy_tox_ini = """
[gh-actions]
python =
3.10: py310
3.11: py311
3.12: py312
3.13: py313
[testenv]
commands =
Expand All @@ -131,7 +131,7 @@ legacy_tox_ini = """
[tox]
env_list =
py310
py311
py312
py313
"""
15 changes: 10 additions & 5 deletions tests/test_package_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import difflib
import os
import pathlib
import shutil
import subprocess
import typing

Expand All @@ -14,18 +15,20 @@ def get_all_files_folders(root_path: pathlib.Path) -> set[pathlib.Path]:
Get all files and folders under a directory.
The paths are returned relative to the root path given.
__pycache__ directories are ignored.
__pycache__ directories and .DS_Store files are ignored.
"""
file_set: set[pathlib.Path] = set()
for dirpath, _, filenames in os.walk(root_path):
dirpath_path = pathlib.Path(dirpath).relative_to(root_path)
if dirpath_path.name == "__pycache__":
if dirpath_path.name in ["__pycache__"]:
continue

# Add this directory
file_set.update((dirpath_path,))
# Add any files in it
for filename in filenames:
if filename in [".DS_Store"]:
continue
file_set.update((dirpath_path / filename,))

return file_set
Expand Down Expand Up @@ -78,11 +81,13 @@ def test_package_generation(
)

if diff:
raise RuntimeError(
shutil.rmtree(expected_package_dir)
shutil.move(test_project_dir, expected_package_dir)
msg = (
"Non-zero diff between generated files and expected files.\n"
f"Generated files can be found in {test_project_dir}.\n"
"\n" + diff
"Test data files have been modified with new content."
)
raise RuntimeError(msg)


def test_pip_installable(
Expand Down

0 comments on commit a285ab3

Please sign in to comment.