tests: add a bunch of tests; refactor helper structures
This commit is contained in:
parent
736fd02b50
commit
3268de32ea
1 changed files with 52 additions and 23 deletions
75
tests.py
75
tests.py
|
|
@ -1,4 +1,3 @@
|
||||||
from typing import TypedDict
|
|
||||||
import pytest
|
import pytest
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
@ -7,23 +6,14 @@ from teilchensammler_cli.models import TeilchenCreate, make_teilchen_input
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.final # don't run while we are fiddling with the app
|
||||||
def test_initial_layout(snap_compare):
|
def test_initial_layout(snap_compare):
|
||||||
from teilchensammler_cli.main import app
|
from teilchensammler_cli.main import app
|
||||||
|
|
||||||
assert snap_compare(app, terminal_size=(130, 40))
|
assert snap_compare(app, terminal_size=(130, 40))
|
||||||
|
|
||||||
|
|
||||||
class Teilchen(TypedDict):
|
empty_teilchen = {
|
||||||
"""The things I do for my LSP..."""
|
|
||||||
|
|
||||||
name: str
|
|
||||||
description: str
|
|
||||||
tags: str
|
|
||||||
text: str
|
|
||||||
number: int
|
|
||||||
|
|
||||||
|
|
||||||
empty_teilchen: Teilchen = {
|
|
||||||
"name": "",
|
"name": "",
|
||||||
"description": "",
|
"description": "",
|
||||||
"tags": "",
|
"tags": "",
|
||||||
|
|
@ -32,23 +22,62 @@ empty_teilchen: Teilchen = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def TC(**kwargs) -> TeilchenCreate | None:
|
||||||
|
"""TC = TeilchenCreate
|
||||||
|
|
||||||
|
Create Teilchen with desired attributes.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
input: mapping that must be well-formed enough to actually create a Teilchen
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
- `None` on empty input
|
||||||
|
- an instance of `TeilchenCreate`
|
||||||
|
"""
|
||||||
|
if kwargs:
|
||||||
|
arguments = empty_teilchen | kwargs
|
||||||
|
return TeilchenCreate(**arguments) # ty:ignore[invalid-argument-type]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"example_input,expected",
|
"example_input,expected",
|
||||||
[
|
[
|
||||||
("", None),
|
# Not enough data
|
||||||
("a", None),
|
("", TC()),
|
||||||
("a.", {"name": "a", "text": "a."}),
|
(".", TC()),
|
||||||
("aa", None),
|
("..", TC()),
|
||||||
("aa.", {"name": "aa", "text": "aa."}),
|
(".a.", TC()),
|
||||||
|
("a", TC()),
|
||||||
|
("aa", TC()),
|
||||||
|
# Just enough for "name"
|
||||||
|
("a.", TC(name="a", text="a.")),
|
||||||
|
("aa.", TC(name="aa", text="aa.")),
|
||||||
|
("a..", TC(name="a", text="a..")),
|
||||||
|
("a.b.", TC(name="a", text="a.b.")),
|
||||||
|
# Just enough for "name" and "description"
|
||||||
|
('a."b"', TC(name="a", description="b", text='a."b"')),
|
||||||
|
('a. "b"', TC(name="a", description="b", text='a. "b"')),
|
||||||
|
('a. ""', TC(name="a", description="", text='a. ""')),
|
||||||
|
('. ""', TC()),
|
||||||
|
('. "b"', TC()),
|
||||||
|
# Just enough for "name" and "description" and "tags"
|
||||||
|
('a. "b" #c', TC(name="a", description="b", tags="#c", text='a. "b" #c')),
|
||||||
|
('a. "b #d" #c', TC(name="a", description="b #d", tags="#c #d", text='a. "b #d" #c')),
|
||||||
|
# swap order in input, tag result is stable
|
||||||
|
('a. "b #c" #d', TC(name="a", description="b #c", tags="#c #d", text='a. "b #c" #d')),
|
||||||
|
# Just enough for "name" and "tags"
|
||||||
|
("a. #d", TC(name="a", description="", tags="#d", text="a. #d")),
|
||||||
|
("a. #d#b", TC(name="a", description="", tags="#b #d", text="a. #d#b")),
|
||||||
|
("a. ##b", TC(name="a", description="", tags="#b", text="a. ##b")),
|
||||||
|
("a. #", TC(name="a", description="", tags="", text="a. #")),
|
||||||
|
("a. ##", TC(name="a", description="", tags="", text="a. ##")),
|
||||||
|
# do we care about "number"?
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_teilchendata_must_include_period(
|
async def test_maketeilcheninput_can_create_desired_teilchen(
|
||||||
example_input: str, expected: dict[str, str | int] | None
|
example_input: str, expected: dict[str, str | int] | None
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
||||||
thing = expected
|
actual = await make_teilchen_input(example_input)
|
||||||
if expected:
|
|
||||||
arguments = empty_teilchen | expected
|
|
||||||
thing = TeilchenCreate(**arguments) # ty:ignore[invalid-argument-type]
|
|
||||||
|
|
||||||
assert await make_teilchen_input(example_input) == thing
|
assert expected == actual
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue