Skip to content

Commit

Permalink
CLI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
flying-sheep committed Nov 29, 2023
1 parent 63bbcbd commit 16ceeb9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ test = [
source = "vcs"

[tool.hatch.envs.test]
python = "3.12"
features = ["test"]
[tool.hatch.envs.test.scripts]
run = "pytest -vv {args}"
Expand Down
5 changes: 4 additions & 1 deletion tests/data/notebooks/example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
"outputs": [],
"source": [
"import random\n",
"random.randint(0, 10)"
"from pathlib import Path\n",
"\n",
"r = random.randint(0, 10)\n",
"Path(\"r.txt\").write_text(str(r))\n"
]
}
],
Expand Down
9 changes: 7 additions & 2 deletions tests/test_runner.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import shutil
from contextlib import chdir
from pathlib import Path
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -54,5 +56,8 @@ def mk_nb() -> None:
assert exc_rr.value.traceback == exc_orig.value.traceback


def test_cli() -> None:
main([f"--preludes={preludes_dir}", str(nbs_dir)])
def test_cli(tmp_path: Path) -> None:
with chdir(tmp_path):
shutil.copytree(nbs_dir, "notebooks")
main([f"--preludes={preludes_dir}", "notebooks"])
assert Path("notebooks/r.txt").read_text() == "6"

0 comments on commit 16ceeb9

Please sign in to comment.