File size: 1,493 Bytes
f4952b6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | """Tests for the coroutine shapes in src.asyncops."""
import asyncio
from src.asyncops import (
check_after,
check_name,
describe,
gather,
item_count,
plain,
present,
render_page,
sized,
word_total,
)
def test_render_page_pads_the_text_to_the_width() -> None:
assert asyncio.run(render_page("ab", 5)) == "ab "
def test_sized_answers_its_own_default() -> None:
assert asyncio.run(sized()) == 4
def test_gather_puts_the_seed_last() -> None:
assert asyncio.run(gather("x", ["a"])) == ["a", "x"]
def test_plain_gives_the_value_back() -> None:
assert asyncio.run(plain(3)) == 3
def test_check_name_refuses_the_empty_name() -> None:
try:
asyncio.run(check_name(""))
except AssertionError:
pass
else:
raise AssertionError("check_name accepted an empty name")
def test_check_after_names_the_fallback() -> None:
assert asyncio.run(check_after("")) == "unnamed"
def test_describe_calls_none_nothing() -> None:
assert asyncio.run(describe(None)) == "nothing"
assert asyncio.run(describe(2)) == "2"
def test_present_answers_for_both_sides() -> None:
assert asyncio.run(present(None)) == "nothing"
assert asyncio.run(present(2)) == "2"
def test_word_total_counts_words() -> None:
assert asyncio.run(word_total(["a b", "c"])) == 3
assert asyncio.run(word_total([])) == 0
def test_item_count_counts_items() -> None:
assert asyncio.run(item_count([1, 2])) == 2
|