-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
93 lines (74 loc) · 3.21 KB
/
test.py
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
import framebuf
from segclock import Clock
import unittest
class SegClockTestCase(unittest.TestCase):
@staticmethod
def _bytes_to_bytearray(value):
return bytearray(
b''.join(map(
lambda x: int.to_bytes(x, 1, 'big'),
value
))
)
def test__clock_initialization(self):
fbuf = None # mock
clock = Clock(fbuf, 100, 100)
def test__clock_init__too_small_screen__raise_exc(self):
fbuf = None # mock
try:
Clock(fbuf, 100, 100)
except Exception as e:
self.assertIsInstance(e, Clock.TooSmallDimensionsException)
def test__clock_draw__minimal_dimentions__correct_clock_state_after_drawing(self):
data = bytearray(40*10//8)
fbuf = framebuf.FrameBuffer(data, 40, 10, framebuf.MONO_HLSB)
clock = Clock(fbuf, 40, 10)
clock.draw(13, 29)
self.assertEqual(
clock._state,
(1, 3, 1, 2, 9),
)
def test__clock_draw__minimal_dimentions__correct_fbuf_values(self):
data = bytearray(40*10//8)
fbuf = framebuf.FrameBuffer(data, 40, 10, framebuf.MONO_HLSB)
clock = Clock(fbuf, 40, 10)
clock.draw(88, 88)
correct_result = self._bytes_to_bytearray((
0b11111100, 0b11111100, 0b00001111, 0b11001111, 0b11000000,
0b11111100, 0b11111100, 0b00001111, 0b11001111, 0b11000000,
0b11001100, 0b11001100, 0b11001100, 0b11001100, 0b11000000,
0b11001100, 0b11001100, 0b11001100, 0b11001100, 0b11000000,
0b11111100, 0b11111100, 0b00001111, 0b11001111, 0b11000000,
0b11111100, 0b11111100, 0b00001111, 0b11001111, 0b11000000,
0b11001100, 0b11001100, 0b11001100, 0b11001100, 0b11000000,
0b11001100, 0b11001100, 0b11001100, 0b11001100, 0b11000000,
0b11111100, 0b11111100, 0b00001111, 0b11001111, 0b11000000,
0b11111100, 0b11111100, 0b00001111, 0b11001111, 0b11000000,
))
self.assertEqual(
data,
correct_result,
)
def test__clock_draw__without_colon__correct_fbuf_values(self):
data = bytearray(40*10//8)
fbuf = framebuf.FrameBuffer(data, 40, 10, framebuf.MONO_HLSB)
clock = Clock(fbuf, 40, 10)
clock.draw(88, 88, False)
correct_result = self._bytes_to_bytearray((
0b11111100, 0b11111100, 0b00001111, 0b11001111, 0b11000000,
0b11111100, 0b11111100, 0b00001111, 0b11001111, 0b11000000,
0b11001100, 0b11001100, 0b00001100, 0b11001100, 0b11000000,
0b11001100, 0b11001100, 0b00001100, 0b11001100, 0b11000000,
0b11111100, 0b11111100, 0b00001111, 0b11001111, 0b11000000,
0b11111100, 0b11111100, 0b00001111, 0b11001111, 0b11000000,
0b11001100, 0b11001100, 0b00001100, 0b11001100, 0b11000000,
0b11001100, 0b11001100, 0b00001100, 0b11001100, 0b11000000,
0b11111100, 0b11111100, 0b00001111, 0b11001111, 0b11000000,
0b11111100, 0b11111100, 0b00001111, 0b11001111, 0b11000000,
))
self.assertEqual(
data,
correct_result,
)
if __name__ == '__main__':
unittest.main()