MTPPy2.0 0.1.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. examples/__init__.py +0 -0
  2. examples/minimal+pid.py +82 -0
  3. examples/minimal.py +32 -0
  4. examples/minimal_recipe.py +117 -0
  5. examples/pea_alarm_base.py +47 -0
  6. examples/pea_minimal.py +258 -0
  7. mtppy/__init__.py +1 -0
  8. mtppy/part1/__init__.py +4 -0
  9. mtppy/part1/empty_folder_test.py +7 -0
  10. mtppy/part3/__init__.py +4 -0
  11. mtppy/part3/data_assembly_set/__init__.py +4 -0
  12. mtppy/part3/data_assembly_set/active_elements/__init__.py +4 -0
  13. mtppy/part3/data_assembly_set/active_elements/active_element.py +22 -0
  14. mtppy/part3/data_assembly_set/active_elements/drives/__init__.py +4 -0
  15. mtppy/part3/data_assembly_set/active_elements/drives/ana_drv.py +446 -0
  16. mtppy/part3/data_assembly_set/active_elements/drives/ana_drv_test.py +567 -0
  17. mtppy/part3/data_assembly_set/active_elements/drives/bin_drv.py +365 -0
  18. mtppy/part3/data_assembly_set/active_elements/drives/bin_drv_test.py +503 -0
  19. mtppy/part3/data_assembly_set/active_elements/drives/mon_ana_drv.py +469 -0
  20. mtppy/part3/data_assembly_set/active_elements/drives/mon_ana_drv_test.py +418 -0
  21. mtppy/part3/data_assembly_set/active_elements/drives/mon_bin_drv.py +295 -0
  22. mtppy/part3/data_assembly_set/active_elements/drives/mon_bin_drv_test.py +265 -0
  23. mtppy/part3/data_assembly_set/active_elements/pid/__init__.py +4 -0
  24. mtppy/part3/data_assembly_set/active_elements/pid/pid_ctrl.py +333 -0
  25. mtppy/part3/data_assembly_set/active_elements/pid/pid_ctrl_test.py +156 -0
  26. mtppy/part3/data_assembly_set/active_elements/valves/__init__.py +4 -0
  27. mtppy/part3/data_assembly_set/active_elements/valves/ana_vlv.py +402 -0
  28. mtppy/part3/data_assembly_set/active_elements/valves/ana_vlv_test.py +732 -0
  29. mtppy/part3/data_assembly_set/active_elements/valves/bin_vlv.py +279 -0
  30. mtppy/part3/data_assembly_set/active_elements/valves/bin_vlv_test.py +585 -0
  31. mtppy/part3/data_assembly_set/active_elements/valves/mon_ana_vlv.py +402 -0
  32. mtppy/part3/data_assembly_set/active_elements/valves/mon_ana_vlv_test.py +270 -0
  33. mtppy/part3/data_assembly_set/active_elements/valves/mon_bin_vlv.py +286 -0
  34. mtppy/part3/data_assembly_set/active_elements/valves/mon_bin_vlv_test.py +224 -0
  35. mtppy/part3/data_assembly_set/base_functions/__init__.py +4 -0
  36. mtppy/part3/data_assembly_set/base_functions/operation_mode.py +252 -0
  37. mtppy/part3/data_assembly_set/base_functions/operation_mode_test.py +260 -0
  38. mtppy/part3/data_assembly_set/base_functions/oslevel.py +35 -0
  39. mtppy/part3/data_assembly_set/base_functions/source_mode.py +189 -0
  40. mtppy/part3/data_assembly_set/base_functions/source_mode_test.py +112 -0
  41. mtppy/part3/data_assembly_set/base_functions/wqc.py +75 -0
  42. mtppy/part3/data_assembly_set/base_functions/wqc_test.py +86 -0
  43. mtppy/part3/data_assembly_set/data_assembly.py +65 -0
  44. mtppy/part3/data_assembly_set/diagnostic_elements/__init__.py +4 -0
  45. mtppy/part3/data_assembly_set/diagnostic_elements/diagnostic_element.py +19 -0
  46. mtppy/part3/data_assembly_set/indicator_elements/__init__.py +4 -0
  47. mtppy/part3/data_assembly_set/indicator_elements/indicator_element.py +22 -0
  48. mtppy/part3/data_assembly_set/indicator_elements/views/__init__.py +4 -0
  49. mtppy/part3/data_assembly_set/indicator_elements/views/ana_view.py +68 -0
  50. mtppy/part3/data_assembly_set/indicator_elements/views/bin_view.py +73 -0
  51. mtppy/part3/data_assembly_set/indicator_elements/views/dint_view.py +76 -0
  52. mtppy/part3/data_assembly_set/indicator_elements/views/string_view.py +55 -0
  53. mtppy/part3/data_assembly_set/operation_elements/__init__.py +4 -0
  54. mtppy/part3/data_assembly_set/operation_elements/operation_element.py +19 -0
  55. mtppy/part3/data_assembly_set/pea_elements/__init__.py +4 -0
  56. mtppy/part3/data_assembly_set/pea_elements/pea_element.py +28 -0
  57. mtppy/part3/data_assembly_set/pea_elements/pea_information_label/__init__.py +4 -0
  58. mtppy/part3/data_assembly_set/pea_elements/pea_information_label/pea_information_label.py +231 -0
  59. mtppy/part3/data_assembly_set/pea_elements/web_server_url_info/__init__.py +4 -0
  60. mtppy/part3/data_assembly_set/pea_elements/web_server_url_info/web_server_url_info.py +42 -0
  61. mtppy/part3/definitions/__init__.py +4 -0
  62. mtppy/part3/definitions/mtp_access.py +15 -0
  63. mtppy/part4/__init__.py +4 -0
  64. mtppy/part4/automation_services/__init__.py +4 -0
  65. mtppy/part4/automation_services/base_functions/__init__.py +4 -0
  66. mtppy/part4/automation_services/base_functions/service_operation_mode.py +368 -0
  67. mtppy/part4/automation_services/base_functions/service_operation_mode_test.py +242 -0
  68. mtppy/part4/automation_services/base_functions/service_operator_interaction.py +62 -0
  69. mtppy/part4/automation_services/base_functions/service_source_mode.py +138 -0
  70. mtppy/part4/automation_services/base_functions/service_source_mode_test.py +179 -0
  71. mtppy/part4/automation_services/helpers/__init__.py +4 -0
  72. mtppy/part4/automation_services/helpers/command_en_control.py +330 -0
  73. mtppy/part4/automation_services/helpers/command_en_control_test.py +302 -0
  74. mtppy/part4/automation_services/helpers/state_machine.py +167 -0
  75. mtppy/part4/automation_services/helpers/state_machine_test.py +294 -0
  76. mtppy/part4/automation_services/helpers/thread_control.py +39 -0
  77. mtppy/part4/automation_services/helpers/thread_control_test.py +80 -0
  78. mtppy/part4/automation_services/procedure.py +111 -0
  79. mtppy/part4/automation_services/procedure_test.py +185 -0
  80. mtppy/part4/automation_services/service.py +463 -0
  81. mtppy/part4/automation_services/service_elements/__init__.py +4 -0
  82. mtppy/part4/automation_services/service_elements/parameter_elements/__init__.py +4 -0
  83. mtppy/part4/automation_services/service_elements/parameter_elements/ana_serv_param.py +108 -0
  84. mtppy/part4/automation_services/service_elements/parameter_elements/ana_serv_param_test.py +59 -0
  85. mtppy/part4/automation_services/service_elements/parameter_elements/bin_serv_param.py +70 -0
  86. mtppy/part4/automation_services/service_elements/parameter_elements/bin_serv_param_test.py +39 -0
  87. mtppy/part4/automation_services/service_elements/parameter_elements/common_serv_param.py +111 -0
  88. mtppy/part4/automation_services/service_elements/parameter_elements/dint_serv_param.py +77 -0
  89. mtppy/part4/automation_services/service_elements/parameter_elements/dint_serv_param_test.py +58 -0
  90. mtppy/part4/automation_services/service_elements/parameter_elements/parameter_element.py +175 -0
  91. mtppy/part4/automation_services/service_elements/parameter_elements/parameter_element_test.py +246 -0
  92. mtppy/part4/automation_services/service_elements/parameter_elements/string_serv_param.py +48 -0
  93. mtppy/part4/automation_services/service_elements/parameter_elements/string_serv_param_test.py +37 -0
  94. mtppy/part4/automation_services/service_elements/procedure_health_view.py +36 -0
  95. mtppy/part4/automation_services/service_elements/service_control.py +473 -0
  96. mtppy/part4/automation_services/service_elements/service_control_test.py +150 -0
  97. mtppy/part4/automation_services/service_elements/service_element.py +20 -0
  98. mtppy/part4/automation_services/service_test.py +407 -0
  99. mtppy/part4/definitions/__init__.py +4 -0
  100. mtppy/part4/definitions/command_codes.py +58 -0
  101. mtppy/part4/definitions/command_codes_test.py +44 -0
  102. mtppy/part4/definitions/state_codes.py +65 -0
  103. mtppy/part4/definitions/state_codes_test.py +44 -0
  104. mtppy/part4/process_values/__init__.py +4 -0
  105. mtppy/part4/process_values/base_functions/__init__.py +4 -0
  106. mtppy/part4/process_values/base_functions/vqc.py +48 -0
  107. mtppy/part4/process_values/input_elements/__init__.py +4 -0
  108. mtppy/part4/process_values/input_elements/ana_process_value_in.py +160 -0
  109. mtppy/part4/process_values/input_elements/bin_process_value_in.py +83 -0
  110. mtppy/part4/process_values/input_elements/dint_process_value_in.py +159 -0
  111. mtppy/part4/process_values/input_elements/input_element.py +40 -0
  112. mtppy/part4/process_values/input_elements/string_process_value_in.py +45 -0
  113. mtppy/part5/__init__.py +4 -0
  114. mtppy/part5/communication_object.py +99 -0
  115. mtppy/part5/communication_object_test.py +59 -0
  116. mtppy/part5/definitions/__init__.py +4 -0
  117. mtppy/part5/definitions/iec61131_data_types.py +31 -0
  118. mtppy/part5/definitions/iec61131_data_types_test.py +82 -0
  119. mtppy/part5/definitions/opcua_data_types.py +36 -0
  120. mtppy/part5/definitions/opcua_data_types_test.py +90 -0
  121. mtppy/part5/definitions/w3c_xml_data_types.py +177 -0
  122. mtppy/part5/definitions/w3c_xml_data_types_test.py +143 -0
  123. mtppy/part5/server_assembly_set/__init__.py +5 -0
  124. mtppy/part6/__init__.py +4 -0
  125. mtppy/part6/alarm_set/__init__.py +4 -0
  126. mtppy/part6/alarm_set/alarm.py +132 -0
  127. mtppy/part6/alarm_set/alarm_test.py +265 -0
  128. mtppy/pea/__init__.py +19 -0
  129. mtppy/pea/data_assembly_factory.py +124 -0
  130. mtppy/pea/data_assembly_factory_test.py +229 -0
  131. mtppy/pea/mtp_generator/__init__.py +4 -0
  132. mtppy/pea/mtp_generator/mtp_generator.py +1183 -0
  133. mtppy/pea/mtp_generator/mtp_generator_test.py +518 -0
  134. mtppy/pea/pea.py +139 -0
  135. mtppy/pea/pea_opcua_server/__init__.py +4 -0
  136. mtppy/pea/pea_opcua_server/marshalling.py +60 -0
  137. mtppy/pea/pea_opcua_server/opcua_options_provider/__init__.py +4 -0
  138. mtppy/pea/pea_opcua_server/opcua_options_provider/instances/basic_opcua_options_provider.py +50 -0
  139. mtppy/pea/pea_opcua_server/opcua_options_provider/opcua_options_provider.py +103 -0
  140. mtppy/pea/pea_opcua_server/pea_opcua_server.py +492 -0
  141. mtppy/pea/pea_opcua_server/subscription_list.py +55 -0
  142. mtppy/pea/pea_test.py +59 -0
  143. mtppy/pea/rmtp_pea.py +155 -0
  144. mtppy/pea/rmtp_pea_test.py +27 -0
  145. mtppy/pea/service_factory.py +178 -0
  146. mtppy/pea/service_factory_test.py +156 -0
  147. mtppy/pea/user_logic/__init__.py +4 -0
  148. mtppy/pea/user_logic/user_logic_pea.py +72 -0
  149. mtppy/pea/user_logic/user_logic_registry.py +106 -0
  150. mtppy/pea/user_logic/user_logic_registry_test.py +167 -0
  151. mtppy/pea/user_logic/user_logic_service.py +228 -0
  152. mtppy/pea/user_logic/user_logic_service_test.py +289 -0
  153. mtppy/utils/__init__.py +4 -0
  154. mtppy/utils/data_assembly_dict.py +61 -0
  155. mtppy/utils/data_assembly_dict_test.py +107 -0
  156. mtppy/utils/data_item.py +446 -0
  157. mtppy/utils/data_item_com_test.py +82 -0
  158. mtppy/utils/data_item_test.py +325 -0
  159. mtppy/utils/logging.py +23 -0
  160. mtppy/utils/logging_test.py +26 -0
  161. mtppy/utils/mtp_file_handling/__init__.py +4 -0
  162. mtppy/utils/mtp_file_handling/extract_manifest_from_mtp_file.py +22 -0
  163. mtppy/utils/mtp_file_handling/extract_mtp_file.py +22 -0
  164. mtppy/utils/mtp_file_handling/is_valid_mtp.py +22 -0
  165. mtppy/utils/mtp_file_handling/is_valid_path_for_manifest.py +15 -0
  166. mtppy/utils/mtp_file_handling/is_valid_path_to_manifest.py +17 -0
  167. mtppy/utils/mtp_file_handling/is_valid_path_to_mtp.py +17 -0
  168. mtppy/utils/mtp_file_handling/load_manifest_file.py +24 -0
  169. mtppy/utils/mtp_file_handling/mtp_reader/__init__.py +4 -0
  170. mtppy/utils/mtp_file_handling/mtp_reader/mtp_reader.py +103 -0
  171. mtppy/utils/mtp_file_handling/mtp_reader/mtp_reader_test.py +96 -0
  172. mtppy/utils/mtp_file_handling/mtp_reader/mtp_xml.py +226 -0
  173. mtppy/utils/mtp_file_handling/mtp_reader/mtp_xml_test.py +108 -0
  174. mtppy/utils/mtp_file_handling/mtp_writer/__init__.py +4 -0
  175. mtppy/utils/mtp_file_handling/mtp_writer/mtp_writer.py +77 -0
  176. mtppy/utils/mtp_file_handling/mtp_writer/ressources/get_content_types.py +10 -0
  177. mtppy/utils/mtp_file_handling/mtp_writer/ressources/get_rels.py +11 -0
  178. mtppy/utils/mtp_file_handling/mtp_writer/test_mtp_writer.py +25 -0
  179. mtppy/utils/mtp_file_handling/write_manifest_file.py +29 -0
  180. mtppy/utils/mtp_file_handling/write_manifest_file_test.py +22 -0
  181. mtppy/utils/mtp_file_handling/write_mtp_file.py +43 -0
  182. mtppy/utils/mtp_file_handling/write_mtp_file_test.py +22 -0
  183. mtppy/utils/testing.py +31 -0
  184. mtppy2_0-0.1.5.dist-info/METADATA +75 -0
  185. mtppy2_0-0.1.5.dist-info/RECORD +214 -0
  186. mtppy2_0-0.1.5.dist-info/WHEEL +5 -0
  187. mtppy2_0-0.1.5.dist-info/entry_points.txt +3 -0
  188. mtppy2_0-0.1.5.dist-info/licenses/LICENSE +21 -0
  189. mtppy2_0-0.1.5.dist-info/top_level.txt +4 -0
  190. tools/__init__.py +0 -0
  191. tools/create_bugreport.py +150 -0
  192. tools/inspect_mtp.py +110 -0
  193. utils/__init__.py +1 -0
  194. utils/file_handling/__init__.py +4 -0
  195. utils/file_handling/cleanup_folder.py +9 -0
  196. utils/file_handling/get_utc_foldername_with_ms.py +15 -0
  197. utils/file_handling/get_work_dir.py +9 -0
  198. utils/file_handling/is_valid_path_for_json.py +11 -0
  199. utils/file_handling/is_valid_path_to_json.py +17 -0
  200. utils/file_handling/load_json_file.py +18 -0
  201. utils/file_handling/read_file_from_file_archive.py +43 -0
  202. utils/file_handling/read_file_string.py +10 -0
  203. utils/file_handling/validate_json_data.py +28 -0
  204. utils/file_handling/write_json_file.py +23 -0
  205. utils/get_uuid.py +18 -0
  206. utils/get_uuid_test.py +17 -0
  207. utils/logging.py +100 -0
  208. utils/logging_test.py +67 -0
  209. utils/opcua/check_node.py +79 -0
  210. utils/resolve_unit/resolve_unit.py +11 -0
  211. utils/resolve_unit/unit_lib.py +2101 -0
  212. utils/resolve_unit/unit_lib_test.py +36 -0
  213. utils/type_conversion.py +236 -0
  214. utils/type_conversion_test.py +114 -0
