Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions tests/e2e/commands/test_check.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
from ..runner import BinaryRunner
from ..result import RunResult


def test_check_git(runner: BinaryRunner) -> None:
def test_check_git(check_results: RunResult) -> None:
"""check git command output indicates git is installed and configured."""
res = runner.run(["check", "git"])
res.assert_success()
res.assert_stdout_contains("Git is installed and configured")
check_results.assert_stdout_contains("Git is installed and configured")


def test_check_github(runner: BinaryRunner) -> None:
def test_check_github(check_results: RunResult) -> None:
"""check github command output indicates Github CLI is installed and configured."""
res = runner.run(["check", "github"])
res.assert_success()
res.assert_stdout_contains("Github CLI is installed and configured")
check_results.assert_stdout_contains("Github CLI is installed and configured")
29 changes: 7 additions & 22 deletions tests/e2e/commands/test_progress.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,23 @@
import json
from pathlib import Path
import pytest

from ..runner import BinaryRunner
from ..result import RunResult


def test_progress_show(runner: BinaryRunner, gitmastery_root: Path) -> None:
def test_progress_show(progress_results: RunResult) -> None:
"""progress show displays the progress header."""
res = runner.run(["progress", "show"], cwd=gitmastery_root)
res.assert_success()
res.assert_stdout_contains("Your Git-Mastery progress:")
progress_results.assert_stdout_contains("Your Git-Mastery progress:")


def test_progress_sync_on_then_off(runner: BinaryRunner, gitmastery_root: Path) -> None:
def test_progress_sync_on_then_off(progress_results: RunResult, gitmastery_root: Path) -> None:
"""progress sync on/off toggles progress_remote in the config."""
res_on = runner.run(["progress", "sync", "on"], cwd=gitmastery_root)
res_on.assert_success()
res_on.assert_stdout_contains("You have setup the progress tracker for Git-Mastery!")
assert json.loads((gitmastery_root / ".gitmastery.json").read_text())["progress_remote"] is True

# send 'y' to confirm
res_off = runner.run(
["progress", "sync", "off"], cwd=gitmastery_root, stdin_text="y\n"
)
res_off.assert_success()
res_off.assert_stdout_contains("Successfully removed your remote sync")
progress_results.assert_stdout_contains("You have setup the progress tracker for Git-Mastery!")
progress_results.assert_stdout_contains("Successfully removed your remote sync")
assert json.loads((gitmastery_root / ".gitmastery.json").read_text())["progress_remote"] is False


@pytest.mark.order(after="tests/e2e/commands/test_verify.py::test_verify_exercise")
def test_progress_reset(runner: BinaryRunner, verified_exercise_dir: Path) -> None:
def test_progress_reset(reset_results: RunResult, verified_exercise_dir: Path) -> None:
"""progress reset removes the current exercise's entry from progress.json."""
res = runner.run(["progress", "reset"], cwd=verified_exercise_dir)
res.assert_success()
progress_json = verified_exercise_dir.parent / "progress" / "progress.json"
# TODO: need to verify that the exercise itself progress was reset, not just progress.json was cleared
assert json.loads(progress_json.read_text()) == []
33 changes: 33 additions & 0 deletions tests/e2e/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .constants import EXERCISE_NAME, HANDS_ON_NAME
from .utils import rmtree
from .runner import BinaryRunner
from .result import RunResult


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -82,3 +83,35 @@ def verified_exercise_dir(runner: BinaryRunner, downloaded_exercise_dir: Path) -
res = runner.run(["verify"], cwd=downloaded_exercise_dir)
res.assert_success()
return downloaded_exercise_dir


@pytest.fixture(scope="session")
def check_results(runner: BinaryRunner) -> RunResult:
"""version + check git/github — no setup required."""
return runner.run_repl_session([
(["version"], None),
(["check", "git"], None),
(["check", "github"], None),
])


@pytest.fixture(scope="session")
def progress_results(runner: BinaryRunner, gitmastery_root: Path) -> RunResult:
"""progress show + sync commands — requires gitmastery_root setup."""
return runner.run_repl_session(
[
(["progress", "show"], None),
(["progress", "sync", "on"], None),
(["progress", "sync", "off"], "y\n"),
],
cwd=gitmastery_root,
)


@pytest.fixture(scope="session")
def reset_results(runner: BinaryRunner, verified_exercise_dir: Path) -> RunResult:
"""progress reset — requires verified exercise."""
return runner.run_repl_session(
[(["progress", "reset"], None)],
cwd=verified_exercise_dir,
)
22 changes: 21 additions & 1 deletion tests/e2e/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import subprocess
from dataclasses import dataclass
from pathlib import Path
from typing import Dict, Optional, Sequence, Self
from typing import Dict, List, Optional, Sequence, Self, Tuple
from .result import RunResult


Expand Down Expand Up @@ -71,3 +71,23 @@ def run(
returncode=proc.returncode,
command=cmd,
)

def run_repl_session(
self,
commands: List[Tuple[List[str], Optional[str]]],
*,
cwd: Optional[Path] = None,
timeout: int = 60,
) -> RunResult:
"""Run multiple commands in one REPL session via stdin.

Each entry is (args, stdin_fragment) where stdin_fragment is optional
extra input appended after the command (e.g. "y\\n" for confirmations).
EOF on stdin exits the REPL cleanly via do_EOF.
"""
lines: List[str] = []
for args, fragment in commands:
lines.append("gitmastery " + " ".join(args) + "\n")
if fragment:
lines.append(fragment)
return self.run([], cwd=cwd, timeout=timeout, stdin_text="".join(lines))
10 changes: 4 additions & 6 deletions tests/e2e/test_version.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from .runner import BinaryRunner
from .result import RunResult


def test_version(runner: BinaryRunner) -> None:
def test_version(check_results: RunResult) -> None:
"""Test the version command output."""
res = runner.run(["version"])
res.assert_success()
res.assert_stdout_contains("Git-Mastery app is")
res.assert_stdout_matches(r"v\d+\.\d+\.\d+")
check_results.assert_stdout_contains("Git-Mastery app is")
check_results.assert_stdout_matches(r"v\d+\.\d+\.\d+")
Loading