11import json
22from pathlib import Path
33
4- from ..constants import EXERCISE_NAME , HANDS_ON_NAME
5- from ..runner import BinaryRunner
4+ from ..constants import EXERCISE_NAME
65
76
87def test_download_exercise (downloaded_exercise_dir : Path ) -> None :
@@ -19,68 +18,3 @@ def test_download_exercise(downloaded_exercise_dir: Path) -> None:
1918def test_download_hands_on (downloaded_hands_on_dir : Path ) -> None :
2019 """download creates the hands-on folder."""
2120 assert downloaded_hands_on_dir .is_dir ()
22-
23-
24- def test_download_blocks_when_already_downloaded (
25- runner : BinaryRunner , gitmastery_root : Path , downloaded_exercise_dir : Path
26- ) -> None :
27- """download refuses to overwrite an existing exercise folder."""
28- sentinel = downloaded_exercise_dir / "NOTES.md"
29- sentinel .write_text ("local work" )
30-
31- try :
32- res = runner .run (["download" , EXERCISE_NAME ], cwd = gitmastery_root )
33-
34- assert res .returncode != 0 , (
35- f"Expected a non-zero exit code, got { res .returncode } \n "
36- f"stdout:\n { res .stdout } "
37- )
38- res .assert_stdout_contains ("already have" )
39- res .assert_stdout_contains ("--force" )
40-
41- assert sentinel .is_file ()
42- assert sentinel .read_text () == "local work"
43- finally :
44- sentinel .unlink ()
45-
46-
47- def test_download_hands_on_blocks_when_already_downloaded (
48- runner : BinaryRunner , gitmastery_root : Path , downloaded_hands_on_dir : Path
49- ) -> None :
50- """download refuses to overwrite an existing hands-on folder."""
51- sentinel = downloaded_hands_on_dir / "NOTES.md"
52- sentinel .write_text ("local work" )
53-
54- try :
55- res = runner .run (["download" , HANDS_ON_NAME ], cwd = gitmastery_root )
56-
57- assert res .returncode != 0 , (
58- f"Expected a non-zero exit code, got { res .returncode } \n "
59- f"stdout:\n { res .stdout } "
60- )
61- res .assert_stdout_contains ("--force" )
62-
63- assert sentinel .is_file ()
64- finally :
65- sentinel .unlink ()
66-
67-
68- def test_download_force_overwrites (
69- runner : BinaryRunner , isolated_gitmastery_root : Path
70- ) -> None :
71- """download --force wipes the existing exercise folder and downloads it again."""
72- runner .run (
73- ["download" , EXERCISE_NAME ], cwd = isolated_gitmastery_root
74- ).assert_success ()
75-
76- exercise_dir = isolated_gitmastery_root / EXERCISE_NAME
77- sentinel = exercise_dir / "NOTES.md"
78- sentinel .write_text ("local work" )
79-
80- runner .run (
81- ["download" , EXERCISE_NAME , "--force" ], cwd = isolated_gitmastery_root
82- ).assert_success ()
83-
84- assert not sentinel .exists ()
85- assert (exercise_dir / ".gitmastery-exercise.json" ).is_file ()
86- assert (exercise_dir / "README.md" ).is_file ()
0 commit comments