Commit e0853b2e76367d98dcb81d95f2122f2dea3b1eef

Authored by Etienne Pallier
1 parent f6009f75
Exists in dev

Bugfixes assert test general

(et renommage DeviceController et Channel)
src/core/pyros_django/agent/Agent.py
... ... @@ -1276,7 +1276,33 @@ class Agent:
1276 1276 def _simulator_test_results(self):
1277 1277 if self.TEST_COMMANDS_LIST == [] : return
1278 1278 commands = self._simulator_test_results_start()
  1279 + nb_commands_to_send = len(self.TEST_COMMANDS_LIST)
  1280 +
  1281 + # General (default) test
  1282 + #print(commands[0].name, "compared to", self.TEST_COMMANDS_LIST[0].split()[1])
  1283 + assert commands[0].name == self.TEST_COMMANDS_LIST[0].split()[1]
  1284 + last_cmd = commands[-1]
  1285 + assert last_cmd.name == self.TEST_COMMANDS_LIST[-1].split()[1]
  1286 + assert last_cmd.name == "do_exit"
  1287 + assert last_cmd.is_executed()
  1288 + assert last_cmd.get_result() == "SHOULD BE DONE NOW"
  1289 +
  1290 + nb_asserted = 0
  1291 + nb_unimplemented = 0
  1292 + for cmd in commands:
  1293 + assert cmd.is_executed() or cmd.is_killed()
  1294 + nb_asserted += 1
  1295 + if cmd.name in ["do_unimplemented", "do_unknown"]:
  1296 + assert cmd.is_killed()
  1297 + assert "NotImplementedGenericCmdException" in cmd.get_result()
  1298 + nb_unimplemented += 1
  1299 + print(nb_commands_to_send, "cmds I had to send <==>", nb_asserted, "cmds executed (or killed)")
  1300 + print("Among them,", nb_unimplemented, "unimplemented or unknown commands ==> NotImplementedGenericCmdException raised then command was killed")
  1301 + assert nb_asserted == nb_commands_to_send
  1302 +
  1303 + # Specific (detailed) test (to be overriden by subclass)
1279 1304 nb_asserted = self.simulator_test_results_main(commands)
  1305 +
