-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
test_coffee.py
48 lines (33 loc) · 1.15 KB
/
test_coffee.py
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
import logging
from unittest.mock import patch
import pytest
from sanic.application.logo import COFFEE_LOGO, get_logo
from sanic.exceptions import SanicException
def has_sugar(value):
if value:
raise SanicException("I said no sugar please")
return False
@pytest.mark.parametrize("sugar", (True, False))
def test_no_sugar(sugar):
if sugar:
with pytest.raises(SanicException):
assert has_sugar(sugar)
else:
assert not has_sugar(sugar)
def test_get_logo_returns_expected_logo():
with patch("sys.stdout.isatty") as isatty:
isatty.return_value = True
logo = get_logo(coffee=True)
assert logo is COFFEE_LOGO
def test_logo_true(app, caplog):
@app.after_server_start
async def shutdown(*_):
app.stop()
with patch("sys.stdout.isatty") as isatty:
isatty.return_value = True
with caplog.at_level(logging.DEBUG):
app.make_coffee(single_process=True)
# Only in the regular logo
assert " ▄███ █████ ██ " not in caplog.text
# Only in the coffee logo
assert " ██ ██▀▀▄ " in caplog.text