mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 18:17:59 +02:00
commands code generation (#871)
* commands code generation (#803) * commands code generation for only frames command * fix cmake file and add Caller files * working exptime, fully extended commands file and its variants * start adding template commands * add INT_CMD_VEC_ID template * add list command, generate multiple bins, format code * reach 208 commands using the cpp macros * add tests for command parser * start adding tests for commands parser * fix typo to use commands.yaml * add more tests for command_parser * add all template functions (up to 218 commands) * finish template functions and add more CmdProxy.cpp functions (250+) * 257 commands * 300 commands the rest are very special commands * add special commands without generation * separate special functions from generated c++ file * implementing one command for put and get (buggy) * add infer action in a separate file * generate header for special commands from yaml * allow only 0 or 1 for bool inputs * group all commands in gen_commands.py * add help to gen_commands.py * add autocomplete bash script * autocompletion: add support for module levels and help * remove debugging line * add autocompletion, help to commands, change int [0,1] to bool * copy tests for Caller.cpp. Tests pass * update with the new developer branch changes * fix errors after merging (there is problems with tests) * fixed port/stopport in yaml (intput typo), added '_caller' to the test dac and test on chip dac command in global test for cmdcaller * undo previous test simulator debug change * add documentation for the generated code * reducing the comment to be replaced in length so formatting does not split into 2 lines * removed formatting specific style of C++11 in gen_commands.py to keep with the top level clang format of the project * regeneratign code for commands * automation generated * Redirect deprecated commands (#872) * working implementation, need to fix dac * fixed deprecation redirect for dac command * Detector specific autocomplete (#873) * working implementation, need to fix dac * fixed deprecation redirect for dac command * detector specific completion for dac * added autocomplete using detector specific * fixed error when autocompleting partial words * Generate commands/fix commands (#875) * fix vm_a, im_a etc have deg Celsius suffix, also help missing or changed in some places * dac: require det id for all, arg0 to be printed at output, help for onchip dac and dac, onchipdac: spacing * getscan detid and blocking trigger help * udp_Dstlist det_id fixed, but rx_id invalid * cmdApp in line with cmdLineApp (missing version, receiver_id, not creating det object in help action * added set_command to differentiate between check_det_id and require_det_id (mixed up), args: -1 needs to check for at least one argument * reordering * reordering and checked till integer_command_hex * fixed a lot more commands * fix caller tests for eiger * changes to tests after Bechir left * changing .cmd to .cmdcall for the caller commands * fixed tests for caller, still warning for setexptime about cast input * autocomplete ran * add moench test * regenerating autocomplete and commands * fixing other things from merge conflicts (renaming slsDetectorDefs to defs in commands.yaml) * formatting * added code injection to help (#876) * updated 3 commands to have get output that can be put into put (#877) * updated some commands to have get output that can be put into put * fix tests for clkdiv * adding help to free (#878) * removing old commands and renaming them, (also making it work for parameters command as it was still calling cmdproxy) (#879) * More helpful error messages for unsupported actions (#880) * removing old commands and renaming them, (also making it work for parameters command as it was still calling cmdproxy) * Added specific help for unsupported actions * fixed a vetofile get special exception message. more specific warning for special exception message instead of no function warning * added condition checking true in exceptions for special message --------- Co-authored-by: Bechir Brahem <bachbrahem@gmail.com> Co-authored-by: Erik Frojdh <erik.frojdh@gmail.com> Co-authored-by: Dhanya Thattil <dhanya.thattil@psi.ch>
This commit is contained in:
@ -0,0 +1,16 @@
|
||||
basic:
|
||||
infer_action: false
|
||||
help: "xx11"
|
||||
actions:
|
||||
GET:
|
||||
function: 'func1'
|
||||
output: [ OutString(t) ]
|
||||
args:
|
||||
- argc: 0
|
||||
PUT:
|
||||
function: 'func2'
|
||||
output: [ 'args.front()' ]
|
||||
input: [ 'args[0]' ]
|
||||
input_types: [ int ]
|
||||
cast_input: [ true ]
|
||||
argc: 1
|
@ -0,0 +1,66 @@
|
||||
---
|
||||
template:
|
||||
infer_action: false
|
||||
help: ""
|
||||
actions:
|
||||
GET:
|
||||
function: 'func1'
|
||||
args:
|
||||
- argc: 0
|
||||
output: [ OutString(t) ]
|
||||
PUT:
|
||||
function: 'func2'
|
||||
output: [ 'args.front()' ]
|
||||
input: [ 'args[0]' ]
|
||||
input_types: [ int ]
|
||||
cast_input: [ true ]
|
||||
argc: 1
|
||||
|
||||
basic:
|
||||
help: "xx11"
|
||||
inherit_actions: template
|
||||
actions:
|
||||
GET:
|
||||
function: 'x'
|
||||
argc: 2
|
||||
args:
|
||||
- check_det_id: true
|
||||
|
||||
|
||||
template2:
|
||||
infer_action: false
|
||||
template: true
|
||||
help: ""
|
||||
actions:
|
||||
GET:
|
||||
convert_to_time:
|
||||
input: [ 'args[0]', 'args[1]' ]
|
||||
output: converted_time
|
||||
separate_time_units:
|
||||
input: 'args[0]'
|
||||
output: [ converted_time, unit ]
|
||||
function: 'func1'
|
||||
output: [ OutString(t) ]
|
||||
args:
|
||||
- argc: 0
|
||||
- argc: 99
|
||||
PUT:
|
||||
function: funcTemplatePUT
|
||||
args:
|
||||
- argc: 19
|
||||
function: 'func19'
|
||||
- argc: 91
|
||||
|
||||
basic2:
|
||||
inherit_actions: template2
|
||||
actions:
|
||||
GET:
|
||||
function: 'x'
|
||||
argc: 2
|
||||
args:
|
||||
- check_det_id: true
|
||||
input: [ 'args[0]', a,b,c ]
|
||||
input_types: [ int, int, int, int ]
|
||||
PUT:
|
||||
function: 'y'
|
||||
|
@ -0,0 +1,208 @@
|
||||
basic:
|
||||
infer_action: false
|
||||
help: "xx11"
|
||||
actions:
|
||||
GET:
|
||||
function: 'func1'
|
||||
output: [ OutString(t) ]
|
||||
args:
|
||||
- argc: 0
|
||||
- argc : 1
|
||||
output: [ testytest ]
|
||||
detectors:
|
||||
MYTHEN3:
|
||||
function: 'do_mythen3'
|
||||
CHIPTESTBOARD:
|
||||
args:
|
||||
- argc: 55
|
||||
output: [ ctbOutput ]
|
||||
PUT:
|
||||
detectors:
|
||||
EIGER:
|
||||
function: 'do_eiger'
|
||||
argc: 99
|
||||
output: [ eigerOutput ]
|
||||
|
||||
|
||||
# classes of tests:
|
||||
# classes of template tests: has args or has detectors => 4 cases noted (0,0) ... (1,1)
|
||||
# classes of childs: has args or has detectors => 4 cases noted (0,0) ... (1,1)
|
||||
# => 16 cases
|
||||
# example: case_0111: template (0,1) and child (1,1)
|
||||
#################### exhaustive testing over chosen classes of tests
|
||||
|
||||
template_01:
|
||||
infer_action: true
|
||||
help: "vv12"
|
||||
template: true
|
||||
|
||||
actions:
|
||||
GET:
|
||||
detectors:
|
||||
MYTHEN3:
|
||||
function: 'do_mythen3'
|
||||
argc: 99
|
||||
CHIPTESTBOARD:
|
||||
function: 'do_ctb'
|
||||
argc: 98
|
||||
|
||||
case_0100:
|
||||
inherit_actions: template_01
|
||||
help: "0100"
|
||||
|
||||
case_0101:
|
||||
inherit_actions: template_01
|
||||
help: "0101"
|
||||
actions:
|
||||
GET:
|
||||
function: 'get_function'
|
||||
detectors:
|
||||
MYTHEN3:
|
||||
function: 'do_mythen23'
|
||||
argc: 420
|
||||
|
||||
case_0110:
|
||||
inherit_actions: template_01
|
||||
help: "0110"
|
||||
actions:
|
||||
GET:
|
||||
argc: 111
|
||||
function: 'get_function'
|
||||
|
||||
case_0110v2:
|
||||
inherit_actions: template_01
|
||||
help: "0110v2"
|
||||
actions:
|
||||
GET:
|
||||
args:
|
||||
- argc: 111
|
||||
function: 'get_function'
|
||||
|
||||
|
||||
case_0111:
|
||||
inherit_actions: template_01
|
||||
help: "0111"
|
||||
actions:
|
||||
GET:
|
||||
args:
|
||||
- argc: 111
|
||||
function: 'get_function'
|
||||
detectors:
|
||||
MYTHEN3:
|
||||
function: 'do_mythen23'
|
||||
argc: 420
|
||||
|
||||
##### cases 10** tests
|
||||
template_10:
|
||||
template: true
|
||||
actions:
|
||||
GET:
|
||||
args:
|
||||
- argc: 0
|
||||
- argc : 1
|
||||
output: [ testytest ]
|
||||
|
||||
case_1000:
|
||||
inherit_actions: template_10
|
||||
help: "1000"
|
||||
|
||||
case_1001:
|
||||
inherit_actions: template_10
|
||||
help: "1001"
|
||||
actions:
|
||||
GET:
|
||||
detectors:
|
||||
MYTHEN3:
|
||||
args:
|
||||
- function: 'do_mythen23'
|
||||
argc: 420
|
||||
- function: 'do_mythen3'
|
||||
argc: 99
|
||||
|
||||
|
||||
|
||||
case_1010:
|
||||
inherit_actions: template_10
|
||||
help: "1010"
|
||||
actions:
|
||||
GET:
|
||||
args:
|
||||
- argc: 111
|
||||
function: 'get_function'
|
||||
|
||||
case_1011:
|
||||
inherit_actions: template_10
|
||||
help: "1011"
|
||||
actions:
|
||||
GET:
|
||||
args:
|
||||
- argc: 111
|
||||
function: 'get_function'
|
||||
detectors:
|
||||
MYTHEN3:
|
||||
function: 'do_mythen23'
|
||||
|
||||
##### cases 11** tests
|
||||
template_11:
|
||||
template: true
|
||||
actions:
|
||||
GET:
|
||||
args:
|
||||
- argc: 0
|
||||
- argc : 1
|
||||
output: [ testytest ]
|
||||
detectors:
|
||||
EIGER:
|
||||
function: 'do_eiger'
|
||||
args:
|
||||
- argc: 99
|
||||
output: [ eigerOutput ]
|
||||
POTATO:
|
||||
function: 'do_potato'
|
||||
|
||||
|
||||
case_1100:
|
||||
inherit_actions: template_11
|
||||
help: "1100"
|
||||
|
||||
case_1101:
|
||||
inherit_actions: template_11
|
||||
help: "1101"
|
||||
actions:
|
||||
GET:
|
||||
detectors:
|
||||
MYTHEN3:
|
||||
function: 'do_mythen3'
|
||||
POTATO:
|
||||
function: 'do_potato'
|
||||
args:
|
||||
- argc: 101
|
||||
function: 'potato_function'
|
||||
- argc: 202
|
||||
|
||||
case_1110:
|
||||
inherit_actions: template_11
|
||||
help: "1110"
|
||||
actions:
|
||||
GET:
|
||||
argc: 77
|
||||
function: 'get_function'
|
||||
|
||||
|
||||
|
||||
case_1111:
|
||||
inherit_actions: template_11
|
||||
help: "1111"
|
||||
actions:
|
||||
GET:
|
||||
argc: 77
|
||||
function: 'get_function'
|
||||
detectors:
|
||||
MYTHEN3:
|
||||
function: 'do_mythen3'
|
||||
POTATO:
|
||||
function: 'do_potato'
|
||||
args:
|
||||
- argc: 101
|
||||
function: 'potato_function'
|
||||
- argc: 202
|
@ -0,0 +1,101 @@
|
||||
from pathlib import Path
|
||||
|
||||
import yaml
|
||||
|
||||
from commands_parser.commands_parser import CommandParser
|
||||
|
||||
data_path = Path(__file__).parent.parent / "data"
|
||||
|
||||
|
||||
def test_basic_propagation(tmp_path):
|
||||
output_file = tmp_path / "basic.yaml"
|
||||
command_parser = CommandParser(commands_file=data_path / "basic.yaml", output_file=output_file)
|
||||
command_parser.verify_format()
|
||||
command_parser.parse_all_commands()
|
||||
|
||||
assert output_file.exists()
|
||||
command = yaml.unsafe_load(output_file.open('r'))['basic']
|
||||
assert command['help'] == "xx11"
|
||||
assert len(command['actions']) == 2
|
||||
# test 'GET' action
|
||||
assert 'args' in command['actions']['GET']
|
||||
assert len(command['actions']['GET'].keys()) == 1 # only 'args' key
|
||||
assert len(command['actions']['GET']['args']) == 1 # only one argument
|
||||
assert command['actions']['GET']['args'][0]['argc'] == 0
|
||||
assert command['actions']['GET']['args'][0]['function'] == 'func1'
|
||||
assert command['actions']['GET']['args'][0]['output'] == ['OutString(t)']
|
||||
assert command['actions']['GET']['args'][0]['input'] == []
|
||||
assert command['actions']['GET']['args'][0]['cast_input'] == []
|
||||
assert command['actions']['GET']['args'][0]['require_det_id'] is False
|
||||
# test PUT action
|
||||
assert 'args' in command['actions']['PUT']
|
||||
assert len(command['actions']['PUT'].keys()) == 1 # only 'args' key
|
||||
assert len(command['actions']['PUT']['args']) == 1 # only one argument
|
||||
assert command['actions']['PUT']['args'][0]['argc'] == 1
|
||||
assert command['actions']['PUT']['args'][0]['function'] == 'func2'
|
||||
assert command['actions']['PUT']['args'][0]['cast_input'] == [True]
|
||||
assert command['actions']['PUT']['args'][0]['output'] == ['args.front()']
|
||||
assert command['actions']['PUT']['args'][0]['input_types'] == ['int']
|
||||
assert command['actions']['PUT']['args'][0]['require_det_id'] is False
|
||||
|
||||
|
||||
def test_basic_inheritance(tmp_path):
|
||||
output_file = tmp_path / "basic_inheritance.yaml"
|
||||
command_parser = CommandParser(commands_file=data_path / "basic_inheritance.yaml", output_file=output_file)
|
||||
command_parser.verify_format()
|
||||
command_parser.parse_all_commands()
|
||||
assert output_file.exists()
|
||||
command = yaml.unsafe_load(output_file.open('r'))['basic']
|
||||
assert command['help'] == "xx11"
|
||||
assert command['actions'].keys() == {'GET', 'PUT'}
|
||||
# test 'GET' action
|
||||
assert 'args' in command['actions']['GET']
|
||||
assert command['actions']['GET'].keys() == {'args'} # only 'args' key
|
||||
assert len(command['actions']['GET']['args']) == 1 # only one argument
|
||||
assert command['actions']['GET']['args'][0]['argc'] == 2
|
||||
assert command['actions']['GET']['args'][0]['function'] == 'x'
|
||||
assert command['actions']['GET']['args'][0]['output'] == [] # test overwriting args when they are present in child
|
||||
assert command['actions']['GET']['args'][0]['input'] == []
|
||||
assert command['actions']['GET']['args'][0]['cast_input'] == []
|
||||
assert command['actions']['GET']['args'][0]['require_det_id'] is False
|
||||
# test PUT action
|
||||
assert 'args' in command['actions']['PUT']
|
||||
assert command['actions']['PUT'].keys() == {'args'} # only 'args' key
|
||||
assert len(command['actions']['PUT']['args']) == 1 # only one argument
|
||||
assert command['actions']['PUT']['args'][0]['argc'] == 1
|
||||
assert command['actions']['PUT']['args'][0]['function'] == 'func2'
|
||||
assert command['actions']['PUT']['args'][0]['cast_input'] == [True]
|
||||
assert command['actions']['PUT']['args'][0]['output'] == ['args.front()']
|
||||
assert command['actions']['PUT']['args'][0]['input_types'] == ['int']
|
||||
assert command['actions']['PUT']['args'][0]['require_det_id'] is False
|
||||
|
||||
|
||||
def test_basic_inheritance2(tmp_path):
|
||||
output_file = tmp_path / "basic_inheritance.yaml"
|
||||
command_parser = CommandParser(commands_file=data_path / "basic_inheritance.yaml", output_file=output_file)
|
||||
command_parser.verify_format()
|
||||
command_parser.parse_all_commands()
|
||||
assert output_file.exists()
|
||||
command = yaml.unsafe_load(output_file.open('r'))['basic2']
|
||||
# check GET
|
||||
assert len(command['actions']['GET']['args']) == 1
|
||||
assert command['actions']['GET'].keys() == {'args'}
|
||||
arg = command['actions']['GET']['args'][0]
|
||||
assert arg['argc'] == 2
|
||||
assert arg['output'] == ['OutString(t)']
|
||||
# check that length of cast input is equal to length of input_types and input
|
||||
assert len(arg['input']) == len(arg['input_types']) == len(arg['cast_input']) == 4
|
||||
assert arg['function'] == 'x'
|
||||
assert 'convert_to_time' in arg
|
||||
assert arg['convert_to_time'].keys() == {'input', 'output'}
|
||||
assert 'separate_time_units' in arg
|
||||
assert arg['separate_time_units'].keys() == {'input', 'output'}
|
||||
|
||||
# check PUT
|
||||
assert command['actions']['PUT'].keys() == {'args'}
|
||||
assert len(command['actions']['PUT']['args']) == 2
|
||||
assert command['actions']['PUT']['args'][0]['argc'] == 19
|
||||
assert command['actions']['PUT']['args'][0]['function'] == 'y'
|
||||
assert command['actions']['PUT']['args'][1]['argc'] == 91
|
||||
assert command['actions']['PUT']['args'][1]['function'] == 'y'
|
||||
|
@ -0,0 +1,309 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import pytest as pytest
|
||||
import yaml
|
||||
|
||||
from commands_parser.commands_parser import CommandParser
|
||||
|
||||
data_path = Path(__file__).parent.parent / "data"
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def detector_file_commands(tmp_path):
|
||||
output_file = tmp_path / "detectors.yaml"
|
||||
command_parser = CommandParser(commands_file=data_path / "detectors.yaml", output_file=output_file)
|
||||
command_parser.verify_format()
|
||||
|
||||
def func(command):
|
||||
return command_parser.parse_command(command)
|
||||
|
||||
return func
|
||||
|
||||
|
||||
def test_basic_propagation(tmp_path, detector_file_commands):
|
||||
command = detector_file_commands('basic')
|
||||
|
||||
assert command['help'] == "xx11"
|
||||
|
||||
# GET
|
||||
assert command['actions']['GET'].keys() == {'detectors', 'args'}
|
||||
assert command['actions']['GET']['detectors'].keys() == {'MYTHEN3', 'CHIPTESTBOARD'}
|
||||
mythen = command['actions']['GET']['detectors']['MYTHEN3']
|
||||
assert len(mythen) == 2
|
||||
assert mythen[0]['argc'] == 0
|
||||
assert mythen[1]['argc'] == 1
|
||||
assert mythen[0]['function'] == mythen[1]['function'] == 'do_mythen3'
|
||||
assert mythen[0]['output'] == ['OutString(t)']
|
||||
assert mythen[1]['output'] == ['testytest']
|
||||
|
||||
ctb = command['actions']['GET']['detectors']['CHIPTESTBOARD']
|
||||
assert len(ctb) == 1
|
||||
assert ctb[0]['argc'] == 55
|
||||
assert ctb[0]['function'] == 'func1'
|
||||
|
||||
# PUT
|
||||
assert command['actions']['PUT'].keys() == {'detectors'}
|
||||
assert command['actions']['PUT']['detectors'].keys() == {'EIGER'}
|
||||
eiger = command['actions']['PUT']['detectors']['EIGER']
|
||||
assert len(eiger) == 1
|
||||
assert eiger[0]['argc'] == 99
|
||||
assert eiger[0]['function'] == 'do_eiger'
|
||||
assert eiger[0]['output'] == ['eigerOutput']
|
||||
|
||||
# 16 test cases for inheritance
|
||||
# 1st bit: parent has args
|
||||
# 2nd bit: parent has detectors
|
||||
# 3rd bit: child has args
|
||||
# 4th bit: child has detectors
|
||||
# each test case is a combination of the above bits
|
||||
# all the possible combinations are tested
|
||||
|
||||
def test_inheritance_0100(tmp_path, detector_file_commands):
|
||||
command = detector_file_commands('case_0100')
|
||||
assert command['help'] == "0100"
|
||||
assert 'actions' in command
|
||||
assert command['actions'].keys() == {'GET'}
|
||||
assert command['actions']['GET'].keys() == {'detectors'}
|
||||
assert command['actions']['GET']['detectors'].keys() == {'MYTHEN3', 'CHIPTESTBOARD'}
|
||||
mythen = command['actions']['GET']['detectors']['MYTHEN3']
|
||||
assert len(mythen) == 1
|
||||
assert mythen[0]['argc'] == 99
|
||||
assert mythen[0]['function'] == 'do_mythen3'
|
||||
|
||||
|
||||
def test_inheritance_0101(tmp_path, detector_file_commands):
|
||||
command = detector_file_commands('case_0101')
|
||||
assert command['help'] == "0101"
|
||||
assert 'actions' in command
|
||||
assert command['actions'].keys() == {'GET'}
|
||||
assert command['actions']['GET'].keys() == {'detectors'}
|
||||
assert command['actions']['GET']['detectors'].keys() == {'MYTHEN3', 'CHIPTESTBOARD'}
|
||||
mythen = command['actions']['GET']['detectors']['MYTHEN3']
|
||||
assert len(mythen) == 1
|
||||
assert mythen[0]['argc'] == 420
|
||||
assert mythen[0]['function'] == 'do_mythen23'
|
||||
ctb = command['actions']['GET']['detectors']['CHIPTESTBOARD']
|
||||
assert len(ctb) == 1
|
||||
assert ctb[0]['argc'] == 98
|
||||
assert ctb[0]['function'] == 'do_ctb'
|
||||
|
||||
|
||||
def test_inheritance_0110(tmp_path, detector_file_commands):
|
||||
command = detector_file_commands('case_0110')
|
||||
assert command['help'] == "0110"
|
||||
assert 'actions' in command
|
||||
assert command['actions'].keys() == {'GET'}
|
||||
assert command['actions']['GET'].keys() == {'args', 'detectors'}
|
||||
assert command['actions']['GET']['args'][0]['argc'] == 111
|
||||
mythen = command['actions']['GET']['detectors']['MYTHEN3']
|
||||
assert len(mythen) == 1
|
||||
assert mythen[0]['argc'] == 99
|
||||
assert mythen[0]['function'] == 'do_mythen3'
|
||||
ctb = command['actions']['GET']['detectors']['CHIPTESTBOARD']
|
||||
assert len(ctb) == 1
|
||||
assert ctb[0]['argc'] == 98
|
||||
assert ctb[0]['function'] == 'do_ctb'
|
||||
|
||||
|
||||
def test_inheritance_0110v2(tmp_path, detector_file_commands):
|
||||
command = detector_file_commands('case_0110v2')
|
||||
assert command['help'] == "0110v2"
|
||||
assert 'actions' in command
|
||||
assert command['actions'].keys() == {'GET'}
|
||||
assert command['actions']['GET'].keys() == {'args', 'detectors'}
|
||||
assert command['actions']['GET']['args'][0]['argc'] == 111
|
||||
mythen = command['actions']['GET']['detectors']['MYTHEN3']
|
||||
assert len(mythen) == 1
|
||||
assert mythen[0]['argc'] == 99
|
||||
assert mythen[0]['function'] == 'do_mythen3'
|
||||
ctb = command['actions']['GET']['detectors']['CHIPTESTBOARD']
|
||||
assert len(ctb) == 1
|
||||
assert ctb[0]['argc'] == 98
|
||||
assert ctb[0]['function'] == 'do_ctb'
|
||||
|
||||
|
||||
def test_inheritacnce_0111(tmp_path, detector_file_commands):
|
||||
command = detector_file_commands('case_0111')
|
||||
assert command['help'] == "0111"
|
||||
assert 'actions' in command
|
||||
assert command['actions'].keys() == {'GET'}
|
||||
assert command['actions']['GET'].keys() == {'args', 'detectors'}
|
||||
assert command['actions']['GET']['detectors'].keys() == {'MYTHEN3', 'CHIPTESTBOARD'}
|
||||
mythen = command['actions']['GET']['detectors']['MYTHEN3']
|
||||
assert len(mythen) == 1
|
||||
assert command['actions']['GET']['args'][0]['argc'] == 111
|
||||
assert len(mythen) == 1
|
||||
assert mythen[0]['argc'] == 420
|
||||
assert mythen[0]['function'] == 'do_mythen23'
|
||||
ctb = command['actions']['GET']['detectors']['CHIPTESTBOARD']
|
||||
assert len(ctb) == 1
|
||||
assert ctb[0]['argc'] == 98
|
||||
assert ctb[0]['function'] == 'do_ctb'
|
||||
|
||||
|
||||
# cases 1000, 1001, 1010, 1011
|
||||
def test_inheritance_1000(tmp_path, detector_file_commands):
|
||||
command = detector_file_commands('case_1000')
|
||||
assert command['help'] == "1000"
|
||||
assert 'actions' in command
|
||||
assert command['actions'].keys() == {'GET'}
|
||||
assert command['actions']['GET'].keys() == {'args'}
|
||||
assert len(command['actions']['GET']['args']) == 2
|
||||
assert command['actions']['GET']['args'][0]['argc'] == 0
|
||||
assert command['actions']['GET']['args'][0]['output'] == []
|
||||
|
||||
assert command['actions']['GET']['args'][1]['argc'] == 1
|
||||
assert command['actions']['GET']['args'][1]['output'] == ['testytest']
|
||||
|
||||
|
||||
def test_inheritance_1001(tmp_path, detector_file_commands):
|
||||
command = detector_file_commands('case_1001')
|
||||
assert command['help'] == "1001"
|
||||
assert 'actions' in command
|
||||
assert command['actions'].keys() == {'GET'}
|
||||
assert command['actions']['GET'].keys() == {'args', 'detectors'}
|
||||
assert len(command['actions']['GET']['args']) == 2
|
||||
assert command['actions']['GET']['args'][0]['argc'] == 0
|
||||
assert command['actions']['GET']['args'][0]['output'] == []
|
||||
assert command['actions']['GET']['args'][1]['argc'] == 1
|
||||
assert command['actions']['GET']['args'][1]['output'] == ['testytest']
|
||||
|
||||
assert command['actions']['GET']['detectors'].keys() == {'MYTHEN3'}
|
||||
assert len(command['actions']['GET']['detectors']['MYTHEN3']) == 2
|
||||
assert command['actions']['GET']['detectors']['MYTHEN3'][0]['argc'] == 420
|
||||
assert command['actions']['GET']['detectors']['MYTHEN3'][0]['function'] == 'do_mythen23'
|
||||
assert command['actions']['GET']['detectors']['MYTHEN3'][1]['argc'] == 99
|
||||
assert command['actions']['GET']['detectors']['MYTHEN3'][1]['function'] == 'do_mythen3'
|
||||
|
||||
|
||||
def test_inheritance_1010(tmp_path, detector_file_commands):
|
||||
command = detector_file_commands('case_1010')
|
||||
assert command['help'] == "1010"
|
||||
assert 'actions' in command
|
||||
assert command['actions'].keys() == {'GET'}
|
||||
assert command['actions']['GET'].keys() == {'args'}
|
||||
assert len(command['actions']['GET']['args']) == 1
|
||||
assert command['actions']['GET']['args'][0]['argc'] == 111
|
||||
assert command['actions']['GET']['args'][0]['function'] == 'get_function'
|
||||
|
||||
|
||||
def test_inheritance_1011(tmp_path, detector_file_commands):
|
||||
command = detector_file_commands('case_1011')
|
||||
assert command['help'] == "1011"
|
||||
assert 'actions' in command
|
||||
assert command['actions'].keys() == {'GET'}
|
||||
assert command['actions']['GET'].keys() == {'args', 'detectors'}
|
||||
assert len(command['actions']['GET']['args']) == 1
|
||||
assert command['actions']['GET']['args'][0]['argc'] == 111
|
||||
assert command['actions']['GET']['args'][0]['function'] == 'get_function'
|
||||
|
||||
assert command['actions']['GET']['detectors'].keys() == {'MYTHEN3'}
|
||||
assert len(command['actions']['GET']['detectors']['MYTHEN3']) == 1
|
||||
assert command['actions']['GET']['detectors']['MYTHEN3'][0]['argc'] == 111
|
||||
assert command['actions']['GET']['detectors']['MYTHEN3'][0]['function'] == 'do_mythen23'
|
||||
|
||||
|
||||
# cases 1100, 1101, 1110, 1111
|
||||
|
||||
def test_inheritance_1100(tmp_path, detector_file_commands):
|
||||
command = detector_file_commands('case_1100')
|
||||
assert command['help'] == "1100"
|
||||
assert 'actions' in command
|
||||
assert command['actions'].keys() == {'GET'}
|
||||
assert command['actions']['GET'].keys() == {'args', 'detectors'}
|
||||
assert len(command['actions']['GET']['args']) == 2
|
||||
assert command['actions']['GET']['args'][0]['argc'] == 0
|
||||
assert command['actions']['GET']['args'][0]['output'] == []
|
||||
|
||||
assert command['actions']['GET']['args'][1]['argc'] == 1
|
||||
assert command['actions']['GET']['args'][1]['output'] == ['testytest']
|
||||
|
||||
assert command['actions']['GET']['detectors'].keys() == {'EIGER', 'POTATO'}
|
||||
assert len(command['actions']['GET']['detectors']['EIGER']) == 1
|
||||
assert command['actions']['GET']['detectors']['EIGER'][0]['argc'] == 99
|
||||
assert command['actions']['GET']['detectors']['EIGER'][0]['function'] == 'do_eiger'
|
||||
assert command['actions']['GET']['detectors']['EIGER'][0]['output'] == ['eigerOutput']
|
||||
|
||||
assert len(command['actions']['GET']['detectors']['POTATO']) == 2
|
||||
assert command['actions']['GET']['detectors']['POTATO'][0]['argc'] == 0
|
||||
assert command['actions']['GET']['detectors']['POTATO'][0]['function'] == 'do_potato'
|
||||
|
||||
|
||||
def test_inheritance_1101(tmp_path, detector_file_commands):
|
||||
command = detector_file_commands('case_1101')
|
||||
assert command['help'] == "1101"
|
||||
assert 'actions' in command
|
||||
assert command['actions'].keys() == {'GET'}
|
||||
assert command['actions']['GET'].keys() == {'args', 'detectors'}
|
||||
assert len(command['actions']['GET']['args']) == 2
|
||||
assert command['actions']['GET']['args'][0]['argc'] == 0
|
||||
assert command['actions']['GET']['args'][0]['output'] == []
|
||||
assert command['actions']['GET']['args'][1]['argc'] == 1
|
||||
assert command['actions']['GET']['args'][1]['output'] == ['testytest']
|
||||
|
||||
assert command['actions']['GET']['detectors'].keys() == {'EIGER', 'MYTHEN3', 'POTATO'}
|
||||
assert len(command['actions']['GET']['detectors']['MYTHEN3']) == 2
|
||||
assert command['actions']['GET']['detectors']['MYTHEN3'][0]['argc'] == 0
|
||||
assert command['actions']['GET']['detectors']['MYTHEN3'][0]['function'] == 'do_mythen3'
|
||||
assert command['actions']['GET']['detectors']['MYTHEN3'][1]['argc'] == 1
|
||||
assert command['actions']['GET']['detectors']['MYTHEN3'][1]['function'] == 'do_mythen3'
|
||||
|
||||
assert len(command['actions']['GET']['detectors']['EIGER']) == 1
|
||||
assert command['actions']['GET']['detectors']['EIGER'][0]['argc'] == 99
|
||||
assert command['actions']['GET']['detectors']['EIGER'][0]['function'] == 'do_eiger'
|
||||
assert command['actions']['GET']['detectors']['EIGER'][0]['output'] == ['eigerOutput']
|
||||
|
||||
assert len(command['actions']['GET']['detectors']['POTATO']) == 2
|
||||
assert command['actions']['GET']['detectors']['POTATO'][0]['argc'] == 101
|
||||
assert command['actions']['GET']['detectors']['POTATO'][0]['function'] == 'potato_function'
|
||||
assert command['actions']['GET']['detectors']['POTATO'][1]['argc'] == 202
|
||||
assert command['actions']['GET']['detectors']['POTATO'][1]['function'] == 'do_potato'
|
||||
|
||||
|
||||
def test_inheritance_1110(tmp_path, detector_file_commands):
|
||||
command = detector_file_commands('case_1110')
|
||||
assert command['help'] == "1110"
|
||||
assert 'actions' in command
|
||||
assert command['actions'].keys() == {'GET'}
|
||||
assert command['actions']['GET'].keys() == {'args', 'detectors'}
|
||||
assert len(command['actions']['GET']['args']) == 1
|
||||
assert command['actions']['GET']['args'][0]['argc'] == 77
|
||||
assert command['actions']['GET']['args'][0]['function'] == 'get_function'
|
||||
|
||||
assert command['actions']['GET']['detectors'].keys() == {'EIGER', 'POTATO'}
|
||||
assert len(command['actions']['GET']['detectors']['EIGER']) == 1
|
||||
assert command['actions']['GET']['detectors']['EIGER'][0]['argc'] == 99
|
||||
assert command['actions']['GET']['detectors']['EIGER'][0]['function'] == 'do_eiger'
|
||||
|
||||
assert len(command['actions']['GET']['detectors']['POTATO']) == 2
|
||||
assert command['actions']['GET']['detectors']['POTATO'][0]['argc'] == 0
|
||||
assert command['actions']['GET']['detectors']['POTATO'][0]['function'] == 'do_potato'
|
||||
assert command['actions']['GET']['detectors']['POTATO'][1]['argc'] == 1
|
||||
assert command['actions']['GET']['detectors']['POTATO'][1]['function'] == 'do_potato'
|
||||
|
||||
|
||||
def test_inheritance_1111(tmp_path, detector_file_commands):
|
||||
command = detector_file_commands('case_1111')
|
||||
assert command['help'] == "1111"
|
||||
assert 'actions' in command
|
||||
assert command['actions'].keys() == {'GET'}
|
||||
assert command['actions']['GET'].keys() == {'args', 'detectors'}
|
||||
assert len(command['actions']['GET']['args']) == 1
|
||||
assert command['actions']['GET']['args'][0]['argc'] == 77
|
||||
assert command['actions']['GET']['args'][0]['function'] == 'get_function'
|
||||
|
||||
assert command['actions']['GET']['detectors'].keys() == {'EIGER', 'MYTHEN3', 'POTATO'}
|
||||
assert len(command['actions']['GET']['detectors']['MYTHEN3']) == 1
|
||||
assert command['actions']['GET']['detectors']['MYTHEN3'][0]['argc'] == 77
|
||||
assert command['actions']['GET']['detectors']['MYTHEN3'][0]['function'] == 'do_mythen3'
|
||||
|
||||
assert len(command['actions']['GET']['detectors']['EIGER']) == 1
|
||||
assert command['actions']['GET']['detectors']['EIGER'][0]['argc'] == 99
|
||||
assert command['actions']['GET']['detectors']['EIGER'][0]['function'] == 'do_eiger'
|
||||
|
||||
assert len(command['actions']['GET']['detectors']['POTATO']) == 2
|
||||
assert command['actions']['GET']['detectors']['POTATO'][0]['argc'] == 101
|
||||
assert command['actions']['GET']['detectors']['POTATO'][0]['function'] == 'potato_function'
|
||||
assert command['actions']['GET']['detectors']['POTATO'][1]['argc'] == 202
|
||||
assert command['actions']['GET']['detectors']['POTATO'][1]['function'] == 'do_potato'
|
@ -0,0 +1,29 @@
|
||||
from pathlib import Path
|
||||
from commands_parser.commands_parser import CommandParser
|
||||
import gen_commands
|
||||
|
||||
data_path = Path(__file__).parent.parent
|
||||
|
||||
|
||||
def test_parse_and_generate(tmp_path):
|
||||
"""
|
||||
tests that the parse and generate functions work without errors
|
||||
:param tmp_path:
|
||||
:return:
|
||||
"""
|
||||
output_file = tmp_path / "detectors.yaml"
|
||||
command_parser = CommandParser(commands_file=data_path / "commands.yaml", output_file=output_file)
|
||||
command_parser.verify_format()
|
||||
command_parser.parse_all_commands()
|
||||
assert output_file.exists()
|
||||
|
||||
GEN_PATH = Path(__file__).parent.parent
|
||||
gen_commands.generate(
|
||||
output_file,
|
||||
GEN_PATH / "Caller.in.cpp",
|
||||
GEN_PATH / "Caller.in.h",
|
||||
tmp_path / "Caller.cpp",
|
||||
tmp_path / "Caller.h",
|
||||
)
|
||||
assert (tmp_path / "Caller.cpp").exists()
|
||||
assert (tmp_path / "Caller.h").exists()
|
Reference in New Issue
Block a user