1280 1306 self._simulator_test_results_end(nb_asserted)
1281 1307  
1282 1308 def _simulator_test_results_start(self):
... ... @@ -1286,8 +1312,6 @@ class Agent:
1286 1312 #commands = Command.get_last_N_commands_sent_to_agent(self.name, 16)
1287 1313 commands = Command.get_last_N_commands_sent_by_agent(self.name, len(self.TEST_COMMANDS_LIST))
1288 1314 Command.show_commands(commands)
1289   - assert commands[0].name == self.TEST_COMMANDS_LIST[0]
1290   - assert commands[-1].name == self.TEST_COMMANDS_LIST[-1]
1291 1315 return commands
1292 1316 """ OLD SCENARIO
1293 1317 nb_asserted = 0
... ... @@ -1318,15 +1342,20 @@ class Agent:
1318 1342  
1319 1343 # To be overriden by subclass
1320 1344 def simulator_test_results_main(self, commands):
  1345 + return 0
  1346 + '''
1321 1347 nb_asserted = 0
  1348 + print("from simulator_test_results_main", commands)
1322 1349 for cmd in commands:
1323 1350 assert cmd.is_executed()
1324 1351 nb_asserted+=1
1325 1352 return nb_asserted
  1353 + '''
1326 1354  
1327 1355 def _simulator_test_results_end(self, nb_asserted):
1328   - nb_commands_to_send = len(self.TEST_COMMANDS_LIST)
1329   - assert nb_asserted == nb_commands_to_send
  1356 + #nb_commands_to_send = len(self.TEST_COMMANDS_LIST)
  1357 + #print(nb_asserted, "vs", nb_commands_to_send)
  1358 + #assert nb_asserted == nb_commands_to_send
1330 1359 #self.print(f"************** Finished testing => result is ok ({nb_asserted} assertions) **************")
1331 1360 printFullTerm(Colors.GREEN, f"************** Finished testing => result is ok ({nb_asserted} assertions) **************")
1332 1361  
... ...
src/core/pyros_django/agent/AgentDevice.py
... ... @@ -13,7 +13,7 @@ from common.models import AgentDeviceStatus, Command, get_or_create_unique_row_f
13 13  
14 14  
15 15 sys.path.append("../../..")
16   -from device_controller.abstract_component.device_controller import DeviceControllerAbstract, DCCNotFoundException, NotImplementedGenericCmdException
  16 +from device_controller.abstract_component.device_controller import DeviceController, DCCNotFoundException, NotImplementedGenericCmdException
17 17  
18 18 ##log = L.setupLogger("AgentXTaskLogger", "AgentX")
19 19  
... ... @@ -84,8 +84,8 @@ class AgentDevice(Agent):
84 84 # @override
85 85 #def __init__(self, name:str=None, config_filename=None, RUN_IN_THREAD=True, device_controller, host, port):
86 86 #def __init__(self, name:str, config_filename, RUN_IN_THREAD, device_controller, host, port, device_simulator):
87   - ##def __init__(self, config_filename, RUN_IN_THREAD, device_controller:DeviceControllerAbstract, host, port, device_simulator):
88   - def __init__(self, config_filename, RUN_IN_THREAD, device_controller:DeviceControllerAbstract, host, port):
  87 + ##def __init__(self, config_filename, RUN_IN_THREAD, device_controller:DeviceController, host, port, device_simulator):
  88 + def __init__(self, config_filename, RUN_IN_THREAD, device_controller:DeviceController, host, port):
89 89 ##if name is None: name = self.__class__.__name__
90 90 #super().__init__(name, config_filename, RUN_IN_THREAD)
91 91 super().__init__(config_filename, RUN_IN_THREAD)
... ...
src/core/pyros_django/agent/AgentDeviceGemini.py
... ... @@ -37,8 +37,8 @@ class AgentDeviceGemini(AgentDevice):
37 37 WITH_SIMULATOR = False
38 38 #WITH_SIMULATOR = True
39 39 # - How many seconds should I be running ?
40   - #TEST_MAX_DURATION_SEC = None
41   - TEST_MAX_DURATION_SEC = 70
  40 + TEST_MAX_DURATION_SEC = None
  41 + #TEST_MAX_DURATION_SEC = 70
42 42 # - Who should I send commands to ?
43 43 #TEST_COMMANDS_DEST = "myself"
44 44 ##TEST_COMMANDS_DEST = "AgentB"
... ...
src/core/pyros_django/agent/AgentDeviceSBIG.py
... ... @@ -37,8 +37,8 @@ class AgentDeviceSBIG(AgentDevice):
37 37 WITH_SIMULATOR = False
38 38 #WITH_SIMULATOR = True
39 39 # - How many seconds should I be running ?
40   - #TEST_MAX_DURATION_SEC = None
41   - TEST_MAX_DURATION_SEC = 110
  40 + TEST_MAX_DURATION_SEC = None
  41 + #TEST_MAX_DURATION_SEC = 110
42 42 # - Who should I send commands to ?
43 43 #TEST_COMMANDS_DEST = "myself"
44 44 ##TEST_COMMANDS_DEST = "AgentB"
... ...
src/core/pyros_django/agent/AgentMultiRequester.py
... ... @@ -314,6 +314,7 @@ class AgentMultiRequester(Agent):
314 314  
315 315 # @override
316 316 def simulator_test_results_main(self, commands):
  317 + #nb_asserted = super().simulator_test_results_main(commands)
317 318 nb_asserted = 0
318 319 for cmd in commands:
319 320 if cmd.name == "flush_commands":
... ...
src/core/pyros_django/majordome/doc/AgentMajordome_object_diag.pu
... ... @@ -183,7 +183,7 @@ skinparam legendFontSize 11
183 183 legend left
184 184 <i>Version 04-11-2019 (E. Pallier)</i>
185 185  
186   -Colors: <b>yellow</b> : abstract classes ; <b>red</b> : real devices ; <b>blue</b> : Gemini concrete classes ; <b>green</b> : SBIG concrete classes
  186 +Colors: <b>(light) yellow</b> : abstract classes ; <b>red</b> : real devices ; <b>blue</b> : Gemini concrete classes ; <b>green</b> : SBIG concrete classes
187 187  
188 188 AD = <b>Agent Device</b>
189 189  
... ...
src/device_controller/abstract_component/detector_sensor.py
... ... @@ -22,13 +22,13 @@ import sys
22 22 #from device_controller.abstract_component.base import *
23 23 #sys.path.append("../..")
24 24 #from device_controller.abstract_component.base import *
25   -from device_controller.abstract_component.device_controller import DeviceControllerAbstract
  25 +from device_controller.abstract_component.device_controller import DeviceController
26 26  
27 27  
28 28  
29 29 #class SocketClientTelescopeAbstract(SocketClientAbstract):
30   -#class DeviceControllerFilterSelector(DeviceControllerAbstract):
31   -class DC_DetectorSensor(DeviceControllerAbstract):
  30 +#class DeviceControllerFilterSelector(DeviceController):
  31 +class DC_DetectorSensor(DeviceController):
32 32  
33 33 _cmd_device_concrete = {}
34 34 #_cmd_device_abstract = {
... ...
src/device_controller/abstract_component/detector_shutter.py
... ... @@ -22,12 +22,12 @@ import sys
22 22 #from device_controller.abstract_component.base import *
23 23 #sys.path.append("../..")
24 24 #from device_controller.abstract_component.base import *
25   -from device_controller.abstract_component.device_controller import DeviceControllerAbstract
  25 +from device_controller.abstract_component.device_controller import DeviceController
26 26  
27 27  
28 28 #class SocketClientTelescopeAbstract(SocketClientAbstract):
29   -#class DeviceControllerFilterSelector(DeviceControllerAbstract):
30   -class DC_DetectorShutter(DeviceControllerAbstract):
  29 +#class DeviceControllerFilterSelector(DeviceController):
  30 +class DC_DetectorShutter(DeviceController):
31 31  
32 32 _cmd_device_concrete = {}
33 33 #_cmd_device_abstract = {
... ...
src/device_controller/abstract_component/device_controller.py
... ... @@ -215,9 +215,9 @@ class TimeoutException(Exception):
215 215  
216 216  
217 217 #TODO: remove ClientChannelAbstract, and set instead a ClientChannel
218   -#class DeviceControllerAbstract(SocketClientAbstract):
219   -##class DeviceControllerAbstract(ClientChannel):
220   -class DeviceControllerAbstract():
  218 +#class DeviceController(SocketClientAbstract):
  219 +##class DeviceController(ClientChannel):
  220 +class DeviceController():
221 221  
222 222 _device_simulator = None
223 223 _thread_device_simulator = None
... ... @@ -264,7 +264,7 @@ class DeviceControllerAbstract():
264 264 :param channel: "SOCKET-TCP", "SOCKET-UDP", "SERIAL", "USB", or instance of Channel
265 265 '''
266 266  
267   - #print("IN DeviceControllerAbstract")
  267 + #print("IN DeviceController")
268 268 self._device_host = device_host
269 269 self._device_port = device_port
270 270  
... ... @@ -503,7 +503,7 @@ class DeviceControllerAbstract():
503 503  
504 504  
505 505 #res = self.getDeviceControllerForType(cmd.device_type).execute_cmd(cmd.full_name)
506   - def get_dc_component_for_type(self, dc_component_type:str): #->DeviceControllerAbstract:
  506 + def get_dc_component_for_type(self, dc_component_type:str): #->DeviceController:
507 507 # By default, return myself (as a DeviceController component)
508 508 # ex1: None
509 509 # ex2: "Telescope" (is in "AgentDeviceTelescopeGemini")
... ...
src/device_controller/abstract_component/filter_selector.py
... ... @@ -22,7 +22,7 @@ import sys
22 22 #from device_controller.abstract_component.base import *
23 23 #sys.path.append("../..")
24 24 #from device_controller.abstract_component.base import *
25   -from device_controller.abstract_component.device_controller import DeviceControllerAbstract
  25 +from device_controller.abstract_component.device_controller import DeviceController
26 26  
27 27  
28 28 # Default timeouts
... ... @@ -32,8 +32,8 @@ TIMEOUT_RECEIVE = 10
32 32  
33 33  
34 34 #class SocketClientTelescopeAbstract(SocketClientAbstract):
35   -#class DeviceControllerFilterSelector(DeviceControllerAbstract):
36   -class DC_FilterSelector(DeviceControllerAbstract):
  35 +#class DeviceControllerFilterSelector(DeviceController):
  36 +class DC_FilterSelector(DeviceController):
37 37  
38 38 _cmd_device_concrete = {}
39 39 #_cmd_device_abstract = {
... ...
src/device_controller/abstract_component/mount.py
... ... @@ -71,8 +71,8 @@ class Position():
71 71  
72 72  
73 73 #class SocketClientTelescopeAbstract(SocketClientAbstract):
74   -#class TelescopeControllerAbstract(DeviceControllerAbstract):
75   -class DC_Mount(DeviceControllerAbstract):
  74 +#class TelescopeControllerAbstract(DeviceController):
  75 +class DC_Mount(DeviceController):
76 76  
77 77 # @abstract (to be overriden)
78 78 _cmd_device_concrete = {}
... ...
src/device_controller/abstract_component/plc.py
... ... @@ -59,7 +59,7 @@ class c(Enum):
59 59  
60 60  
61 61  
62   -class DeviceControllerPLC(DeviceControllerAbstract):
  62 +class DeviceControllerPLC(DeviceController):
63 63  
64 64 # @abstract (to be overriden)
65 65 _cmd_native = {}
... ...
src/device_controller/concrete_component/gemini/gemini_controller.py
... ... @@ -17,7 +17,7 @@ import time
17 17 sys.path.append('../../..')
18 18  
19 19 # My parent class and exceptions
20   -from device_controller.abstract_component.device_controller import DeviceControllerAbstract, UnknownNativeCmdException, UnknownGenericCmdArgException
  20 +from device_controller.abstract_component.device_controller import DeviceController, UnknownNativeCmdException, UnknownGenericCmdArgException
21 21 #from src.client.socket_client_telescope_abstract import Position, UnknownNativeCmdException, TimeoutException, SocketClientTelescopeAbstract
22 22 ##from src_socket.client.socket_client_telescope_abstract import *
23 23  
... ... @@ -44,7 +44,7 @@ COMMAND6_SIMPLE = &#39;6&#39;
44 44  
45 45 #class DeviceControllerTelescopeGemini(DC_Mount):
46 46 #class DC_Gemini(DC_Mount):
47   -class DC_Gemini(DeviceControllerAbstract):
  47 +class DC_Gemini(DeviceController):
48 48  
49 49  
50 50 # Gemini communication protocol
... ...
src/device_controller/concrete_component/sbig/sbig_controller.py
... ... @@ -17,7 +17,7 @@ import time
17 17 sys.path.append('../../..')
18 18  
19 19 # My parent class and exceptions
20   -from device_controller.abstract_component.device_controller import DeviceControllerAbstract, UnknownNativeCmdException, UnknownGenericCmdArgException
  20 +from device_controller.abstract_component.device_controller import DeviceController, UnknownNativeCmdException, UnknownGenericCmdArgException
21 21  
22 22 # My DC components:
23 23 from device_controller.abstract_component.filter_selector import DC_FilterSelector
... ... @@ -48,9 +48,9 @@ TIMEOUT_RECEIVE = 10
48 48  
49 49  
50 50 ##class SocketClientTelescopeGemini(SocketClientTelescopeAbstract):
51   -#class DeviceControllerSBIG(DeviceControllerAbstract):
52   -#class DeviceControllerSBIG(DeviceControllerAbstract):
53   -class DC_SBIG(DeviceControllerAbstract):
  51 +#class DeviceControllerSBIG(DeviceController):
  52 +#class DeviceControllerSBIG(DeviceController):
  53 +class DC_SBIG(DeviceController):
54 54 '''
55 55 # Components (list of my capabilities or roles):
56 56 DeviceControllerDetectorSensor,
... ... @@ -163,12 +163,12 @@ class DC_SBIG(DeviceControllerAbstract):
163 163 def uncap(cls, data_received:str)->str:
164 164 #data_received = super().uncap(data_received_bytes)
165 165 ##data_received = self._my_channel.uncap(data_received_bytes)
166   -
  166 +
167 167 #>>> tele.uncap(b'001700001\x00')
168   -
  168 +
169 169 r"""
170 170 Extract useful data from received raw data
171   -
  171 +
