From 4e37798145fa03bd90880f4ac315529190472eaf Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 4 Mar 2019 15:15:54 +0100 Subject: generate PTA from YAML model, support several types of test harness --- lib/automata.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'lib/automata.py') diff --git a/lib/automata.py b/lib/automata.py index 922cdaf..96a724e 100755 --- a/lib/automata.py +++ b/lib/automata.py @@ -365,6 +365,38 @@ class PTA: return pta + @classmethod + def from_yaml(cls, yaml_input: dict): + """Return a PTA created from the YAML DFA format (passed as dict).""" + + kwargs = dict() + + if 'parameters' in yaml_input: + kwargs['parameters'] = yaml_input['parameters'] + + if 'initial_param_values' in yaml_input: + kwargs['initial_param_values'] = yaml_input['initial_param_values'] + + if 'states' in yaml_input: + kwargs['state_names'] = yaml_input['states'] + + pta = cls(**kwargs) + + for trans_name in sorted(yaml_input['transition'].keys()): + transition = yaml_input['transition'][trans_name] + arguments = list() + argument_values = list() + is_interrupt = False + if 'arguments' in transition: + for argument in transition['arguments']: + arguments.append(argument['name']) + argument_values.append(argument['values']) + for origin in transition['src']: + pta.add_transition(origin, transition['dst'], trans_name, + arguments = arguments, argument_values = argument_values) + + return pta + def to_json(self) -> dict: """ Return JSON encoding of this PTA. -- cgit v1.2.3