Skip to content

Commit ad9c066

Browse files
committed
adde unit tests for Popup Message
1 parent b22c4ae commit ad9c066

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Tests/test_input_handlers.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
LookHandler,
1919
SingleRangedAttackHandler,
2020
AreaRangedAttackHandler,
21+
PopupMessage,
2122
)
2223

2324
from actions import (
@@ -102,6 +103,40 @@ def test_ev_quit(self):
102103
with self.assertRaises(SystemExit):
103104
eh.ev_quit(event=event)
104105

106+
class Test_PopupMessage(unittest.TestCase):
107+
def test_init(self):
108+
'''
109+
test that the popup message can be initialized correctly
110+
'''
111+
pop = PopupMessage(parent_handler=BaseEventHandler(), text="string")
112+
self.assertIsInstance(pop.parent, BaseEventHandler)
113+
self.assertEqual(pop.text, "string")
114+
115+
def test_on_render(self):
116+
'''
117+
verify that the parent is rendered as expected then an additional print is
118+
called with the correct parameters
119+
'''
120+
pop = PopupMessage(parent_handler=BaseEventHandler(), text="string")
121+
console = Console(width=10, height=10, order='F')
122+
123+
with patch('input_handlers.BaseEventHandler.on_render') as patch_on_render:
124+
with patch('tcod.console.Console.print') as patch_print:
125+
pop.on_render(console=console)
126+
127+
patch_on_render.assert_called_once()
128+
patch_print.assert_called_with(5, 5, "string", fg=color.white, bg=color.black, alignment=tcod.CENTER)
129+
130+
def test_ev_keydown(self):
131+
'''
132+
verify that sending a keydown will return the parent
133+
'''
134+
pop = PopupMessage(parent_handler=BaseEventHandler(), text="string")
135+
event = tcod.event.KeyDown(
136+
scancode=tcod.event.Scancode.UP, sym=tcod.event.K_UP, mod=tcod.event.Modifier.NONE
137+
)
138+
ret = pop.ev_keydown(event=event)
139+
self.assertIsInstance(ret, BaseEventHandler)
105140

106141
class Test_EventHandler(unittest.TestCase):
107142
def test_init(self):

0 commit comments

Comments
 (0)