Skip to content

Commit ba03162

Browse files
committed
init cli file unittest
1 parent e0855bc commit ba03162

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

tests/test_cli.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import pytest
2+
3+
from typer.testing import CliRunner
4+
from devlog.cli import app
5+
import devlog.cli as cli
6+
7+
runner = CliRunner()
8+
9+
10+
@pytest.fixture(autouse=True)
11+
def clean_env(tmp_path, monkeypatch):
12+
sessions_dir = tmp_path / "sessions"
13+
monkeypatch.setattr("devlog.cli.DATA_DIR", sessions_dir)
14+
monkeypatch.setattr("devlog.cli.CURRENT", tmp_path / "current.json")
15+
sessions_dir.mkdir(parents=True)
16+
17+
yield
18+
19+
for file in tmp_path.iterdir():
20+
if file.is_file():
21+
file.unlink()
22+
23+
24+
def test_start_create_session():
25+
result = runner.invoke(app, ["start"])
26+
assert result.exit_code == 0
27+
assert "✅ Session started" in result.stdout
28+
assert cli.CURRENT.exists()
29+
30+
31+
def test_start_already_active_session():
32+
cli.CURRENT.write_text("hello world")
33+
result = runner.invoke(app, ["start"])
34+
assert "[DEVLOG] session already in progress." in result.stdout
35+
36+
37+
def test_note_no_session():
38+
result = runner.invoke(app, ["note", "Hello Test"])
39+
assert "[DEVLOG] No current session active." in result.stdout
40+
41+
42+
def test_stop_no_session():
43+
result = runner.invoke(app, ["stop"])
44+
assert "[DEVLOG] No current session active." in result.stdout

0 commit comments

Comments
 (0)