This repository was archived by the owner on Jul 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_test.py
More file actions
94 lines (67 loc) · 2.37 KB
/
Copy pathrun_test.py
File metadata and controls
94 lines (67 loc) · 2.37 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#! /usr/bin/env python3
from sys import argv
from time import sleep
def test_fullscreen_print():
from time import sleep
from lib_common import fullscreen_print
counter = 100
while counter > 0:
fullscreen_print(str(counter))
counter -= 1
sleep(0.01)
def test_log_line():
from lib_common import log_line
def write_test(log_file):
log_line(log_file, "Started log test.")
for line in range(5):
log_line(log_file, "Test line " + str(line))
for line in range(5):
log_line(log_file, "Test warn line " + str(line), level="warn")
for line in range(5):
log_line(log_file, "Test indented line " + str(line), indent=4)
for line in range(5):
log_line(log_file, "Test indented warn line " + str(line), level="warn", indent=4)
log_line(log_file, "Finished log test.")
with open("logs/test_a.txt", "a") as log_file:
write_test(log_file)
with open("logs/test_aplus.txt", "a+") as log_file:
write_test(log_file)
with open("logs/test_wplus.txt", "w+") as log_file:
write_test(log_file)
def test_solenoid_pin():
import RPi.GPIO as GPIO
from time import sleep
PULSE_INTERVAL = 2
PULSE_DURATION = 4
SOLENOID_PIN = 4
GPIO.setmode(GPIO.BCM) # Set mode to broadcom
GPIO.setup(SOLENOID_PIN, GPIO.OUT) # Set pin mode to output
while True:
GPIO.output(SOLENOID_PIN, True)
sleep(PULSE_DURATION)
GPIO.output(SOLENOID_PIN, GPIO.OUT)
sleep(PULSE_INTERVAL)
test_map = {
"figlet": test_fullscreen_print,
"logger": test_log_line,
"solenoid": test_solenoid_pin
}
if len(argv) > 1:
exceptions = {}
print("Starting", len(argv) - 1, "test" + ("s." if len(argv) - 1 > 1 else "."))
for test in argv[1:]:
if test in test_map:
try:
print("Starting test:", test)
sleep(2)
test_map[test]()
except Exception as error:
exceptions[test] = error
print("Failed with exception:", error)
else:
print("Test not found:", test)
print("Completed tests:", ", ".join(argv[1:]), "\n", len(exceptions), "failed.")
if exceptions:
print("\nExceptions:\n")
for test, error in exceptions.items():
print(test + ":\n", error)