-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_camStates.py
142 lines (99 loc) · 3.81 KB
/
test_camStates.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
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
from unittest import TestCase
import cv2
import cam_states
class TestCamStates(TestCase):
def test_get_state_high_motion_set_true(self):
cs = cam_states.CamStates()
cs.state = 'dreaming'
ret = cs.get_state(cs.HIGH_THRESHOLD + 1)
assert ret == 'show_frames'
assert cs.motion
def test_get_state_low_motion_true_starts_time(self):
cs = cam_states.CamStates()
cs.motion = True
ret = cs.get_state(cs.LOW_THRESHOLD - 1)
assert ret == 'waiting'
assert cv2.getTickCount() - cs.start_time < 5000
assert not cs.motion
def test_get_state_low_motion_false_long_time(self):
cs = cam_states.CamStates()
cs.motion = False
cs.start_time = 0
ret = cs.get_state(cs.LOW_THRESHOLD - 1)
assert ret == 'waiting'
assert not cs.motion
def test_get_state_starts_waiting(self):
cs = cam_states.CamStates()
cs.get_state(cs.LOW_THRESHOLD)
cs.get_state(cs.LOW_THRESHOLD)
cs.get_state(cs.LOW_THRESHOLD)
ret = cs.get_state(cs.LOW_THRESHOLD)
assert ret == 'waiting'
assert not cs.motion
def test_get_state_start_dreaming_high_threshold(self):
cs = cam_states.CamStates()
cs.motion = False
cs.start_time = 0
cs.state = 'not waiting'
cs.get_state(cs.HIGH_THRESHOLD + 1)
ret = cs.get_state(cs.LOW_THRESHOLD - 1)
assert cs.motion_threshold == cs.HIGH_THRESHOLD
assert ret == 'dreaming'
assert cs.motion
def test_get_state_motion_high_stays_high_threshold(self):
cs = cam_states.CamStates()
cs.motion = False
cs.state = 'dreaming'
cs.motion_threshold = cs.HIGH_THRESHOLD
cs.get_state(cs.HIGH_THRESHOLD + 1)
assert cs.motion_threshold == cs.HIGH_THRESHOLD
def test_get_state_dream_over_fade_to_frame_and_fading(self):
cs = cam_states.CamStates()
cs.motion = False
cs.state = 'dreaming'
cs.dream_start = cv2.getTickCount() - cs.DREAM_OVER - 1
cs.start_time = cv2.getTickCount() - 500000000 - 1
ret = cs.get_state(cs.LOW_THRESHOLD - 1)
assert ret == 'fade_dream_to_frame'
ret = cs.get_state(cs.LOW_THRESHOLD - 1)
assert ret == 'fading'
assert cs.beta == 0.0
def test_get_state_start_up_nothing_until_high_motion(self):
cs = cam_states.CamStates()
ret = cs.get_state(cs.LOW_THRESHOLD + 1)
assert ret == 'waiting'
assert cs.motion_threshold == cs.HIGH_THRESHOLD
assert not cs.motion
def test_get_state_waiting_at_startup(selfself):
cs = cam_states.CamStates()
ret = cs.get_state(cs.HIGH_THRESHOLD - 1)
assert not cs.motion
assert ret == 'waiting'
def test_get_state_beta_updates_fading(self):
cs = cam_states.CamStates()
cs.state = 'fade_dream_to_frame'
ret = cs.get_state(0)
assert ret == 'fading'
assert cs.beta == 0.0
cs.get_state(0)
assert cs.beta == 1.0 / cs.fade_iterations
cs.get_state(0)
cs.get_state(0)
cs.get_state(0)
assert cs.beta == 4.0 / cs.fade_iterations
def test_get_state_fade_over_to_show_frames(self):
cs = cam_states.CamStates()
cs.state = 'fade_dream_to_frame'
cs.get_state(0)
cs.get_state(0)
cs.fade_iter = 81.0
ret = cs.get_state(0)
assert ret == "show_frames"
assert cs.fade_iter == 0.0 # This must be reset
assert cs.beta == 0.0
def test_get_state_no_motion_time_up_to_waiting(self):
cs = cam_states.CamStates()
cs.state = 'dreaming'
cs.low_motion_last_time = cv2.getTickCount() - cs.LOW_MOTION_TIMEOUT - 1000000000
ret = cs.get_state(0)
assert ret == 'waiting'