Coverage for test_configuration_updates.py: 97%
96 statements
« prev ^ index » next coverage.py v7.2.7, created at 2024-04-10 15:08 +0100
« prev ^ index » next coverage.py v7.2.7, created at 2024-04-10 15:08 +0100
1#-----------------------------------------------------------------------------------
2# System tests for configuration update functions. This module calls directly into
3# the required editor functions to update and apply configuration changes rather
4# than using the system test harness functions
5#-----------------------------------------------------------------------------------
7import system_test_harness
8from system_test_harness import *
9from model_railway_signals.editor import settings
11#-----------------------------------------------------------------------------------
12# Test the GPIO Configuration update functions
13#-----------------------------------------------------------------------------------
15def test_gpio_configuration_update_functions(delay:float=0.0):
16 initial_settings = settings.get_gpio()
17 # Initial mappings for test_run_layout.sig' are 1-2-1 mappings
18 assert initial_settings[2] == []
19 # Create the initial gpio sensor objects [sensor_id, gpio_port]
20 run_function(lambda:settings.set_gpio(mappings=[[1,4], [2,5], [3,6], [4,7], [5,8], [6,9], [7,10], [8,11]]))
21 run_function(lambda:system_test_harness.main_menubar.gpio_update(), delay=0.5)
22 # Create the other library objects and assign the gpio sensors:
23 s1 = create_colour_light_signal()
24 s2 = create_colour_light_signal()
25 ts1 = create_track_sensor()
26 ts2 = create_track_sensor()
27 update_object_configuration(get_object_id("signal",1),{"approachsensor":[True,"1"],"passedsensor":[True,"2"]})
28 update_object_configuration(get_object_id("signal",2),{"approachsensor":[True,"3"],"passedsensor":[True,"4"]})
29 update_object_configuration(get_object_id("tracksensor",1),{"passedsensor":"5"})
30 update_object_configuration(get_object_id("tracksensor",2),{"passedsensor":"6"})
31 simulate_gpio_triggered(4)
32 sleep(delay)
33 simulate_gpio_triggered(5)
34 sleep(delay)
35 simulate_gpio_triggered(6)
36 sleep(delay)
37 simulate_gpio_triggered(7)
38 sleep(delay)
39 simulate_gpio_triggered(8)
40 sleep(delay)
41 simulate_gpio_triggered(9)
42 sleep(delay)
43 # Update the mappings and APPLY - signal and track sensor config remains unchanged
44 run_function(lambda:settings.set_gpio(mappings=[[1,4], [2,5], [3,6], [4,7], [5,8], [6,9]]))
45 run_function(lambda:system_test_harness.main_menubar.gpio_update(), delay=0.5)
46 assert_object_configuration(get_object_id("signal",1),{"approachsensor":[True,"1"],"passedsensor":[True,"2"]})
47 assert_object_configuration(get_object_id("signal",2),{"approachsensor":[True,"3"],"passedsensor":[True,"4"]})
48 assert_object_configuration(get_object_id("tracksensor",1),{"passedsensor":"5"})
49 assert_object_configuration(get_object_id("tracksensor",2),{"passedsensor":"6"})
50 simulate_gpio_triggered(4)
51 sleep(delay)
52 simulate_gpio_triggered(5)
53 sleep(delay)
54 simulate_gpio_triggered(6)
55 sleep(delay)
56 simulate_gpio_triggered(7)
57 sleep(delay)
58 simulate_gpio_triggered(8)
59 sleep(delay)
60 simulate_gpio_triggered(9)
61 sleep(delay)
62 # Update the mappings and APPLY - signal and track sensor config remains unchanged
63 run_function(lambda:settings.set_gpio(mappings=[[1,9], [2,8], [3,7], [4,6], [5,5], [6,4]]), delay=0.2)
64 run_function(lambda:system_test_harness.main_menubar.gpio_update(), delay=0.8)
65 assert_object_configuration(get_object_id("signal",1),{"approachsensor":[True,"1"],"passedsensor":[True,"2"]})
66 assert_object_configuration(get_object_id("signal",2),{"approachsensor":[True,"3"],"passedsensor":[True,"4"]})
67 assert_object_configuration(get_object_id("tracksensor",1),{"passedsensor":"5"})
68 assert_object_configuration(get_object_id("tracksensor",2),{"passedsensor":"6"})
69 simulate_gpio_triggered(4)
70 sleep(delay)
71 simulate_gpio_triggered(5)
72 sleep(delay)
73 simulate_gpio_triggered(6)
74 sleep(delay)
75 simulate_gpio_triggered(7)
76 sleep(delay)
77 simulate_gpio_triggered(8)
78 sleep(delay)
79 simulate_gpio_triggered(9)
80 sleep(delay)
81 # Update the mappings and APPLY - This time the signal and track sensor config should change
82 run_function(lambda:settings.set_gpio(mappings=[[1,4], [2,5], [3,6], [4,7], [5,8]]), delay=0.2)
83 run_function(lambda:system_test_harness.main_menubar.gpio_update(), delay=0.8)
84 assert_object_configuration(get_object_id("signal",1),{"approachsensor":[True,"1"],"passedsensor":[True,"2"]})
85 assert_object_configuration(get_object_id("signal",2),{"approachsensor":[True,"3"],"passedsensor":[True,"4"]})
86 assert_object_configuration(get_object_id("tracksensor",1),{"passedsensor":"5"})
87 assert_object_configuration(get_object_id("tracksensor",2),{"passedsensor":""})
88 # Update the mappings and APPLY - This time the signal and track sensor config should change
89 run_function(lambda:settings.set_gpio(mappings=[[2,5], [3,6], [4,7], [5,8]]), delay=0.2)
90 run_function(lambda:system_test_harness.main_menubar.gpio_update(), delay=0.8)
91 assert_object_configuration(get_object_id("signal",1),{"approachsensor":[True,""],"passedsensor":[True,"2"]})
92 assert_object_configuration(get_object_id("signal",2),{"approachsensor":[True,"3"],"passedsensor":[True,"4"]})
93 assert_object_configuration(get_object_id("tracksensor",1),{"passedsensor":"5"})
94 assert_object_configuration(get_object_id("tracksensor",2),{"passedsensor":""})
95 # Update the mappings and APPLY - This time the signal and track sensor config should change
96 run_function(lambda:settings.set_gpio(mappings=[[2,5], [3,6], [5,8]]), delay=0.2)
97 run_function(lambda:system_test_harness.main_menubar.gpio_update(), delay=0.8)
98 assert_object_configuration(get_object_id("signal",1),{"approachsensor":[True,""],"passedsensor":[True,"2"]})
99 assert_object_configuration(get_object_id("signal",2),{"approachsensor":[True,"3"],"passedsensor":[True,""]})
100 assert_object_configuration(get_object_id("tracksensor",1),{"passedsensor":"5"})
101 assert_object_configuration(get_object_id("tracksensor",2),{"passedsensor":""})
102 # Update the mappings and APPLY - This time the signal and track sensor config should change
103 run_function(lambda:settings.set_gpio(mappings=[]), delay=0.2)
104 run_function(lambda:system_test_harness.main_menubar.gpio_update(), delay=0.8)
105 assert_object_configuration(get_object_id("signal",1),{"approachsensor":[True,""],"passedsensor":[True,""]})
106 assert_object_configuration(get_object_id("signal",2),{"approachsensor":[True,""],"passedsensor":[True,""]})
107 assert_object_configuration(get_object_id("tracksensor",1),{"passedsensor":""})
108 assert_object_configuration(get_object_id("tracksensor",2),{"passedsensor":""})
109 return()
111######################################################################################################
113def run_all_configuration_update_tests(shutdown:bool=False, delay:float=0):
114 initialise_test_harness()
115 set_edit_mode()
116 test_gpio_configuration_update_functions(delay)
117 if shutdown: report_results()
119if __name__ == "__main__": 119 ↛ 120line 119 didn't jump to line 120, because the condition on line 119 was never true
120 start_application(lambda:run_all_configuration_update_tests(shutdown=True, delay=1.0))
122###############################################################################################################################