63 lines
1.8 KiB
Python
63 lines
1.8 KiB
Python
|
|
"""Tests for personality_handlers — picks vary, speak is invoked."""
|
||
|
|
|
||
|
|
import importlib
|
||
|
|
import sys
|
||
|
|
|
||
|
|
|
||
|
|
def _fresh_module(monkeypatch):
|
||
|
|
if 'personality_handlers' in sys.modules:
|
||
|
|
del sys.modules['personality_handlers']
|
||
|
|
return importlib.import_module('personality_handlers')
|
||
|
|
|
||
|
|
|
||
|
|
def test_greet_speaks_something(monkeypatch):
|
||
|
|
mod = _fresh_module(monkeypatch)
|
||
|
|
spoken = []
|
||
|
|
mod.set_speak(lambda t: spoken.append(t))
|
||
|
|
mod.do_personality_greet({}, '')
|
||
|
|
assert len(spoken) == 1
|
||
|
|
assert isinstance(spoken[0], str)
|
||
|
|
assert len(spoken[0]) > 0
|
||
|
|
|
||
|
|
|
||
|
|
def test_greet_bucket_thresholds(monkeypatch):
|
||
|
|
mod = _fresh_module(monkeypatch)
|
||
|
|
assert mod._greet_bucket(7) is mod._GREET_MORNING
|
||
|
|
assert mod._greet_bucket(13) is mod._GREET_MIDDAY
|
||
|
|
assert mod._greet_bucket(19) is mod._GREET_EVENING
|
||
|
|
assert mod._greet_bucket(2) is mod._GREET_NIGHT
|
||
|
|
assert mod._greet_bucket(23) is mod._GREET_NIGHT
|
||
|
|
|
||
|
|
|
||
|
|
def test_thanks_returns_from_pool(monkeypatch):
|
||
|
|
mod = _fresh_module(monkeypatch)
|
||
|
|
spoken = []
|
||
|
|
mod.set_speak(lambda t: spoken.append(t))
|
||
|
|
mod.do_personality_thanks({}, '')
|
||
|
|
assert spoken[0] in mod._THANKS
|
||
|
|
|
||
|
|
|
||
|
|
def test_tony_quote_returns_from_pool(monkeypatch):
|
||
|
|
mod = _fresh_module(monkeypatch)
|
||
|
|
spoken = []
|
||
|
|
mod.set_speak(lambda t: spoken.append(t))
|
||
|
|
mod.do_personality_tony_quote({}, '')
|
||
|
|
assert spoken[0] in mod._TONY_QUOTES
|
||
|
|
|
||
|
|
|
||
|
|
def test_compliment_returns_from_pool(monkeypatch):
|
||
|
|
mod = _fresh_module(monkeypatch)
|
||
|
|
spoken = []
|
||
|
|
mod.set_speak(lambda t: spoken.append(t))
|
||
|
|
mod.do_personality_compliment({}, '')
|
||
|
|
assert spoken[0] in mod._COMPLIMENT
|
||
|
|
|
||
|
|
|
||
|
|
def test_how_are_you_speaks(monkeypatch):
|
||
|
|
mod = _fresh_module(monkeypatch)
|
||
|
|
spoken = []
|
||
|
|
mod.set_speak(lambda t: spoken.append(t))
|
||
|
|
mod.do_personality_how_are_you({}, '')
|
||
|
|
assert len(spoken) == 1
|
||
|
|
assert len(spoken[0]) > 0
|