def test_configparameter_norange_nounits(): cmd = ConfigurationParameter(name=NAME, ptype=TYPE, category=CATEGORY, description=DESCRIPTION) assert repr(cmd) == f"{TYPE} {NAME}: {DESCRIPTION}" assert str( cmd ) == f"ConfigurationParameter[name={NAME}, type={TYPE}, desc='{DESCRIPTION}', category={CATEGORY}, units=UNDEFINED, range=[UNDEFINED, UNDEFINED]]" assert cmd.to_csv( "Toto" ) == f"Toto,{NAME},{TYPE},{CATEGORY},UNDEFINED,UNDEFINED,UNDEFINED,{DESCRIPTION}\n"
def test_configparameter_nodescription_deprecated(): cmd = ConfigurationParameter(name=NAME, ptype=TYPE, category=CATEGORY, units=UNITS, description=None, is_deprecated=True) assert repr(cmd) == f"{TYPE} {NAME}" assert str( cmd ) == f"ConfigurationParameter[name={NAME}, type={TYPE}, category={CATEGORY}, units={UNITS}, range=[UNDEFINED, UNDEFINED]](DEPRECATED)" assert cmd.to_csv( "Toto" ) == f"Toto,{NAME},{TYPE},{CATEGORY},{UNITS},UNDEFINED,UNDEFINED,\n"
def extract_param_info(lines: List[str], idx: int) -> ConfigurationParameter: """Create a ConfigurationParameter instance from text""" # Verify if the parameter is deprecated deprecated = "@Deprecated" in lines[idx - 1] param_decorator = lines[idx] if "(" in param_decorator: while not param_decorator.endswith(")"): idx += 1 param_decorator += lines[idx] param_dict = extract_parameter_arguments(param_decorator) else: param_dict = {} lowval, highval = extract_range_values(param_dict.get("range", "..")) definition = lines[idx + 1] param_name, ptype = extract_parameter_name_and_type(definition) return ConfigurationParameter( name=param_name, category=param_dict.get("category", "UNKNOWN"), ptype=ptype, units=param_dict.get("units", None), low=lowval, high=highval, description=param_dict.get("description", None), is_deprecated=deprecated, )
def test_configparameter_nodescription(): cmd = ConfigurationParameter(name=NAME, ptype=TYPE, category=CATEGORY, low=RANGE_LOW, high=RANGE_HIGH, units=UNITS, description=None) assert repr(cmd) == f"{TYPE} {NAME}" assert str( cmd ) == f"ConfigurationParameter[name={NAME}, type={TYPE}, category={CATEGORY}, units={UNITS}, range=[{RANGE_LOW}, {RANGE_HIGH}]]" assert cmd.to_csv( "Toto" ) == f"Toto,{NAME},{TYPE},{CATEGORY},{UNITS},{RANGE_LOW},{RANGE_HIGH},\n"
def test_extract_param_info_no_args(): input_ = ["", CONFIG_PARAM_NO_ARGS, "public void myParam"] param_position = 1 result = extract_param_info(input_, param_position) expected = ConfigurationParameter( name="myParam", ptype="void", category="UNKNOWN" ) assert result == expected
def test_extract_param_info_real(): input_ = SPACED_TEXT_CLEANED param_position = 2 result = extract_param_info(input_, param_position) expected = ConfigurationParameter( name="deltaPosition", ptype="int", description="Position margin to terminate movement.", category="UNKNOWN" ) assert result == expected
def test_extract_param_info_no_units_basic(): input_ = [CONFIG_PARAM_WITH_ARGS_NO_UNITS, "private int myParam"] param_position = 0 result = extract_param_info(input_, param_position) expected = ConfigurationParameter( name="myParam", ptype="int", category="carousel", low=0, high=500000, description="In milliseconds; if rotation lasts more than rotationTimeout rotation is halted and the subsystem goes in error state." ) assert result == expected
def test_parse_raw_text(): expected_commands = [ Command( name="setFilter", cmdtype="ACTION", level="NORMAL", description="Set filter.", args=[Argument(name="filterId", ptype="int")] ) ] expected_parameters = [ ConfigurationParameter(name="deltaPosition", ptype="int", description="Position margin to terminate movement.", category="UNKNOWN") ] res_commands, res_parameters = parse_raw_text(SPACED_TEXT_RAW) for exp_cmd, res_cmd in zip(expected_commands, res_commands): assert exp_cmd == res_cmd for exp_param, res_param in zip(expected_parameters, res_parameters): assert exp_param == res_param