172 172 >>> tele = DC_Gemini("localhost", 11110, DEBUG=False)
173 173 Starting device simulator on (host:port): localhost:11110
174 174 >>> tele.last_stamp = '00170000'
... ... @@ -176,13 +176,14 @@ class DC_SBIG(DeviceControllerAbstract):
176 176 '1'
177 177 >>> tele.close()
178 178 """
179   -
  179 +
180 180 print("data_received_bytes type is", type(data_received))
181 181 print("data received is", data_received)
182 182 ##data_received = data_received_bytes.decode()
183 183 #print("data_received is", data_received)
184 184 # Remove STAMP (and \n at the end):
185 185 #useful_data = data_received.split(self.MY_FULL_STAMP)[1][:-1]
  186 + print("*** Last stamp is ***", cls.last_stamp, ", data received is", data_received)
186 187 useful_data = data_received.split(cls.last_stamp)[1][:-1]
187 188 # Remove '#' at the end, if exists
188 189 if useful_data[-1] == '#': useful_data = useful_data[:-1]
... ... @@ -253,7 +254,7 @@ class DC_SBIG(DeviceControllerAbstract):
253 254 # Gemini is using UDP
254 255 def __init__(self, device_host:str="localhost", device_port:int=11110, DEBUG=False):
255 256 #super().__init__(device_host, device_port, "SOCKET-UDP", 1024, DEBUG)
256   - ##DeviceControllerAbstract.__init__(self, device_host, device_port, "SOCKET-UDP", 1024, DEBUG, DeviceSimulatorSBIG)
  257 + ##DeviceController.__init__(self, device_host, device_port, "SOCKET-UDP", 1024, DEBUG, DeviceSimulatorSBIG)
257 258 ##super().__init__(device_host, device_port, "SOCKET-UDP", 1024, DEBUG, DeviceSimulatorSBIG)
258 259 super().__init__(device_host, device_port, "SOCKET-UDP", 1024, protoc=self.Protocol, gen2nat_cmds=self.MY_GEN2NAT_CMDS, device_sim=DS_SBIG, DEBUG=DEBUG)
259 260  
... ...