diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 00000000..fc4807cd --- /dev/null +++ b/.tool-versions @@ -0,0 +1,2 @@ +nodejs 24.8.0 +python 3.13.5 diff --git a/examples/py-pytest/- b/examples/py-pytest/- new file mode 100644 index 00000000..1ca25b00 --- /dev/null +++ b/examples/py-pytest/- @@ -0,0 +1 @@ +{"created": 1773927080.850636, "duration": 0.008067131042480469, "exitcode": 0, "root": "/Users/freddie/Documents/bough/examples/py-pytest", "environment": {}, "summary": {"passed": 3, "total": 3, "collected": 3}, "collectors": [{"nodeid": "", "outcome": "passed", "result": [{"nodeid": "src", "type": "Package"}]}, {"nodeid": "src/__init__.py", "outcome": "passed", "result": [{"nodeid": "src/__init__.py::src.childs_day", "type": "DoctestItem", "lineno": 4}]}, {"nodeid": "src/test_monday.py", "outcome": "passed", "result": []}, {"nodeid": "src/test_monday.py", "outcome": "passed", "result": [{"nodeid": "src/test_monday.py::test_mondays_child_is_fair_of_face", "type": "Function", "lineno": 4}]}, {"nodeid": "src/test_tuesday.py", "outcome": "passed", "result": []}, {"nodeid": "src/test_tuesday.py", "outcome": "passed", "result": [{"nodeid": "src/test_tuesday.py::test_tuesdays_child_is_full_of_grace", "type": "Function", "lineno": 4}]}, {"nodeid": "src", "outcome": "passed", "result": [{"nodeid": "src/__init__.py", "type": "DoctestModule"}, {"nodeid": "src/test_monday.py", "type": "DoctestModule"}, {"nodeid": "src/test_monday.py", "type": "Module"}, {"nodeid": "src/test_tuesday.py", "type": "DoctestModule"}, {"nodeid": "src/test_tuesday.py", "type": "Module"}]}], "tests": [{"nodeid": "src/__init__.py::src.childs_day", "lineno": 4, "outcome": "passed", "keywords": ["src.childs_day", "__init__.py", "src", "py-pytest", ""], "setup": {"duration": 0.00019287498435005546, "outcome": "passed"}, "call": {"duration": 0.00020758301252499223, "outcome": "passed"}, "teardown": {"duration": 5.904200952500105e-05, "outcome": "passed"}}, {"nodeid": "src/test_monday.py::test_mondays_child_is_fair_of_face", "lineno": 4, "outcome": "passed", "keywords": ["test_mondays_child_is_fair_of_face", "test_monday.py", "src", "py-pytest", ""], "setup": {"duration": 5.0665985327214e-05, "outcome": "passed"}, "call": {"duration": 5.6958990171551704e-05, "outcome": "passed"}, "teardown": {"duration": 4.474999150261283e-05, "outcome": "passed"}}, {"nodeid": "src/test_tuesday.py::test_tuesdays_child_is_full_of_grace", "lineno": 4, "outcome": "passed", "keywords": ["test_tuesdays_child_is_full_of_grace", "test_tuesday.py", "src", "py-pytest", ""], "setup": {"duration": 4.5290973503142595e-05, "outcome": "passed"}, "call": {"duration": 5.0833041314035654e-05, "outcome": "passed"}, "teardown": {"duration": 5.483301356434822e-05, "outcome": "passed"}}]} \ No newline at end of file diff --git a/examples/py-pytest/.gitignore b/examples/py-pytest/.gitignore new file mode 100644 index 00000000..a144b5b0 --- /dev/null +++ b/examples/py-pytest/.gitignore @@ -0,0 +1,5 @@ +.venv/ +__pycache__/ +*.pyc +.bough/workspaces +uv.lock diff --git a/examples/py-pytest/bough.config.toml b/examples/py-pytest/bough.config.toml new file mode 100644 index 00000000..33604c54 --- /dev/null +++ b/examples/py-pytest/bough.config.toml @@ -0,0 +1,10 @@ +base_root_dir = "." + +include = ["./src/__init__.py"] +exclude = [] + +test.cmd = "uv run pytest" + +[lang.py] +include = ["./src/__init__.py"] +exclude = ["**/*test*.py"] diff --git a/examples/py-pytest/get-failed-test-ids.py b/examples/py-pytest/get-failed-test-ids.py new file mode 100644 index 00000000..89582186 --- /dev/null +++ b/examples/py-pytest/get-failed-test-ids.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 +import hashlib +import json +import subprocess +import tempfile + +with tempfile.NamedTemporaryFile(suffix=".json") as f: + subprocess.run( + ["uv", "run", "pytest", "--tb=no", "-q", "--json-report", f"--json-report-file={f.name}"], + capture_output=True, + ) + report = json.load(f) + +seen = set() +for test in report.get("tests", []): + if test["outcome"] != "failed": + continue + path = test["nodeid"].split("::")[0] + if path in seen: + continue + seen.add(path) + content = open(path, "rb").read() + h = hashlib.sha256(content).hexdigest() + print(f"{path} {h}") diff --git a/examples/py-pytest/get-test-ids.py b/examples/py-pytest/get-test-ids.py new file mode 100644 index 00000000..8f7f8431 --- /dev/null +++ b/examples/py-pytest/get-test-ids.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python3 +import hashlib +import os + +for root, dirs, files in os.walk("src"): + dirs[:] = [d for d in dirs if d not in ("__pycache__",)] + for name in files: + if not name.endswith(".py"): + continue + path = os.path.join(root, name) + content = open(path, "rb").read() + text = content.decode() + if name.startswith("test_") or ">>>" in text: + h = hashlib.sha256(content).hexdigest() + print(f"{path} {h}") diff --git a/examples/py-pytest/pyproject.toml b/examples/py-pytest/pyproject.toml new file mode 100644 index 00000000..c5403864 --- /dev/null +++ b/examples/py-pytest/pyproject.toml @@ -0,0 +1,11 @@ +[project] +name = "bough-example-pytest" +version = "0.1.0" +requires-python = ">=3.12" + +[tool.pytest.ini_options] +addopts = ["--doctest-modules"] +testpaths = ["src"] + +[dependency-groups] +dev = ["pytest>=8.0", "pytest-json-report>=1.5"] diff --git a/examples/py-pytest/src/__init__.py b/examples/py-pytest/src/__init__.py new file mode 100644 index 00000000..99e3f878 --- /dev/null +++ b/examples/py-pytest/src/__init__.py @@ -0,0 +1,19 @@ +from datetime import date + + +def childs_day(d: date) -> str: + """Return the Monday's Child verse for a given date. + + >>> childs_day(date(2026, 2, 25)) + 'full of woe' + """ + verses = { + 0: "fair of face", + 1: "full of grace", + 2: "full of woe", + 3: "has far to go", + 4: "loving and giving", + 5: "works hard for a living", + 6: "bonny and blithe and good and gay", + } + return verses[d.weekday()] diff --git a/examples/py-pytest/src/test_monday.py b/examples/py-pytest/src/test_monday.py new file mode 100644 index 00000000..38eb5ce9 --- /dev/null +++ b/examples/py-pytest/src/test_monday.py @@ -0,0 +1,6 @@ +from datetime import date +from src import childs_day + + +def test_mondays_child_is_fair_of_face(): + assert childs_day(date(2026, 2, 23)) == "fair of face" diff --git a/examples/py-pytest/src/test_tuesday.py b/examples/py-pytest/src/test_tuesday.py new file mode 100644 index 00000000..2cc23c0e --- /dev/null +++ b/examples/py-pytest/src/test_tuesday.py @@ -0,0 +1,6 @@ +from datetime import date +from src import childs_day + + +def test_tuesdays_child_is_full_of_grace(): + assert childs_day(date(2026, 2, 24)) == "full of grace"