"""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