pytest plugin for testing TUI and regular command-line applications.
Project description
What is this?
pytest_tuitest is a pytest plugin for testing TUI (text/terminal user interface) and regular command-line applications.
It allows you to run an application in a virtual terminal and run assertions on the contents and colors of its output. It uses pyte for terminal emulation.
What can it do?
Here are some examples to give you a taste of what can be done.
import pytest_tuitest as tt
# You can simply run an application and verify that it prints
# the expected output in the terminal.
@tt.test_executable("grep")
@tt.with_arguments(["--color=always", "pytest_tuitest"])
@tt.with_stdin("This is a pytest_tuitest demo")
def test_grep_marks_the_output_according_to_arguments(terminal):
terminal.wait_for_finished()
# You can get the text in the terminal
assert terminal.get_string_at(line=0, column=10, length=14) == "pytest_tuitest"
# The color
assert terminal.get_foreground_at(line=0, column=10) == tt.Color16.RED
assert terminal.get_background_at(line=0, column=10) == tt.Color16.DEFAULT
# Or the font style
assert not terminal.has_style_at(line=0, column=10, style=tt.Style.BLINKING)
# You can also send stdin and capture stdout. Capturing stdout
# is useful in cases where TUI is printed on TTY and something
# else is printed on stdout (e.g. in case of fzf). That way, you
# can independently check what's in the TUI and what's "returned".
@tt.test_executable("fzf")
@tt.with_terminal_size(columns=80, lines=40)
@tt.with_stdin("things\nstuff")
@tt.with_captured_stdout(True)
def test_sending_input_and_capturing_output(terminal):
terminal.wait_for_stable_output()
assert terminal.get_string_at(line=39, column=0, length=1) == ">"
# Emulate typing of "th" and pressing enter
terminal.send("th\r\n")
(status, stdout, _) = terminal.wait_for_finished()
assert status == 0
assert stdout == "things\n"
Installation
pip install pytest-tuitest
This will automatically install pytest as well.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_tuitest-0.1.0.tar.gz.
File metadata
- Download URL: pytest_tuitest-0.1.0.tar.gz
- Upload date:
- Size: 26.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08117075273daaa510436679d63c720d60bc5481abe37340a83010051c75dcdf
|
|
| MD5 |
bdc3183735988562cbe2299e2a371d80
|
|
| BLAKE2b-256 |
e0169be83112a0b622a93811a05bfa71ab1d74f3ad87e7232765b7a10cbd2ac6
|
File details
Details for the file pytest_tuitest-0.1.0-py2.py3-none-any.whl.
File metadata
- Download URL: pytest_tuitest-0.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 14.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a52e3530e1083c949deab2305098e07239fafdc20a9cd2526e49815975f5b85e
|
|
| MD5 |
91e23f23cf1dd27b6907e0a73d49fa18
|
|
| BLAKE2b-256 |
3df963f99a174eec0820007ced0786d43533636434c44edc876a294ce64971ed
|