diff --git a/src/core/pyros_django/agent/Agent.py b/src/core/pyros_django/agent/Agent.py index 708bef4..2b08669 100755 --- a/src/core/pyros_django/agent/Agent.py +++ b/src/core/pyros_django/agent/Agent.py @@ -1276,7 +1276,33 @@ class Agent: def _simulator_test_results(self): if self.TEST_COMMANDS_LIST == [] : return commands = self._simulator_test_results_start() + nb_commands_to_send = len(self.TEST_COMMANDS_LIST) + + # General (default) test + #print(commands[0].name, "compared to", self.TEST_COMMANDS_LIST[0].split()[1]) + assert commands[0].name == self.TEST_COMMANDS_LIST[0].split()[1] + last_cmd = commands[-1] + assert last_cmd.name == self.TEST_COMMANDS_LIST[-1].split()[1] + assert last_cmd.name == "do_exit" + assert last_cmd.is_executed() + assert last_cmd.get_result() == "SHOULD BE DONE NOW" + + nb_asserted = 0 + nb_unimplemented = 0 + for cmd in commands: + assert cmd.is_executed() or cmd.is_killed() + nb_asserted += 1 + if cmd.name in ["do_unimplemented", "do_unknown"]: + assert cmd.is_killed() + assert "NotImplementedGenericCmdException" in cmd.get_result() + nb_unimplemented += 1 + print(nb_commands_to_send, "cmds I had to send <==>", nb_asserted, "cmds executed (or killed)") + print("Among them,", nb_unimplemented, "unimplemented or unknown commands ==> NotImplementedGenericCmdException raised then command was killed") + assert nb_asserted == nb_commands_to_send + + # Specific (detailed) test (to be overriden by subclass) nb_asserted = self.simulator_test_results_main(commands) + self._simulator_test_results_end(nb_asserted) def _simulator_test_results_start(self): @@ -1286,8 +1312,6 @@ class Agent: #commands = Command.get_last_N_commands_sent_to_agent(self.name, 16) commands = Command.get_last_N_commands_sent_by_agent(self.name, len(self.TEST_COMMANDS_LIST)) Command.show_commands(commands) - assert commands[0].name == self.TEST_COMMANDS_LIST[0] - assert commands[-1].name == self.TEST_COMMANDS_LIST[-1] return commands """ OLD SCENARIO nb_asserted = 0 @@ -1318,15 +1342,20 @@ class Agent: # To be overriden by subclass def simulator_test_results_main(self, commands): + return 0 + ''' nb_asserted = 0 + print("from simulator_test_results_main", commands) for cmd in commands: assert cmd.is_executed() nb_asserted+=1 return nb_asserted + ''' def _simulator_test_results_end(self, nb_asserted): - nb_commands_to_send = len(self.TEST_COMMANDS_LIST) - assert nb_asserted == nb_commands_to_send + #nb_commands_to_send = len(self.TEST_COMMANDS_LIST) + #print(nb_asserted, "vs", nb_commands_to_send) + #assert nb_asserted == nb_commands_to_send #self.print(f"************** Finished testing => result is ok ({nb_asserted} assertions) **************") printFullTerm(Colors.GREEN, f"************** Finished testing => result is ok ({nb_asserted} assertions) **************") diff --git a/src/core/pyros_django/agent/AgentDevice.py b/src/core/pyros_django/agent/AgentDevice.py index a29e0f2..2a939c9 100755 --- a/src/core/pyros_django/agent/AgentDevice.py +++ b/src/core/pyros_django/agent/AgentDevice.py @@ -13,7 +13,7 @@ from common.models import AgentDeviceStatus, Command, get_or_create_unique_row_f sys.path.append("../../..") -from device_controller.abstract_component.device_controller import DeviceControllerAbstract, DCCNotFoundException, NotImplementedGenericCmdException +from device_controller.abstract_component.device_controller import DeviceController, DCCNotFoundException, NotImplementedGenericCmdException ##log = L.setupLogger("AgentXTaskLogger", "AgentX") @@ -84,8 +84,8 @@ class AgentDevice(Agent): # @override #def __init__(self, name:str=None, config_filename=None, RUN_IN_THREAD=True, device_controller, host, port): #def __init__(self, name:str, config_filename, RUN_IN_THREAD, device_controller, host, port, device_simulator): - ##def __init__(self, config_filename, RUN_IN_THREAD, device_controller:DeviceControllerAbstract, host, port, device_simulator): - def __init__(self, config_filename, RUN_IN_THREAD, device_controller:DeviceControllerAbstract, host, port): + ##def __init__(self, config_filename, RUN_IN_THREAD, device_controller:DeviceController, host, port, device_simulator): + def __init__(self, config_filename, RUN_IN_THREAD, device_controller:DeviceController, host, port): ##if name is None: name = self.__class__.__name__ #super().__init__(name, config_filename, RUN_IN_THREAD) super().__init__(config_filename, RUN_IN_THREAD) diff --git a/src/core/pyros_django/agent/AgentDeviceGemini.py b/src/core/pyros_django/agent/AgentDeviceGemini.py index 3d579f6..524a7d2 100755 --- a/src/core/pyros_django/agent/AgentDeviceGemini.py +++ b/src/core/pyros_django/agent/AgentDeviceGemini.py @@ -37,8 +37,8 @@ class AgentDeviceGemini(AgentDevice): WITH_SIMULATOR = False #WITH_SIMULATOR = True # - How many seconds should I be running ? - #TEST_MAX_DURATION_SEC = None - TEST_MAX_DURATION_SEC = 70 + TEST_MAX_DURATION_SEC = None + #TEST_MAX_DURATION_SEC = 70 # - Who should I send commands to ? #TEST_COMMANDS_DEST = "myself" ##TEST_COMMANDS_DEST = "AgentB" diff --git a/src/core/pyros_django/agent/AgentDeviceSBIG.py b/src/core/pyros_django/agent/AgentDeviceSBIG.py index 7dc87cc..bba2744 100755 --- a/src/core/pyros_django/agent/AgentDeviceSBIG.py +++ b/src/core/pyros_django/agent/AgentDeviceSBIG.py @@ -37,8 +37,8 @@ class AgentDeviceSBIG(AgentDevice): WITH_SIMULATOR = False #WITH_SIMULATOR = True # - How many seconds should I be running ? - #TEST_MAX_DURATION_SEC = None - TEST_MAX_DURATION_SEC = 110 + TEST_MAX_DURATION_SEC = None + #TEST_MAX_DURATION_SEC = 110 # - Who should I send commands to ? #TEST_COMMANDS_DEST = "myself" ##TEST_COMMANDS_DEST = "AgentB" diff --git a/src/core/pyros_django/agent/AgentMultiRequester.py b/src/core/pyros_django/agent/AgentMultiRequester.py index 0528325..ab35463 100755 --- a/src/core/pyros_django/agent/AgentMultiRequester.py +++ b/src/core/pyros_django/agent/AgentMultiRequester.py @@ -314,6 +314,7 @@ class AgentMultiRequester(Agent): # @override def simulator_test_results_main(self, commands): + #nb_asserted = super().simulator_test_results_main(commands) nb_asserted = 0 for cmd in commands: if cmd.name == "flush_commands": diff --git a/src/core/pyros_django/majordome/doc/AgentMajordome_object_diag.pu b/src/core/pyros_django/majordome/doc/AgentMajordome_object_diag.pu index cc0abd4..91d96f8 100755 --- a/src/core/pyros_django/majordome/doc/AgentMajordome_object_diag.pu +++ b/src/core/pyros_django/majordome/doc/AgentMajordome_object_diag.pu @@ -183,7 +183,7 @@ skinparam legendFontSize 11 legend left Version 04-11-2019 (E. Pallier) -Colors: yellow : abstract classes ; red : real devices ; blue : Gemini concrete classes ; green : SBIG concrete classes +Colors: (light) yellow : abstract classes ; red : real devices ; blue : Gemini concrete classes ; green : SBIG concrete classes AD = Agent Device diff --git a/src/device_controller/abstract_component/detector_sensor.py b/src/device_controller/abstract_component/detector_sensor.py index 6c5ff3f..dc8b621 100755 --- a/src/device_controller/abstract_component/detector_sensor.py +++ b/src/device_controller/abstract_component/detector_sensor.py @@ -22,13 +22,13 @@ import sys #from device_controller.abstract_component.base import * #sys.path.append("../..") #from device_controller.abstract_component.base import * -from device_controller.abstract_component.device_controller import DeviceControllerAbstract +from device_controller.abstract_component.device_controller import DeviceController #class SocketClientTelescopeAbstract(SocketClientAbstract): -#class DeviceControllerFilterSelector(DeviceControllerAbstract): -class DC_DetectorSensor(DeviceControllerAbstract): +#class DeviceControllerFilterSelector(DeviceController): +class DC_DetectorSensor(DeviceController): _cmd_device_concrete = {} #_cmd_device_abstract = { diff --git a/src/device_controller/abstract_component/detector_shutter.py b/src/device_controller/abstract_component/detector_shutter.py index da5874f..2a0283c 100755 --- a/src/device_controller/abstract_component/detector_shutter.py +++ b/src/device_controller/abstract_component/detector_shutter.py @@ -22,12 +22,12 @@ import sys #from device_controller.abstract_component.base import * #sys.path.append("../..") #from device_controller.abstract_component.base import * -from device_controller.abstract_component.device_controller import DeviceControllerAbstract +from device_controller.abstract_component.device_controller import DeviceController #class SocketClientTelescopeAbstract(SocketClientAbstract): -#class DeviceControllerFilterSelector(DeviceControllerAbstract): -class DC_DetectorShutter(DeviceControllerAbstract): +#class DeviceControllerFilterSelector(DeviceController): +class DC_DetectorShutter(DeviceController): _cmd_device_concrete = {} #_cmd_device_abstract = { diff --git a/src/device_controller/abstract_component/device_controller.py b/src/device_controller/abstract_component/device_controller.py index 3f6c152..833720b 100755 --- a/src/device_controller/abstract_component/device_controller.py +++ b/src/device_controller/abstract_component/device_controller.py @@ -215,9 +215,9 @@ class TimeoutException(Exception): #TODO: remove ClientChannelAbstract, and set instead a ClientChannel -#class DeviceControllerAbstract(SocketClientAbstract): -##class DeviceControllerAbstract(ClientChannel): -class DeviceControllerAbstract(): +#class DeviceController(SocketClientAbstract): +##class DeviceController(ClientChannel): +class DeviceController(): _device_simulator = None _thread_device_simulator = None @@ -264,7 +264,7 @@ class DeviceControllerAbstract(): :param channel: "SOCKET-TCP", "SOCKET-UDP", "SERIAL", "USB", or instance of Channel ''' - #print("IN DeviceControllerAbstract") + #print("IN DeviceController") self._device_host = device_host self._device_port = device_port @@ -503,7 +503,7 @@ class DeviceControllerAbstract(): #res = self.getDeviceControllerForType(cmd.device_type).execute_cmd(cmd.full_name) - def get_dc_component_for_type(self, dc_component_type:str): #->DeviceControllerAbstract: + def get_dc_component_for_type(self, dc_component_type:str): #->DeviceController: # By default, return myself (as a DeviceController component) # ex1: None # ex2: "Telescope" (is in "AgentDeviceTelescopeGemini") diff --git a/src/device_controller/abstract_component/filter_selector.py b/src/device_controller/abstract_component/filter_selector.py index 354ae6e..9290521 100755 --- a/src/device_controller/abstract_component/filter_selector.py +++ b/src/device_controller/abstract_component/filter_selector.py @@ -22,7 +22,7 @@ import sys #from device_controller.abstract_component.base import * #sys.path.append("../..") #from device_controller.abstract_component.base import * -from device_controller.abstract_component.device_controller import DeviceControllerAbstract +from device_controller.abstract_component.device_controller import DeviceController # Default timeouts @@ -32,8 +32,8 @@ TIMEOUT_RECEIVE = 10 #class SocketClientTelescopeAbstract(SocketClientAbstract): -#class DeviceControllerFilterSelector(DeviceControllerAbstract): -class DC_FilterSelector(DeviceControllerAbstract): +#class DeviceControllerFilterSelector(DeviceController): +class DC_FilterSelector(DeviceController): _cmd_device_concrete = {} #_cmd_device_abstract = { diff --git a/src/device_controller/abstract_component/mount.py b/src/device_controller/abstract_component/mount.py index c5e2cc8..57dd568 100755 --- a/src/device_controller/abstract_component/mount.py +++ b/src/device_controller/abstract_component/mount.py @@ -71,8 +71,8 @@ class Position(): #class SocketClientTelescopeAbstract(SocketClientAbstract): -#class TelescopeControllerAbstract(DeviceControllerAbstract): -class DC_Mount(DeviceControllerAbstract): +#class TelescopeControllerAbstract(DeviceController): +class DC_Mount(DeviceController): # @abstract (to be overriden) _cmd_device_concrete = {} diff --git a/src/device_controller/abstract_component/plc.py b/src/device_controller/abstract_component/plc.py index dd905d1..a70f204 100755 --- a/src/device_controller/abstract_component/plc.py +++ b/src/device_controller/abstract_component/plc.py @@ -59,7 +59,7 @@ class c(Enum): -class DeviceControllerPLC(DeviceControllerAbstract): +class DeviceControllerPLC(DeviceController): # @abstract (to be overriden) _cmd_native = {} diff --git a/src/device_controller/concrete_component/gemini/gemini_controller.py b/src/device_controller/concrete_component/gemini/gemini_controller.py index cc45b4b..1812255 100755 --- a/src/device_controller/concrete_component/gemini/gemini_controller.py +++ b/src/device_controller/concrete_component/gemini/gemini_controller.py @@ -17,7 +17,7 @@ import time sys.path.append('../../..') # My parent class and exceptions -from device_controller.abstract_component.device_controller import DeviceControllerAbstract, UnknownNativeCmdException, UnknownGenericCmdArgException +from device_controller.abstract_component.device_controller import DeviceController, UnknownNativeCmdException, UnknownGenericCmdArgException #from src.client.socket_client_telescope_abstract import Position, UnknownNativeCmdException, TimeoutException, SocketClientTelescopeAbstract ##from src_socket.client.socket_client_telescope_abstract import * @@ -44,7 +44,7 @@ COMMAND6_SIMPLE = '6' #class DeviceControllerTelescopeGemini(DC_Mount): #class DC_Gemini(DC_Mount): -class DC_Gemini(DeviceControllerAbstract): +class DC_Gemini(DeviceController): # Gemini communication protocol diff --git a/src/device_controller/concrete_component/sbig/sbig_controller.py b/src/device_controller/concrete_component/sbig/sbig_controller.py index 1da7475..8269a81 100755 --- a/src/device_controller/concrete_component/sbig/sbig_controller.py +++ b/src/device_controller/concrete_component/sbig/sbig_controller.py @@ -17,7 +17,7 @@ import time sys.path.append('../../..') # My parent class and exceptions -from device_controller.abstract_component.device_controller import DeviceControllerAbstract, UnknownNativeCmdException, UnknownGenericCmdArgException +from device_controller.abstract_component.device_controller import DeviceController, UnknownNativeCmdException, UnknownGenericCmdArgException # My DC components: from device_controller.abstract_component.filter_selector import DC_FilterSelector @@ -48,9 +48,9 @@ TIMEOUT_RECEIVE = 10 ##class SocketClientTelescopeGemini(SocketClientTelescopeAbstract): -#class DeviceControllerSBIG(DeviceControllerAbstract): -#class DeviceControllerSBIG(DeviceControllerAbstract): -class DC_SBIG(DeviceControllerAbstract): +#class DeviceControllerSBIG(DeviceController): +#class DeviceControllerSBIG(DeviceController): +class DC_SBIG(DeviceController): ''' # Components (list of my capabilities or roles): DeviceControllerDetectorSensor, @@ -163,12 +163,12 @@ class DC_SBIG(DeviceControllerAbstract): def uncap(cls, data_received:str)->str: #data_received = super().uncap(data_received_bytes) ##data_received = self._my_channel.uncap(data_received_bytes) - + #>>> tele.uncap(b'001700001\x00') - + r""" Extract useful data from received raw data - + >>> tele = DC_Gemini("localhost", 11110, DEBUG=False) Starting device simulator on (host:port): localhost:11110 >>> tele.last_stamp = '00170000' @@ -176,13 +176,14 @@ class DC_SBIG(DeviceControllerAbstract): '1' >>> tele.close() """ - + print("data_received_bytes type is", type(data_received)) print("data received is", data_received) ##data_received = data_received_bytes.decode() #print("data_received is", data_received) # Remove STAMP (and \n at the end): #useful_data = data_received.split(self.MY_FULL_STAMP)[1][:-1] + print("*** Last stamp is ***", cls.last_stamp, ", data received is", data_received) useful_data = data_received.split(cls.last_stamp)[1][:-1] # Remove '#' at the end, if exists if useful_data[-1] == '#': useful_data = useful_data[:-1] @@ -253,7 +254,7 @@ class DC_SBIG(DeviceControllerAbstract): # Gemini is using UDP def __init__(self, device_host:str="localhost", device_port:int=11110, DEBUG=False): #super().__init__(device_host, device_port, "SOCKET-UDP", 1024, DEBUG) - ##DeviceControllerAbstract.__init__(self, device_host, device_port, "SOCKET-UDP", 1024, DEBUG, DeviceSimulatorSBIG) + ##DeviceController.__init__(self, device_host, device_port, "SOCKET-UDP", 1024, DEBUG, DeviceSimulatorSBIG) ##super().__init__(device_host, device_port, "SOCKET-UDP", 1024, DEBUG, DeviceSimulatorSBIG) super().__init__(device_host, device_port, "SOCKET-UDP", 1024, protoc=self.Protocol, gen2nat_cmds=self.MY_GEN2NAT_CMDS, device_sim=DS_SBIG, DEBUG=DEBUG) -- libgit2 0.21.2