Skip to content

Commit 895578a

Browse files
committed
build: add test data dir
1 parent 5c0ba33 commit 895578a

5 files changed

Lines changed: 44 additions & 8 deletions

File tree

{{cookiecutter.project_name}}/pyproject.toml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ description = "{{cookiecutter.description}}"
55
authors = [
66
{ name = "{{cookiecutter.author_name}}" },
77
]
8-
requires-python = ">={{cookiecutter.version}}"
8+
readme = "README.md"
9+
license = { file = "LICENSE" }
10+
requires-python = ">={{cookiecutter.python_version}}"
911
dependencies = []
1012

1113
[project.optional-dependencies]
@@ -15,9 +17,6 @@ dev = [
1517
"pytest-cov==6.0.0",
1618
]
1719

18-
[tool.setuptools.packages.find]
19-
where = ["src"]
20-
2120
[build-system]
22-
requires = ["pip>=22.0", "setuptools>=61", "wheel"]
23-
build-backend = "setuptools.build_meta"
21+
requires = ["uv_build>=0.8.14,<0.9.0"]
22+
build-backend = "uv_build"

{{cookiecutter.project_name}}/src/{{cookiecutter.project_name}}/add_one.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
from pathlib import Path
2+
3+
4+
def add_one_file(input_file: Path) -> list[int]:
5+
"""
6+
Example function that adds one to the input.
7+
8+
Args:
9+
input_file: The input file containing one integer per line.
10+
11+
Returns:
12+
A list of integers, one for each line in the input file.
13+
"""
14+
with open(input_file, "r") as f:
15+
return [add_one(int(line.strip())) for line in f]
16+
17+
118
def add_one(x: int) -> int:
219
"""
320
Example function that adds one to the input.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from pathlib import Path
2+
3+
import pytest
4+
5+
6+
@pytest.fixture
7+
def test_data_dir() -> Path:
8+
"""
9+
Returns the path to the test data directory.
10+
"""
11+
return Path(__file__).parent / "data"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1
2+
2
3+
3

{{cookiecutter.project_name}}/tests/test_add_one.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
from {{cookiecutter.project_name}}.add_one import add_one
1+
from {{cookiecutter.project_name}}.add_one import add_one, add_one_file
2+
from pathlib import Path
23

4+
def test_add_one_file(test_data_dir: Path) -> None:
5+
"""
6+
Test that the add_one_file function works correctly.
7+
"""
8+
assert add_one_file(test_data_dir / "test_add_one" / "integers.txt") == [2, 3, 4]
39

4-
def test_add_one():
10+
def test_add_one() -> None:
511
"""
612
Test that the add_one function works correctly.
713
"""

0 commit comments

Comments
 (0)