Skip to content

Commit

Permalink
New tests and some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Enrico Scala committed Oct 16, 2024
1 parent aabe009 commit cfba2c0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 52 deletions.
10 changes: 10 additions & 0 deletions run_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash


python3.11 -m pytest \
--cov=unified_planning --cov-report term-missing\
--doctest-modules \
--ignore=unified_planning/grpc \
--ignore=unified_planning/interop \
--ignore=unified_planning/engines \
unified_planning
74 changes: 22 additions & 52 deletions unified_planning/io/pddl_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,25 @@ def _add_timed_effects(
raise SyntaxError(
f"Not able to handle: {eff.value}, from line: {start_line}, col {start_col} to line: {end_line}, col {end_col}"
)

def _get_params(self, a: dict, types_map: TypesMap, domain_str: str):
a_params = OrderedDict()
for g in a.get("params", []):
try:
t = types_map[g.value[1] if len(g.value) > 1 else Object]
except KeyError:
g_start_line, g_start_col = lineno(g.locn_start, domain_str), col(
g.locn_start, domain_str
)
g_end_line, g_end_col = lineno(g.locn_end, domain_str), col(
g.locn_end, domain_str
)
raise SyntaxError(
f"Undefined parameter's type: {g.value[1]}."
+ f"\nError from line: {g_start_line}, col: {g_start_col} to line: {g_end_line}, col: {g_end_col}."
)
for p in g.value[0]:
a_params[p] = t
return a_params
def _parse_subtask(
self,
e,
Expand Down Expand Up @@ -1251,23 +1269,7 @@ def declare_type(
problem.add_task(task)
for a in domain_res.get("processes", []):
n = a["name"]
a_params = OrderedDict()
for g in a.get("params", []):
try:
t = types_map[g.value[1] if len(g.value) > 1 else Object]
except KeyError:
g_start_line, g_start_col = lineno(g.locn_start, domain_str), col(
g.locn_start, domain_str
)
g_end_line, g_end_col = lineno(g.locn_end, domain_str), col(
g.locn_end, domain_str
)
raise SyntaxError(
f"Undefined parameter's type: {g.value[1]}."
+ f"\nError from line: {g_start_line}, col: {g_start_col} to line: {g_end_line}, col: {g_end_col}."
)
for p in g.value[0]:
a_params[p] = t
a_params = self._get_params(a, types_map, domain_str)
proc = up.model.Process(n, a_params, self._env)
if "pre" in a:
proc.add_precondition(
Expand All @@ -1292,23 +1294,7 @@ def declare_type(

for a in domain_res.get("events", []):
n = a["name"]
a_params = OrderedDict()
for g in a.get("params", []):
try:
t = types_map[g.value[1] if len(g.value) > 1 else Object]
except KeyError:
g_start_line, g_start_col = lineno(g.locn_start, domain_str), col(
g.locn_start, domain_str
)
g_end_line, g_end_col = lineno(g.locn_end, domain_str), col(
g.locn_end, domain_str
)
raise SyntaxError(
f"Undefined parameter's type: {g.value[1]}."
+ f"\nError from line: {g_start_line}, col: {g_start_col} to line: {g_end_line}, col: {g_end_col}."
)
for p in g.value[0]:
a_params[p] = t
a_params = self._get_params(a, types_map, domain_str)
evt = up.model.Event(n, a_params, self._env)
if "pre" in a:
evt.add_precondition(
Expand All @@ -1333,23 +1319,7 @@ def declare_type(

for a in domain_res.get("actions", []):
n = a["name"]
a_params = OrderedDict()
for g in a.get("params", []):
try:
t = types_map[g.value[1] if len(g.value) > 1 else Object]
except KeyError:
g_start_line, g_start_col = lineno(g.locn_start, domain_str), col(
g.locn_start, domain_str
)
g_end_line, g_end_col = lineno(g.locn_end, domain_str), col(
g.locn_end, domain_str
)
raise SyntaxError(
f"Undefined parameter's type: {g.value[1]}."
+ f"\nError from line: {g_start_line}, col: {g_start_col} to line: {g_end_line}, col: {g_end_col}."
)
for p in g.value[0]:
a_params[p] = t
a_params = self._get_params(a, types_map, domain_str)
if "duration" in a:
dur_act = up.model.DurativeAction(n, a_params, self._env)
dur = CustomParseResults(a["duration"][0])
Expand Down
5 changes: 5 additions & 0 deletions unified_planning/test/test_pddl_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,11 @@ def test_non_linear_car(self):
self.assertEqual(
len(list([ele for ele in problem.actions if isinstance(ele, Event)])), 1
)
for ele in problem.actions:
if isinstance(ele, Process):
for e in ele.effects:
self.assertEqual(e.kind,EffectKind.DERIVATIVE)


def test_matchcellar_reader(self):
reader = PDDLReader()
Expand Down

0 comments on commit cfba2c0

Please sign in to comment.