Procházet zdrojové kódy

Added test_sink script

To replace my old Sink testing system (GNU Screen and a text file with
the commands to send to the Sink), I wrote a Python script that tests
the Sink automatically.  The only thing I have to do (assuming the test
is successful) is press Enter a few times while watching a voltmeter's
display.  A basic testing script could be useful to other people, so I'm
including it in this Python package.

I have a vague plan to integrate this with Kaylee at some point so I
don't even have to press Enter, but that will have to wait until Kaylee
has menu support.
Clara Hobbs před 7 roky
rodič
revize
43810cf6ba
2 změnil soubory, kde provedl 97 přidání a 0 odebrání
  1. 0
    0
      pdbuddy/tools/__init__.py
  2. 97
    0
      pdbuddy/tools/test_sink.py

+ 0
- 0
pdbuddy/tools/__init__.py Zobrazit soubor


+ 97
- 0
pdbuddy/tools/test_sink.py Zobrazit soubor

@@ -0,0 +1,97 @@
1
+"""Test a freshly-flashed PD Buddy Sink"""
2
+
3
+import argparse
4
+import sys
5
+
6
+import pdbuddy
7
+
8
+
9
+class ExitCode:
10
+    configuration_error = 1
11
+    wrong_output = 2
12
+
13
+
14
+def write_verify(sink, cfg):
15
+    """Write a SinkConfig to a Sink and verify that it was written"""
16
+    sink.set_tmpcfg(cfg)
17
+    sink.write()
18
+
19
+    actual_cfg = sink.get_cfg()
20
+    if actual_cfg != cfg:
21
+        print('Configuration error; expected config:')
22
+        print(cfg)
23
+        print('actual config:')
24
+        print(actual_cfg)
25
+        sys.exit(ExitCode.configuration_error)
26
+
27
+
28
+def output_verify(sink):
29
+    """Verify that the Sink's output is correct"""
30
+    # Get the configured voltage
31
+    voltage = sink.get_cfg().v
32
+    if voltage is None:
33
+        voltage = 0
34
+
35
+    answer = input("Is the Sink's output stable at {:.1f} V [Y,n]? ".format(
36
+        voltage/1000. * sink.output))
37
+    if answer.lower().startswith('n'):
38
+        print('Wrong output, exiting.')
39
+        sys.exit(ExitCode.wrong_output)
40
+
41
+
42
+def main():
43
+    # Make the argument parser
44
+    parser = argparse.ArgumentParser(description='Test a PD Buddy Sink')
45
+    parser.add_argument('tty', metavar='tty', type=str, help="the Sink's tty")
46
+
47
+    # Parse arguments
48
+    args = parser.parse_args()
49
+
50
+    # Define configurations for testing
51
+    cfg_20v = pdbuddy.SinkConfig(status=pdbuddy.SinkStatus.VALID,
52
+            flags=pdbuddy.SinkFlags.NONE, v=20000, i=1000)
53
+    cfg_9v = pdbuddy.SinkConfig(status=pdbuddy.SinkStatus.VALID,
54
+            flags=pdbuddy.SinkFlags.NONE, v=9000, i=1000)
55
+
56
+    # Run the testing procedure
57
+    with pdbuddy.Sink(args.tty) as sink:
58
+        # Make sure output is disabled to start
59
+        sink.output = False
60
+
61
+        # Set initial configuration
62
+        print('Writing 20 V configuration object…')
63
+        write_verify(sink, cfg_20v)
64
+        print('Done.')
65
+
66
+        # Turn on the output and ensure that it's correct
67
+        sink.output = True
68
+        output_verify(sink)
69
+
70
+        # Turn off the output and ensure that it's off
71
+        sink.output = False
72
+        output_verify(sink)
73
+
74
+        # Turn on the output again and ensure that it's back at 20 V
75
+        sink.output = True
76
+        output_verify(sink)
77
+
78
+        # Set second configuration
79
+        print('Writing 9 V configuration object…')
80
+        write_verify(sink, cfg_9v)
81
+        print('Done.')
82
+
83
+        # Ensure that the output is 9 V now
84
+        output_verify(sink)
85
+
86
+        # Erase the sink's configuration
87
+        sink.erase()
88
+
89
+        # Ensure there's no output despite it being enabled
90
+        sink.output = True
91
+        output_verify(sink)
92
+
93
+    # Congratulations, all tests passed!
94
+    print('Test successful!')
95
+
96
+if __name__ == '__main__':
97
+    main()

Loading…
Zrušit
Uložit