Commit 4d01f948881c49399a84139fe33e0d2f5394b880

Authored by Etienne Pallier
1 parent e756352f
Exists in dev

Agent test bugfixes et updated doc scenario test

src/core/pyros_django/agent/Agent.py
... ... @@ -355,16 +355,18 @@ class Agent:
355 355 TEST_WITH_FINAL_TEST = False
356 356  
357 357  
358   - # (EP 2022/06) Default SCENARIO to be executed (only in TEST mode)
  358 + # (EP 2022/07) Default SCENARIO to be executed (only in TEST mode)
359 359 #
360   - # List of commands to be sent by this agent to other agents ("self" means himself)
  360 + # It is a list of commands to be sent by this agent to other agents ("self" means himself)
361 361 #
362   - # Command format is :
363   - # "[Recipient] Command [Args]"
364   - # with :
365   - # - [Recipient] optional, the name of the Agent the command is to be sent to (use "self" to mean himself)
366   - # - Command, the command name
367   - # - [Args] optional, the list of command arguments, separated by blanks : arg1 arg2 arg3 ...
  362 + # Format : List of tuples (command, expected_res), with :
  363 + #
  364 + # - command : the command format is "recipient cmd args", with :
  365 + # - recipient : name of the Agent that the command is to be sent to (use "self" to mean himself)
  366 + # - cmd : the command name
  367 + # - args : (optional) the list of command arguments, separated by blanks : arg1 arg2 arg3 ...
  368 + #
  369 + # - expected_res : le résultat attendu
368 370 #
369 371 # Ex :
370 372 # - "AgentScheduler set_state ATTENTIVE" => means to send the command "set_state ATTENTIVE" to the agent AgentScheduler
... ... @@ -372,57 +374,32 @@ class Agent:
372 374 # - "self set_state ATTENTIVE" => means to send the command "set_state ATTENTIVE" to MYSELF
373 375 # - "self do_restart_loop" => means to send the command "do_restart_loop" to MYSELF (no args)
374 376 #
375   - #TEST_COMMANDS = iter([
376   -
377   - '''
378   - NEW FORMAT
379 377 TEST_COMMANDS_LIST = [
380   - # 1) First, 3 EXCEPTION CASES :
381   - # Uncomment to activate exception
382 378  
383   - # - Agent general command malformed (missing arg) => ko, AgentCmdBadArgsException
384   - #"Agent set_state",
385   -
386   - # - Agent specific command, known but not implemented => ko, AgentCmdUnimplementedException
387   - #"self set_specific2",
388   -
389   - # - Agent specific command, implemented but missing args => ko, AgentCmdBadArgsException
390   - #" self do_specific1 1 ",
391   - [ "self", "do_specific1", [ 1, 2, 3.5, 'titi', (3,'titi',5), [1,3,5,7,9] ] ],
392   -
393   - # 2) NORMAL CASES
  379 + # 1) First, 3 EXCEPTION CASES (uncomment to activate exception)
  380 + # ------------------------------------------------------------
394 381  
395   - # Agent general command => ok
396   - #"Agent set_state ATTENTIVE",
397   - [ "Agent", "set_state", ["ATTENTIVE"] ],
398   - ]
399   - '''
400   -
401   - TEST_COMMANDS_LIST = [
402   -
403   - # 1) First, 3 EXCEPTION CASES :
404   - # Uncomment to activate exception
  382 + # - Agent command, unknown => ko, UnknownCmdException
  383 + ("self do_unknown", None),
405 384  
406 385 # - Agent general command malformed (missing arg) => ko, AgentCmdBadArgsException
407   - #"Agent set_state",
  386 + #("Agent set_mode", None),
408 387  
409 388 # - Agent specific command, known but not implemented => ko, AgentCmdUnimplementedException
410   - #"self set_specific2",
  389 + #("self set_specific2", None),
411 390  
412 391 # - Agent specific command, implemented but missing args => ko, AgentCmdBadArgsException
413   - #" self do_specific1 1 ",
414   -
415   - # - Agent command, unknown => ko, UnknownCmdException
416   - #"self do_specific3",
  392 + #(" self do_specific1 1 ", None),
417 393  
418 394  
419 395 # 2) NORMAL CASES (test scenario)
420   -
  396 + # -------------------------------
421 397  
422 398 # Agent general command
423 399 ("Agent set_mode ATTENTIVE", "MODE = ATTENTIVE"),
424 400 # => should get "ATTENTIVE"
425 401 ("self get_mode", "MODE = ATTENTIVE"),
  402 +
426 403 # => should get "7"
427 404 ("self do_eval 3+5-1", 7),
428 405  
... ... @@ -449,17 +426,17 @@ class Agent:
449 426  
450 427 # TODO: test priority commands : do_abort, do_flush_cmds, ...
451 428 # - Stop executing new commands (just let them accumulate)
452   - ##"self do_stop_exec",
453   - ##"self set_mode ATTENTIVE",
454   - ##"self get_mode",
455   - ##"self do_specific1 1 2 3.5 titi (3,'titi',5) [1,3,5,7,9]",
456   - ##"self set_mode ROUTINE",
457   - ##"self get_mode",
458   - ##"self do_abort",
  429 + ##("self do_stop_exec",),
  430 + ##("self set_mode ATTENTIVE",),
  431 + ##("self get_mode",),
  432 + ##("self do_specific1 1 2 3.5 titi (3,'titi',5) [1,3,5,7,9]",),
  433 + ##("self set_mode ROUTINE",),
  434 + ##("self get_mode",),
  435 + ##("self do_abort",),
459 436 # - Now, resume execution of commands :
460 437 # we should have the previous list pending,
461 438 # but as "do_abort" is priority, it should be executed first even if last !
462   - ##"self do_resume_exec",
  439 + ##("self do_resume_exec",),
463 440  
464 441 # Restart the restart loop (from init())
465 442 ("self do_restart_loop", "RESTARTING"),
... ... @@ -2161,7 +2138,8 @@ class Agent:
2161 2138 if self.TEST_MODE: log.info("in TEST MODE")
2162 2139  
2163 2140 def _TEST_get_next_command_to_send(self)->AgentCmd:
2164   - (cmd_full_name, res_expected) = next(self.TEST_COMMANDS, (None,None))
  2141 + cmd_full_name, res_expected = next(self.TEST_COMMANDS, (None,None))
  2142 + #print(cmd_full_name, res_expected)
2165 2143 #return cmd_name
2166 2144 if cmd_full_name is None: return None
2167 2145 # Remove excessive spaces
... ...
src/core/pyros_django/common/models.py
... ... @@ -491,6 +491,9 @@ class AgentCmd(models.Model):
491 491  
492 492 # SET commands
493 493 # -----------
  494 +
  495 + # - Set agent current STATE (IN_MAIN_LOOP, ...) => forbidden
  496 + #"set_state",
494 497  
495 498 # - Set agent current MODE (idle, routine, attentive)
496 499 "set_mode", # + value to set
... ...