Skip to content
Open
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
39 changes: 39 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Tests

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest pytest-asyncio mypy
pip install .[dev]
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 devlog --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 devlog --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Check typing with mypy
run: |
mypy devlog
- name: Test with pytest
run: |
pytest -v
77 changes: 77 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import pytest
import devlog.cli as cli

from typer.testing import CliRunner

runner = CliRunner()


@pytest.fixture(autouse=True)
def clean_env(tmp_path, monkeypatch):
sessions_dir = tmp_path / "sessions"

monkeypatch.setattr("pathlib.Path.home", lambda: tmp_path)

monkeypatch.setattr("devlog.cli.DATA_DIR", sessions_dir)
monkeypatch.setattr("devlog.cli.CURRENT", tmp_path / "current.json")

sessions_dir.mkdir(parents=True, exist_ok=True)

yield

for file in tmp_path.iterdir():
if file.is_file():
file.unlink()


def test_start_create_session():
result = runner.invoke(cli.app, ["start"])
assert result.exit_code == 0
assert "✅ Session started" in result.stdout
assert cli.CURRENT.exists()


def test_start_already_active_session():
cli.CURRENT.write_text("hello world")
result = runner.invoke(cli.app, ["start"])
assert "[DEVLOG] session already in progress." in result.stdout


def test_note():
runner.invoke(cli.app, ["start"])
result = runner.invoke(cli.app, ["note", "Hello Test"])
assert "[LOG]📝 Note recorded." in result.stdout


def test_note_no_session():
result = runner.invoke(cli.app, ["note", "Hello Test"])
assert "[DEVLOG] No current session active." in result.stdout


def test_stop():
runner.invoke(cli.app, ["start"])
result = runner.invoke(cli.app, ["stop"])
assert "[DEVLOG] ✅ Session ended." in result.stdout


def test_stop_no_session():
result = runner.invoke(cli.app, ["stop"])
assert "[DEVLOG] No current session active." in result.stdout


def test_export_markdown():
result = runner.invoke(cli.app, ["export", "md"])
assert "[LOG] 🚀 Logs exported" in result.stdout


def test_export_html():
result = runner.invoke(cli.app, ["export", "html"])
assert "[LOG] ✅ Data moved to HTML" in result.stdout


def test_export_fail():
cli.CURRENT.write_text("hello world")
result = runner.invoke(cli.app, ["export", "md"])

assert "[DEVLOG] Session active. Stop it before exporting." \
in result.stdout
Loading