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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
import sys
import pytest
from sdl2 import SDL_Window
from sdl2 import ext as sdl2ext
from sdl2 import messagebox as mb
class TestSDL2ExtGUI(object):
__tags__ = ["sdl", "sdl2ext"]
@classmethod
def setup_class(cls):
try:
sdl2ext.init()
except sdl2ext.SDLError:
raise pytest.skip('Video subsystem not supported')
@classmethod
def teardown_class(cls):
sdl2ext.quit()
def test_MessageBoxTheme(self):
# Test using RGB color tuples
theme = sdl2ext.MessageBoxTheme(text=(255, 255, 255))
text_col = theme._get_theme().colors[1]
assert text_col.r == 255 and text_col.g == 255
# Test using Color objects
BLACK = sdl2ext.Color(0, 0, 0)
theme = sdl2ext.MessageBoxTheme(btn=BLACK)
btn_col = theme._get_theme().colors[3]
assert btn_col.r == 0 and btn_col.b == 0
# Test exceptions on bad input
with pytest.raises(TypeError):
sdl2ext.MessageBoxTheme(bg=(255, 255))
with pytest.raises(ValueError):
sdl2ext.MessageBoxTheme(bg=(256, 255, 255))
def test_MessageBox(self):
# Test initialization of the class
box = sdl2ext.MessageBox(
"Test", "Did it work?", ["Yes", "No"], default="Yes", msgtype="info"
)
sdl_box = box._get_msgbox()
assert sdl_box.flags & mb.SDL_MESSAGEBOX_INFORMATION
assert sdl_box.title.decode('utf-8') == "Test"
assert sdl_box.message.decode('utf-8') == "Did it work?"
assert sdl_box.numbuttons == 2
b1 = sdl_box.buttons.contents # Only gets first button for some reason
assert b1.text.decode('utf-8') == "Yes"
assert b1.flags & mb.SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT
# Test internal generation w/ an associated window
win = sdl2ext.Window(b"Test", (640, 480))
sdl_box = box._get_msgbox(win)
assert isinstance(sdl_box.window.contents, SDL_Window)
win.close()
# Test initialization with theme
mbtheme = sdl2ext.MessageBoxTheme(text=(255, 0, 0))
box2 = sdl2ext.MessageBox(
"Test", "Did it work?", ["Yes", "No"], theme=mbtheme
)
sdl_box2 = box2._get_msgbox()
text_col = sdl_box2.colorScheme.contents.colors[1]
assert text_col.r == 255 and text_col.g == 0
# Test exceptions on bad input
with pytest.raises(TypeError):
sdl2ext.MessageBox("Title", "Some text", "A button")
with pytest.raises(ValueError):
sdl2ext.MessageBox("Title", "Some text", [])
with pytest.raises(ValueError):
box._get_window_pointer("not a window")
@pytest.mark.skip("not implemented, requires GUI interaction")
def test_show_messagebox(self):
# Could implement a test using mock, but not sure how useful that'd be
pass
@pytest.mark.skip("not implemented, requires GUI interaction")
def test_show_alert(self):
pass
@pytest.mark.skip("not implemented")
def test_UIFactory(self):
pass
@pytest.mark.skip("not implemented")
def test_UIFactory_create_button(self):
pass
@pytest.mark.skip("not implemented")
def test_UIFactory_create_checkbutton(self):
pass
@pytest.mark.skip("not implemented")
def test_UIFactory_create_text_entry(self):
pass
@pytest.mark.skip("not implemented")
def test_Button(self):
pass
@pytest.mark.skip("not implemented")
def test_CheckButton(self):
pass
@pytest.mark.skip("not implemented")
def test_TextEntry(self):
pass
@pytest.mark.skip("not implemented")
def test_UIProcessor(self):
pass
@pytest.mark.skip("not implemented")
def test_UIProcessor_activate(self):
pass
@pytest.mark.skip("not implemented")
def test_UIProcessor_deactivate(self):
pass
@pytest.mark.skip("not implemented")
def test_UIProcessor_dispatch(self):
pass
@pytest.mark.skip("not implemented")
def test_UIProcessor_mousedown(self):
pass
@pytest.mark.skip("not implemented")
def test_UIProcessor_mouseup(self):
pass
@pytest.mark.skip("not implemented")
def test_UIProcessor_mousemotion(self):
pass
@pytest.mark.skip("not implemented")
def test_UIProcessor_passevent(self):
pass
@pytest.mark.skip("not implemented")
def test_UIProcessor_process(self):
pass
@pytest.mark.skip("not implemented")
def test_UIProcessor_textinput(self):
pass
|