-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise10_lock_screen_unittest.py
More file actions
63 lines (45 loc) · 1.75 KB
/
exercise10_lock_screen_unittest.py
File metadata and controls
63 lines (45 loc) · 1.75 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
#!/usr/bin/env python
"""You are tasked with testing a lock screen pin pad for a smartphone.
We need you to create a test script that automates a test case where you set
the lock screen PIN, push the number buttons to unlock the device based on the
PIN, then ensure that the lock screen is unlocked. This should be done with the
following PINs: 1234, 0000, 9999, 1470. You can use the following APIs for the
lock screen below. Feel free to add new APIs to this if needed."""
"""class LockScreen {
void set_pin(int pin)
void lock_device()
boolean is_locked()
void press_number(int number)
}"""
import unittest
import logging
import time
import LockScreen (???from class/file_name import function: e.g. from LockScreen import set_pin)
class TestLockScreenAPI(unittest.TestCase):
log = logging.getLogger("TestLockScreenAPI.test_lock_screen_unlock")
logging.basicConfig()
log.setLevel(logging.INFO)
def setUp(self):
pins=[1234, 0000, 9999, 1470]
lock_screen=LockScreen()
#self.lock_screen=LockScreen(), then replace all the following lock_screen with self. lock_screen
lock_screen.lock_device()
#assert lock_screen.is_locked() == True
self.assertTrue(lock_screen.is_locked())
def tearDown(self):
pins=[]
lock_screen=None
def test_lock_screen_unlock(self):
for num in pins:
lock_screen.set_pin(num)
log.info("Pin is %d:" % num)
lock_screen.press_number(num)
time.sleep(2)
#assert lock_screen.is_locked()==False
self.assertFalse(lock_screen.is_locked())
if __name__ == '__main__':
unittest.main()
"""if __name__ == "__main__":
logging.basicConfig( stream=sys.stderr )
logging.getLogger( "TestLockScreenAPI.test_lock_screen_unlock" ).setLevel( logging.DEBUG )
unittest.main()***