forked from tompreston/python-lirc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
52 lines (41 loc) · 1.48 KB
/
tests.py
File metadata and controls
52 lines (41 loc) · 1.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
import os
import sys
import time
import unittest
parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, parentdir + "/build/lib.linux-armv6l-3.2/")
import lirc
class TestNextCode(unittest.TestCase):
"""General use tests (not really in the spirit of unittesting)."""
def setUp(self):
lirc.init("lirctest", "tests/lircrc.test")
def test_nextcode(self):
print("Press 1 on your remote.")
self.assertEqual(lirc.nextcode(), ["horses"])
def tearDown(self):
lirc.deinit()
class TestNonBlocking(unittest.TestCase):
"""Tests the non blocking setting."""
def setUp(self):
lirc.init("lirctest", "tests/lircrc.test", blocking=False)
def test_nonblocking_nextcode(self):
print("Don't press anything yet...")
start_time = time.time()
end_time = start_time + 1 # 1 second in the future
pressed = False
while not pressed and time.time() < end_time:
if lirc.nextcode() == ["horses"]:
pressed = True
self.assertFalse(pressed)
print("Press 1 on your remote.")
start_time = time.time()
end_time = start_time + 5 # 5 seconds in the future
pressed = False
while not pressed and time.time() < end_time:
if lirc.nextcode() == ["horses"]:
pressed = True
self.assertTrue(pressed)
def tearDown(self):
lirc.deinit()
if __name__ == "__main__":
unittest.main()