Skip to content

Commit fafecf7

Browse files
committed
added more test for cli.py
test for: - note - stop - export md - export html
1 parent ba03162 commit fafecf7

File tree

1 file changed

+40
-7
lines changed

1 file changed

+40
-7
lines changed

tests/test_cli.py

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
import pytest
2+
import devlog.cli as cli
23

34
from typer.testing import CliRunner
4-
from devlog.cli import app
5-
import devlog.cli as cli
65

76
runner = CliRunner()
87

98

109
@pytest.fixture(autouse=True)
1110
def clean_env(tmp_path, monkeypatch):
1211
sessions_dir = tmp_path / "sessions"
12+
13+
monkeypatch.setattr("pathlib.Path.home", lambda: tmp_path)
14+
1315
monkeypatch.setattr("devlog.cli.DATA_DIR", sessions_dir)
1416
monkeypatch.setattr("devlog.cli.CURRENT", tmp_path / "current.json")
15-
sessions_dir.mkdir(parents=True)
17+
18+
sessions_dir.mkdir(parents=True, exist_ok=True)
1619

1720
yield
1821

@@ -22,23 +25,53 @@ def clean_env(tmp_path, monkeypatch):
2225

2326

2427
def test_start_create_session():
25-
result = runner.invoke(app, ["start"])
28+
result = runner.invoke(cli.app, ["start"])
2629
assert result.exit_code == 0
2730
assert "✅ Session started" in result.stdout
2831
assert cli.CURRENT.exists()
2932

3033

3134
def test_start_already_active_session():
3235
cli.CURRENT.write_text("hello world")
33-
result = runner.invoke(app, ["start"])
36+
result = runner.invoke(cli.app, ["start"])
3437
assert "[DEVLOG] session already in progress." in result.stdout
3538

3639

40+
def test_note():
41+
runner.invoke(cli.app, ["start"])
42+
result = runner.invoke(cli.app, ["note", "Hello Test"])
43+
assert "[LOG]📝 Note recorded." in result.stdout
44+
45+
3746
def test_note_no_session():
38-
result = runner.invoke(app, ["note", "Hello Test"])
47+
result = runner.invoke(cli.app, ["note", "Hello Test"])
3948
assert "[DEVLOG] No current session active." in result.stdout
4049

4150

51+
def test_stop():
52+
runner.invoke(cli.app, ["start"])
53+
result = runner.invoke(cli.app, ["stop"])
54+
assert "[DEVLOG] ✅ Session ended." in result.stdout
55+
56+
4257
def test_stop_no_session():
43-
result = runner.invoke(app, ["stop"])
58+
result = runner.invoke(cli.app, ["stop"])
4459
assert "[DEVLOG] No current session active." in result.stdout
60+
61+
62+
def test_export_markdown():
63+
result = runner.invoke(cli.app, ["export", "md"])
64+
assert "[LOG] 🚀 Logs exported" in result.stdout
65+
66+
67+
def test_export_html():
68+
result = runner.invoke(cli.app, ["export", "html"])
69+
assert "[LOG] ✅ Data moved to HTML" in result.stdout
70+
71+
72+
def test_export_fail():
73+
cli.CURRENT.write_text("hello world")
74+
result = runner.invoke(cli.app, ["export", "md"])
75+
76+
assert "[DEVLOG] Session active. Stop it before exporting." \
77+
in result.stdout

0 commit comments

Comments
 (0)