Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic testing with PyTest #26

Merged
merged 1 commit into from
Jun 7, 2024
Merged
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
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ This is a terminal application that allows developers to generate logos for thei
- [PDM](https://pdm-project.org/en/latest/) for development scripts and managing (dev)dependencies.
- [Ruff](https://docs.astral.sh/ruff/) for linting and formatting
- [Pyright](https://microsoft.github.io/pyright/#/) for type checking
- [Pytest](https://docs.pytest.org/) for unit tests

You can install PDM with the following command:

Expand All @@ -116,6 +117,19 @@ cd ./octo-logo
pdm install
```

- You must configure your IDE to use the project's venv or your extensions will fail to resolve the dependencies.

- If you use a command line editor (like vim), you can activate the venv in your shell session then start vim.

> [!CAUTION]
> This command must be run everytime you open a new shell session.

```bash
# Activating the project's venv (linux)
eval $(pdm venv activate)
vim
```

## Files and directories 📂

__Configuration Files:__ ⚙
Expand All @@ -132,6 +146,7 @@ __Source:__ 🔢
__Other:__ 📄

- `assets/`: Assets for the GitHub repo only.
- `tests/`: Unit test files (pytest).

## Creating a pull request 👍

Expand All @@ -151,6 +166,12 @@ pdm run lint # Check for linting errors
pdm run check-types # Check for type errors
```

- You also have to run tests to check if your changes didn't break anything

```bash
pdm run tests
```

- After that, add your changes to `CHANGELOG.md` and update the README if needed.

- Do not increment the module version yourself, the maintainer will do it.
Expand All @@ -172,3 +193,4 @@ git push -u origin my-new-feature
- `lint`: Checks for linting errors and fixes them if possible.
- `lint-check`: Check for linting errors and exits with error code if any is found.
- `check-types`: Check for type errors with Pyright.
- `tests`: Run all unit tests.
121 changes: 94 additions & 27 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ dependencies = [
"textual==0.38.1",
"click-extra==4.7.2",
"loguru==0.7.2",
"pyright>=1.1.365",
]

[project.urls]
Expand All @@ -34,6 +33,9 @@ distribution = true
[tool.pdm.dev-dependencies]
dev = [
"ruff>=0.4.7",
"pytest>=8.2.2",
"pytest-asyncio>=0.23.7",
"pyright>=1.1.365",
]

[tool.pdm.scripts]
Expand All @@ -42,3 +44,4 @@ format-check = "ruff format --check"
lint = "ruff check --fix --show-fixes"
lint-check = "ruff check"
check-types = "pyright"
tests = "pytest"
31 changes: 31 additions & 0 deletions tests/test_no_errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pytest

# The project's venv must be activated, so that
# Octologo is imported directly from src/octologo
from octologo.__main__ import OctoLogoApp


@pytest.mark.asyncio
async def test_no_errors() -> None:
app = OctoLogoApp()
async with app.run_test() as pilot:
await pilot.pause()

keypress_sequences = [
# Enter project name
("M", "y", "P", "r", "o", "j", "e", "c", "t", "enter"),
# select default style (just click next)
("tab", "tab", "enter"),
# select default font
("tab", "enter"),
# select default color scheme
("tab", "tab", "enter"),
# default value for the next 6 questions
("enter",) * 6,
]

for keys in keypress_sequences:
await pilot.press(*keys)
await pilot.pause()

# The test ends before the image gets generated