@@ -0,0 +1,567 @@
1
+ """Test Suite for AnaDrv."""
2
+
3
+ __copyright__ = (
4
+ "Copyright (c) 2026 Dresden University of Technology, Process-to-Order Group"
5
+ )
6
+ __license__ = "MIT"
7
+ import pytest
8
+
9
+ from mtppy.utils.testing import data_object_set_modes
10
+ from mtppy.part3.data_assembly_set.active_elements.drives.ana_drv import AnaDrv
11
+
12
+
13
+ def init_ana_drv(
14
+ init_op_mode="off",
15
+ init_src_mode="int",
16
+ rev_fbk_calc=True,
17
+ fwd_fbk_calc=True,
18
+ rpm_fbk_calc=True,
19
+ safe_pos=0,
20
+ fwd_en=True,
21
+ rev_en=False,
22
+ perm_en=False,
23
+ intl_en=False,
24
+ prot_en=False,
25
+ ):
26
+ instance = AnaDrv(
27
+ "tag",
28
+ tag_description="",
29
+ rpm_min=-10,
30
+ rpm_max=1000,
31
+ rpm_scl_min=0,
32
+ rpm_scl_max=1000,
33
+ rpm_unit=0,
34
+ rev_fbk_calc=rev_fbk_calc,
35
+ fwd_fbk_calc=fwd_fbk_calc,
36
+ rpm_fbk_calc=rpm_fbk_calc,
37
+ safe_pos=safe_pos,
38
+ fwd_en=fwd_en,
39
+ rev_en=rev_en,
40
+ perm_en=perm_en,
41
+ intl_en=intl_en,
42
+ prot_en=prot_en,
43
+ )
44
+ data_object_set_modes(instance, init_op_mode, init_src_mode)
45
+ return instance
46
+
47
+
48
+ test_scenario = [
49
+ ("off", "int", "set_fwd_op", False),
50
+ ("off", "man", "set_fwd_op", False),
51
+ ("op", "int", "set_fwd_op", True),
52
+ ("op", "man", "set_fwd_op", True),
53
+ ("aut", "int", "set_fwd_op", False),
54
+ ("aut", "man", "set_fwd_op", False),
55
+ ("off", "int", "set_fwd_aut", False),
56
+ ("off", "man", "set_fwd_aut", False),
57
+ ("op", "int", "set_fwd_aut", False),
58
+ ("op", "man", "set_fwd_aut", False),
59
+ ("aut", "int", "set_fwd_aut", True),
60
+ ("aut", "man", "set_fwd_aut", True),
61
+ ("off", "int", "set_rev_op", False),
62
+ ("off", "man", "set_rev_op", False),
63
+ ("op", "int", "set_rev_op", True),
64
+ ("op", "man", "set_rev_op", True),
65
+ ("aut", "int", "set_rev_op", False),
66
+ ("aut", "man", "set_rev_op", False),
67
+ ("off", "int", "set_rev_aut", False),
68
+ ("off", "man", "set_rev_aut", False),
69
+ ("op", "int", "set_rev_aut", False),
70
+ ("op", "man", "set_rev_aut", False),
71
+ ("aut", "int", "set_rev_aut", True),
72
+ ("aut", "man", "set_rev_aut", True),
73
+ ]
74
+
75
+
76
+ @pytest.mark.parametrize(
77
+ "op_mode, src_mode, set_command, expected_result", test_scenario
78
+ )
79
+ def test_fwd_rev(op_mode, src_mode, set_command, expected_result):
80
+ for command in [True, False]:
81
+ ana_drv = init_ana_drv(
82
+ init_op_mode=op_mode, init_src_mode=src_mode, fwd_en=True, rev_en=True
83
+ )
84
+ eval(f"ana_drv.{set_command}({command})")
85
+ print(
86
+ f"Scenario: mode {op_mode} {src_mode}, {set_command}, expected: {expected_result}"
87
+ )
88
+ if set_command in ["set_fwd_op", "set_fwd_aut"]:
89
+ if command:
90
+ assert ana_drv["FwdCtrl"] == expected_result
91
+ assert ana_drv.get_fwd_fbk() == expected_result
92
+ assert ana_drv["RevCtrl"] == False
93
+ assert ana_drv.get_rev_fbk() == False
94
+ else:
95
+ assert ana_drv["FwdCtrl"] == False
96
+ assert ana_drv.get_fwd_fbk() == False
97
+ assert ana_drv["RevCtrl"] == False
98
+ assert ana_drv.get_rev_fbk() == False
99
+ elif set_command in ["set_rev_op", "set_rev_aut"]:
100
+ if command:
101
+ assert ana_drv["FwdCtrl"] == False
102
+ assert ana_drv.get_fwd_fbk() == False
103
+ assert ana_drv["RevCtrl"] == expected_result
104
+ assert ana_drv.get_rev_fbk() == expected_result
105
+ else:
106
+ assert ana_drv["FwdCtrl"] == False
107
+ assert ana_drv.get_fwd_fbk() == False
108
+ assert ana_drv["RevCtrl"] == False
109
+ assert ana_drv.get_rev_fbk() == False
110
+
111
+
112
+ @pytest.mark.parametrize(
113
+ "op_mode, src_mode, set_command, expected_result", test_scenario
114
+ )
115
+ def test_fwd_rev_en(op_mode, src_mode, set_command, expected_result):
116
+ for command in [True, False]:
117
+ ana_drv = init_ana_drv(
118
+ init_op_mode=op_mode, init_src_mode=src_mode, fwd_en=False, rev_en=False
119
+ )
120
+ eval(f"ana_drv.{set_command}({command})")
121
+ print(f"Scenario: mode {op_mode} {src_mode}, {set_command}, expected: False")
122
+ assert ana_drv["FwdCtrl"] == False
123
+ assert ana_drv["RevCtrl"] == False
124
+
125
+
126
+ @pytest.mark.parametrize(
127
+ "op_mode, src_mode, set_command, expected_result", test_scenario
128
+ )
129
+ def test_fwd_rev_trip(op_mode, src_mode, set_command, expected_result):
130
+ for command in [True, False]:
131
+ ana_drv = init_ana_drv(
132
+ init_op_mode=op_mode, init_src_mode=src_mode, fwd_en=True, rev_en=True
133
+ )
134
+ ana_drv.set_trip(False)
135
+ eval(f"ana_drv.{set_command}({command})")
136
+ print(f"Scenario: mode {op_mode} {src_mode}, {set_command}, expected: False")
137
+ assert ana_drv["SafePosAct"] == True
138
+ assert ana_drv["Trip"] == False
139
+ assert ana_drv["FwdCtrl"] == False
140
+ assert ana_drv["RevCtrl"] == False
141
+
142
+
143
+ @pytest.mark.parametrize(
144
+ "op_mode, src_mode, set_command, expected_result", test_scenario
145
+ )
146
+ def test_fwd_rev_permit_en_true(op_mode, src_mode, set_command, expected_result):
147
+ for command in [True, False]:
148
+ ana_drv = init_ana_drv(
149
+ init_op_mode=op_mode,
150
+ init_src_mode=src_mode,
151
+ fwd_en=True,
152
+ rev_en=True,
153
+ perm_en=True,
154
+ )
155
+ ana_drv.set_permit(False)
156
+ eval(f"ana_drv.{set_command}({command})")
157
+ print(f"Scenario: mode {op_mode} {src_mode}, {set_command}, expected: False")
158
+ assert ana_drv["SafePosAct"] == True
159
+ assert ana_drv["Permit"] == False
160
+ assert ana_drv["FwdCtrl"] == False
161
+ assert ana_drv["RevCtrl"] == False
162
+
163
+ for command in [True, False]:
164
+ ana_drv = init_ana_drv(
165
+ init_op_mode=op_mode,
166
+ init_src_mode=src_mode,
167
+ fwd_en=True,
168
+ rev_en=True,
169
+ perm_en=True,
170
+ )
171
+ ana_drv.set_permit(True)
172
+ eval(f"ana_drv.{set_command}({command})")
173
+ print(
174
+ f"Scenario: mode {op_mode} {src_mode}, {set_command}, expected: {expected_result}"
175
+ )
176
+
177
+ assert ana_drv["Permit"] == True
178
+ assert ana_drv["SafePosAct"] == False
179
+ if set_command in ["set_fwd_op", "set_fwd_aut"]:
180
+ if command:
181
+ assert ana_drv["FwdCtrl"] == expected_result
182
+ assert ana_drv["RevCtrl"] == False
183
+ else:
184
+ assert ana_drv["FwdCtrl"] == False
185
+ assert ana_drv["RevCtrl"] == False
186
+ elif set_command in ["set_rev_op", "set_rev_aut"]:
187
+ if command:
188
+ assert ana_drv["FwdCtrl"] == False
189
+ assert ana_drv["RevCtrl"] == expected_result
190
+ else:
191
+ assert ana_drv["FwdCtrl"] == False
192
+ assert ana_drv["RevCtrl"] == False
193
+
194
+
195
+ def test_fwd_rev_permit_en_false():
196
+ for op_mode, src_mode, set_command, expected_result in test_scenario:
197
+ for command in [True, False]:
198
+ ana_drv = init_ana_drv(
199
+ init_op_mode=op_mode,
200
+ init_src_mode=src_mode,
201
+ fwd_en=True,
202
+ rev_en=True,
203
+ perm_en=False,
204
+ )
205
+ ana_drv.set_permit(True)
206
+ eval(f"ana_drv.{set_command}({command})")
207
+ print(
208
+ f"Scenario: mode {op_mode} {src_mode}, {set_command}, expected: {expected_result}"
209
+ )
210
+
211
+ assert ana_drv["Permit"] == True
212
+ assert ana_drv["SafePosAct"] == False
213
+ if set_command in ["set_fwd_op", "set_fwd_aut"]:
214
+ if command:
215
+ assert ana_drv["FwdCtrl"] == expected_result
216
+ assert ana_drv["RevCtrl"] == False
217
+ else:
218
+ assert ana_drv["FwdCtrl"] == False
219
+ assert ana_drv["RevCtrl"] == False
220
+ elif set_command in ["set_rev_op", "set_rev_aut"]:
221
+ if command:
222
+ assert ana_drv["FwdCtrl"] == False
223
+ assert ana_drv["RevCtrl"] == expected_result
224
+ else:
225
+ assert ana_drv["FwdCtrl"] == False
226
+ assert ana_drv["RevCtrl"] == False
227
+
228
+
229
+ def test_fwd_rev_interlock_en_true():
230
+ for op_mode, src_mode, set_command, _ in test_scenario:
231
+ for command in [True, False]:
232
+ ana_drv = init_ana_drv(
233
+ init_op_mode=op_mode,
234
+ init_src_mode=src_mode,
235
+ fwd_en=True,
236
+ rev_en=True,
237
+ intl_en=True,
238
+ )
239
+ ana_drv.set_interlock(False)
240
+ eval(f"ana_drv.{set_command}({command})")
241
+ print(
242
+ f"Scenario: mode {op_mode} {src_mode}, {set_command}, expected: False"
243
+ )
244
+
245
+ assert ana_drv["Interlock"] == False
246
+ assert ana_drv["SafePosAct"] == True
247
+ assert ana_drv["FwdCtrl"] == False
248
+ assert ana_drv["RevCtrl"] == False
249
+
250
+ for op_mode, src_mode, set_command, expected_result in test_scenario:
251
+ for command in [True, False]:
252
+ ana_drv = init_ana_drv(
253
+ init_op_mode=op_mode,
254
+ init_src_mode=src_mode,
255
+ fwd_en=True,
256
+ rev_en=True,
257
+ intl_en=True,
258
+ )
259
+ ana_drv.set_interlock(True)
260
+ eval(f"ana_drv.{set_command}({command})")
261
+ print(
262
+ f"Scenario: mode {op_mode} {src_mode}, {set_command}, expected: {expected_result}"
263
+ )
264
+
265
+ assert ana_drv["Interlock"] == True
266
+ assert ana_drv["SafePosAct"] == False
267
+ if set_command in ["set_fwd_op", "set_fwd_aut"]:
268
+ if command:
269
+ assert ana_drv["FwdCtrl"] == expected_result
270
+ assert ana_drv["RevCtrl"] == False
271
+ else:
272
+ assert ana_drv["FwdCtrl"] == False
273
+ assert ana_drv["RevCtrl"] == False
274
+ elif set_command in ["set_rev_op", "set_rev_aut"]:
275
+ if command:
276
+ assert ana_drv["FwdCtrl"] == False
277
+ assert ana_drv["RevCtrl"] == expected_result
278
+ else:
279
+ assert ana_drv["FwdCtrl"] == False
280
+ assert ana_drv["RevCtrl"] == False
281
+
282
+
283
+ def test_fwd_rev_interlock_en_false():
284
+ for op_mode, src_mode, set_command, expected_result in test_scenario:
285
+ for command in [True, False]:
286
+ ana_drv = init_ana_drv(
287
+ init_op_mode=op_mode,
288
+ init_src_mode=src_mode,
289
+ fwd_en=True,
290
+ rev_en=True,
291
+ intl_en=False,
292
+ )
293
+ ana_drv.set_interlock(True)
294
+ eval(f"ana_drv.{set_command}({command})")
295
+ print(
296
+ f"Scenario: mode {op_mode} {src_mode}, {set_command}, expected: {expected_result}"
297
+ )
298
+
299
+ assert ana_drv["Interlock"] == True
300
+ assert ana_drv["SafePosAct"] == False
301
+ if set_command in ["set_fwd_op", "set_fwd_aut"]:
302
+ if command:
303
+ assert ana_drv["FwdCtrl"] == expected_result
304
+ assert ana_drv["RevCtrl"] == False
305
+ else:
306
+ assert ana_drv["FwdCtrl"] == False
307
+ assert ana_drv["RevCtrl"] == False
308
+ elif set_command in ["set_rev_op", "set_rev_aut"]:
309
+ if command:
310
+ assert ana_drv["FwdCtrl"] == False
311
+ assert ana_drv["RevCtrl"] == expected_result
312
+ else:
313
+ assert ana_drv["FwdCtrl"] == False
314
+ assert ana_drv["RevCtrl"] == False
315
+
316
+
317
+ def test_fwd_rev_protect_en_true():
318
+ for op_mode, src_mode, set_command, _ in test_scenario:
319
+ for command in [True, False]:
320
+ ana_drv = init_ana_drv(
321
+ init_op_mode=op_mode,
322
+ init_src_mode=src_mode,
323
+ fwd_en=True,
324
+ rev_en=True,
325
+ prot_en=True,
326
+ )
327
+ ana_drv.set_protect(False)
328
+ eval(f"ana_drv.{set_command}({command})")
329
+ print(
330
+ f"Scenario: mode {op_mode} {src_mode}, {set_command}, expected: False"
331
+ )
332
+
333
+ assert ana_drv["Protect"] == False
334
+ assert ana_drv["SafePosAct"] == True
335
+ assert ana_drv["FwdCtrl"] == False
336
+ assert ana_drv["RevCtrl"] == False
337
+
338
+ for op_mode, src_mode, set_command, expected_result in test_scenario:
339
+ for command in [True, False]:
340
+ ana_drv = init_ana_drv(
341
+ init_op_mode=op_mode,
342
+ init_src_mode=src_mode,
343
+ fwd_en=True,
344
+ rev_en=True,
345
+ prot_en=True,
346
+ )
347
+ ana_drv.set_protect(True)
348
+ eval(f"ana_drv.{set_command}({command})")
349
+ print(
350
+ f"Scenario: mode {op_mode} {src_mode}, {set_command}, expected: {expected_result}"
351
+ )
352
+
353
+ assert ana_drv["Protect"] == True
354
+ assert ana_drv["SafePosAct"] == False
355
+ if set_command in ["set_fwd_op", "set_fwd_aut"]:
356
+ if command:
357
+ assert ana_drv["FwdCtrl"] == expected_result
358
+ assert ana_drv["RevCtrl"] == False
359
+ else:
360
+ assert ana_drv["FwdCtrl"] == False
361
+ assert ana_drv["RevCtrl"] == False
362
+ elif set_command in ["set_rev_op", "set_rev_aut"]:
363
+ if command:
364
+ assert ana_drv["FwdCtrl"] == False
365
+ assert ana_drv["RevCtrl"] == expected_result
366
+ else:
367
+ assert ana_drv["FwdCtrl"] == False
368
+ assert ana_drv["RevCtrl"] == False
369
+
370
+
371
+ def test_fwd_rev_protect_en_false():
372
+ for op_mode, src_mode, set_command, expected_result in test_scenario:
373
+ for command in [True, False]:
374
+ ana_drv = init_ana_drv(
375
+ init_op_mode=op_mode,
376
+ init_src_mode=src_mode,
377
+ fwd_en=True,
378
+ rev_en=True,
379
+ prot_en=False,
380
+ )
381
+ ana_drv.set_protect(True)
382
+ eval(f"ana_drv.{set_command}({command})")
383
+ print(
384
+ f"Scenario: mode {op_mode} {src_mode}, {set_command}, expected: {expected_result}"
385
+ )
386
+
387
+ assert ana_drv["Protect"] == True
388
+ assert ana_drv["SafePosAct"] == False
389
+ if set_command in ["set_fwd_op", "set_fwd_aut"]:
390
+ if command:
391
+ assert ana_drv["FwdCtrl"] == expected_result
392
+ assert ana_drv["RevCtrl"] == False
393
+ else:
394
+ assert ana_drv["FwdCtrl"] == False
395
+ assert ana_drv["RevCtrl"] == False
396
+ elif set_command in ["set_rev_op", "set_rev_aut"]:
397
+ if command:
398
+ assert ana_drv["FwdCtrl"] == False
399
+ assert ana_drv["RevCtrl"] == expected_result
400
+ else:
401
+ assert ana_drv["FwdCtrl"] == False
402
+ assert ana_drv["RevCtrl"] == False
403
+
404
+
405
+ test_scenario_reset = [
406
+ ("off", "int", "set_reset_op", False),
407
+ ("off", "man", "set_reset_op", False),
408
+ ("op", "int", "set_reset_op", True),
409
+ ("op", "man", "set_reset_op", True),
410
+ ("aut", "int", "set_reset_op", False),
411
+ ("aut", "man", "set_reset_op", False),
412
+ ("off", "int", "set_reset_aut", False),
413
+ ("off", "man", "set_reset_aut", False),
414
+ ("op", "int", "set_reset_aut", False),
415
+ ("op", "man", "set_reset_aut", False),
416
+ ("aut", "int", "set_reset_aut", True),
417
+ ("aut", "man", "set_reset_aut", True),
418
+ ]
419
+
420
+
421
+ def test_reset():
422
+ for op_mode, src_mode, set_command, result in test_scenario_reset:
423
+ for command in [True, False]:
424
+ ana_drv = init_ana_drv(
425
+ init_op_mode=op_mode,
426
+ init_src_mode=src_mode,
427
+ fwd_en=True,
428
+ rev_en=True,
429
+ prot_en=True,
430
+ )
431
+
432
+ ana_drv.set_protect(False)
433
+ assert ana_drv["Protect"] == False
434
+ assert ana_drv["SafePosAct"] == True
435
+
436
+ eval(f"ana_drv.{set_command}({command})")
437
+ print(
438
+ f"Scenario: mode {op_mode} {src_mode}, {set_command}, expected: {result}"
439
+ )
440
+
441
+ if command:
442
+ assert ana_drv["Protect"] == result
443
+ assert ana_drv["SafePosAct"] != result
444
+ else:
445
+ assert ana_drv["Protect"] == False
446
+ assert ana_drv["SafePosAct"] == True
447
+
448
+
449
+ test_scenario_stop = [
450
+ ("op", "int", "set_stop_op", True),
451
+ ("op", "man", "set_stop_op", True),
452
+ ("aut", "int", "set_stop_op", False),
453
+ ("aut", "man", "set_stop_op", False),
454
+ ("op", "int", "set_stop_aut", False),
455
+ ("op", "man", "set_stop_aut", False),
456
+ ("aut", "int", "set_stop_aut", True),
457
+ ("aut", "man", "set_stop_aut", True),
458
+ ]
459
+
460
+
461
+ def test_stop():
462
+ for op_mode, src_mode, set_command, changes_expected in test_scenario_stop:
463
+ for command in [True, False]:
464
+ ana_drv = init_ana_drv(
465
+ init_op_mode=op_mode, init_src_mode=src_mode, fwd_en=True, rev_en=True
466
+ )
467
+ ana_drv.set_fwd_op(True)
468
+ ana_drv.set_fwd_aut(True)
469
+
470
+ print(
471
+ f"Scenario: mode {op_mode} {src_mode}, {set_command}, expected: {changes_expected}"
472
+ )
473
+ if changes_expected:
474
+ assert ana_drv["FwdCtrl"] == True
475
+ eval(f"ana_drv.{set_command}({command})")
476
+ if command:
477
+ assert ana_drv["FwdCtrl"] == False
478
+ else:
479
+ assert ana_drv["FwdCtrl"] == True
480
+ else:
481
+ assert ana_drv["FwdCtrl"] == True
482
+
483
+
484
+ test_scenario_rpm = [
485
+ ("off", "int", "set_rpm_int", False),
486
+ ("off", "man", "set_rpm_int", False),
487
+ ("op", "int", "set_rpm_int", False),
488
+ ("op", "man", "set_rpm_int", False),
489
+ ("aut", "int", "set_rpm_int", True),
490
+ ("aut", "man", "set_rpm_int", False),
491
+ ("off", "int", "set_rpm_man", False),
492
+ ("off", "man", "set_rpm_man", False),
493
+ ("op", "int", "set_rpm_man", True),
494
+ ("op", "man", "set_rpm_man", True),
495
+ ("aut", "int", "set_rpm_man", False),
496
+ ("aut", "man", "set_rpm_man", False),
497
+ ]
498
+
499
+
500
+ @pytest.mark.parametrize(
501
+ "op_mode, src_mode, set_command, changes_expected", test_scenario_rpm
502
+ )
503
+ def test_rpm(op_mode, src_mode, set_command, changes_expected):
504
+ for rpm in [-500, -10, 500, 1000, 10000]:
505
+ ana_drv = init_ana_drv(
506
+ init_op_mode=op_mode, init_src_mode=src_mode, rpm_fbk_calc=True
507
+ )
508
+ eval(f"ana_drv.{set_command}({rpm})")
509
+
510
+ print(
511
+ f"Scenario: mode {op_mode} {src_mode}, {set_command}, {rpm} changes expected: {changes_expected}"
512
+ )
513
+ if changes_expected:
514
+ if -10 <= rpm <= 1000:
515
+ assert ana_drv.get_rpm() == rpm
516
+ assert ana_drv.get_rpm_fbk() == rpm
517
+ else:
518
+ assert ana_drv.get_rpm() == -10
519
+ assert ana_drv.get_rpm_fbk() == -10
520
+ else:
521
+ assert ana_drv.get_rpm() == -10
522
+ assert ana_drv.get_rpm_fbk() == -10
523
+
524
+
525
+ def test_rpm_rbk():
526
+ for rpm in [-500, -10, 500, 1000, 10000]:
527
+ ana_drv = init_ana_drv()
528
+ ana_drv.set_rpm_rbk(rpm)
529
+
530
+ if -10 <= rpm <= 1000:
531
+ assert ana_drv.get_rpm_rbk() == rpm
532
+ elif rpm < -10:
533
+ assert ana_drv.get_rpm_rbk() == -10
534
+ elif rpm > 1000:
535
+ assert ana_drv.get_rpm_rbk() == 1000
536
+
537
+
538
+ def test_rpm_fbk():
539
+ for rpm in [-500, -10, 500, 1000, 10000]:
540
+ for fbk_calc in [False, True]:
541
+ ana_drv = init_ana_drv(rpm_fbk_calc=fbk_calc)
542
+ ana_drv.set_rpm_fbk(rpm)
543
+ if not fbk_calc:
544
+ if -10 <= rpm <= 1000:
545
+ assert ana_drv.get_rpm_fbk() == rpm
546
+ elif rpm < -10:
547
+ assert ana_drv.get_rpm_fbk() == -10
548
+ elif rpm > 1000:
549
+ assert ana_drv.get_rpm_fbk() == 1000
550
+
551
+
552
+ def test_fwd_fbk():
553
+ ana_drv = init_ana_drv(fwd_fbk_calc=False, rev_fbk_calc=False)
554
+ assert ana_drv.get_fwd_fbk() == False
555
+ ana_drv.set_fwd_fbk(True)
556
+ assert ana_drv.get_fwd_fbk() == True
557
+
558
+
559
+ def test_rev_fbk():
560
+ ana_drv = init_ana_drv(fwd_fbk_calc=False, rev_fbk_calc=False)
561
+ assert ana_drv.get_rev_fbk() == False
562
+ ana_drv.set_rev_fbk(True)
563
+ assert ana_drv.get_rev_fbk() == True
564
+
565
+ if __name__ == "__main__":
566
+ # This allows running the tests directly if needed
567
+ pytest.main([__file__, "-v"])