-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_testing.py
More file actions
77 lines (63 loc) · 2.48 KB
/
example_testing.py
File metadata and controls
77 lines (63 loc) · 2.48 KB
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
from kibot import Kibot, KibotTestCase, run_kibot_tests
from kivy.factory import Factory
class KibotTestExample(KibotTestCase):
def test_button_text_equals_pressed(self):
"""Test that my_button has proper text after one click/touch """
kibot = self.kibot
# find button by tag property
my_button = kibot.find(text="Kibot Test")
kibot.do_click(widget=my_button) # click my button
kibot.wait_until() # wait until all events are executed
# always call this before asserts
self.assertEqual(my_button.text, "Pressed!")
def test_textinput(self):
"""Test that my_textinput has proper text after keyboard input"""
kibot = self.kibot
my_textinput = kibot.find(class_="TextInput")
kibot.do_click(widget=my_textinput)
kibot.do_keystroke(text="hello") # Sends hello using keyboard
kibot.do_keystroke(key="enter") # Simulates Enter key
kibot.do_keystroke(text="world")
kibot.wait_until() # wait until all events are executed
self.assertEqual(my_textinput.text, "hello\nworld")
def test_slider_and_label(self):
"""Test that slider has proper value and label has proper text after
touch"""
kibot = self.kibot
my_slider = kibot.find(class_="Slider")
my_label = kibot.find(class_="Label")
# touch at x=79% of widget's width, and y=50% of widget's height
# relative to widget's position
kibot.do_press(widget=my_slider, x=0.0, y=0.5)
for i in range(80):
kibot.do_move(widget=my_slider, x=i / 100., y=0.5)
kibot.do_release(widget=my_slider, x=0.0, y=0.5)
kibot.wait_until()
# On my pc that touch sets slider value to 80
self.assertEqual(my_slider.value, 80)
self.assertEqual(my_label.text, "80.0")
if __name__ == '__main__':
# A kibot testing example
from kivy.app import App
from kivy.lang import Builder
kv = """
<RootWidget@BoxLayout>:
orientation: 'vertical'
BoxLayout:
Button:
text: "Kibot Test"
on_press: self.text="Pressed!"
TextInput:
Slider:
step: 1
on_value: _lbl.text="%s"%(self.value)
Label:
id: _lbl
size_hint_y: 0.1
"""
class TestApp(App):
def build(self):
return Factory.RootWidget()
Builder.load_string(kv)
app = TestApp() # Do not run the app!
run_kibot_tests(app) # This runs the app and calls unittest.main()