Skip to content

Commit

Permalink
Green!
Browse files Browse the repository at this point in the history
Signed-off-by: Marco Lampacrescia <[email protected]>
  • Loading branch information
MarcoLm993 committed Jul 4, 2024
1 parent 13f63fb commit 7b2f533
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ def as_dict(self) -> Union[str, int, float, bool, dict]:
"op": self.op,
}
for op_key, op_value in self.operands.items():
assert isinstance(op_value, JaniExpression), f"Expected an expression, found {type(op_value)} for {op_key}"
assert isinstance(op_value, JaniExpression), \
f"Expected an expression, found {type(op_value)} for {op_key}"
assert hasattr(op_value, "identifier"), f"Identifier not set for {op_key}"
op_dict.update({op_key: op_value.as_dict()})
return op_dict
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
],
"constants": [],
"actions": [
{
"name": "BatteryDrainer_action_0"
},
{
"name": "level_on_receive"
},
{
"name": "level_on_send"
},
{
"name": "use_battery-use_battery-683f44d46c02df80d8211f9c92a72d13"
}
],
"automata": [
Expand All @@ -39,18 +39,18 @@
"name": "use_battery"
},
{
"name": "use_battery_on_entry"
"name": "use_battery_1"
}
],
"initial-locations": [
"use_battery_on_entry"
"use_battery"
],
"edges": [
{
"location": "use_battery",
"destinations": [
{
"location": "use_battery_on_entry",
"location": "use_battery_1",
"assignments": [
{
"ref": "battery_percent",
Expand All @@ -64,16 +64,13 @@
]
}
],
"action": "BatteryDrainer_action_0"
"action": "use_battery-use_battery-683f44d46c02df80d8211f9c92a72d13"
},
{
"location": "use_battery_on_entry",
"location": "use_battery_1",
"destinations": [
{
"location": "use_battery",
"probability": {
"exp": 1.0
},
"assignments": [
{
"ref": "level.data",
Expand All @@ -83,7 +80,7 @@
{
"ref": "level.valid",
"value": true,
"index": 1
"index": 0
}
]
}
Expand Down Expand Up @@ -227,9 +224,9 @@
]
},
{
"result": "BatteryDrainer_action_0",
"result": "use_battery-use_battery-683f44d46c02df80d8211f9c92a72d13",
"synchronise": [
"BatteryDrainer_action_0",
"use_battery-use_battery-683f44d46c02df80d8211f9c92a72d13",
null,
null
]
Expand Down
28 changes: 14 additions & 14 deletions jani_generator/test/test_systemtest_scxml_to_jani.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,20 @@ def test_battery_manager(self):
self.assertEqual(variable["type"], "bool")
self.assertEqual(variable["initial-value"], False)

@pytest.mark.skip(reason="WIP")
def test_example_with_sync(self):
"""
Testing the conversion of two SCXML files with a sync.
"""
scxml_battery_drainer = os.path.join(
os.path.dirname(__file__), '_test_data', 'battery_example',
'battery_drainer.scxml')
scxml_battery_manager = os.path.join(
os.path.dirname(__file__), '_test_data', 'battery_example',
'battery_manager.scxml')
TEST_DATA_FOLDER = os.path.join(
os.path.dirname(__file__), '_test_data', 'battery_example')
scxml_battery_drainer_path = os.path.join(
TEST_DATA_FOLDER, 'battery_drainer.scxml')
scxml_battery_manager_path = os.path.join(
TEST_DATA_FOLDER, 'battery_manager.scxml')
with open(scxml_battery_drainer_path, 'r', encoding='utf-8') as f:
scxml_battery_drainer = f.read()
with open(scxml_battery_manager_path, 'r', encoding='utf-8') as f:
scxml_battery_manager = f.read()

jani_model = convert_multiple_scxmls_to_jani([
scxml_battery_drainer,
Expand All @@ -138,6 +141,7 @@ def test_example_with_sync(self):
jani_dict = jani_model.as_dict()
# pprint(jani_dict)

# Check automata
self.assertEqual(len(jani_dict["automata"]), 3)
names = [a["name"] for a in jani_dict["automata"]]
self.assertIn("BatteryDrainer", names)
Expand All @@ -160,10 +164,6 @@ def test_example_with_sync(self):
'synchronise': [
None, 'level_on_receive', 'level_on_receive']},
syncs)
self.assertIn({'result': 'BatteryDrainer_action_0',
'synchronise': [
'BatteryDrainer_action_0', None, None]},
syncs)

# Check global variables for event
variables = jani_dict["variables"]
Expand All @@ -178,10 +178,10 @@ def test_example_with_sync(self):
"transient": False}, variables)

# Check full jani file
TEST_FILE = 'test_output.jani'
TEST_FILE = os.path.join(
TEST_DATA_FOLDER, 'output.jani')
GROUND_TRUTH_FILE = os.path.join(
os.path.dirname(__file__), '_test_data',
'battery_example', 'output.jani')
TEST_DATA_FOLDER, 'output_GROUND_TRUTH.jani')
if os.path.exists(TEST_FILE):
os.remove(TEST_FILE)
with open(TEST_FILE, "w", encoding='utf-8') as output_file:
Expand Down

0 comments on commit 7b2f533

Please sign in to comment.