-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
01bf701
commit 73f9d36
Showing
5 changed files
with
164 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright 2021 -- 2023 WhiteMech | ||
# | ||
# ------------------------------ | ||
# | ||
# This file is part of Plan4Past. | ||
# | ||
# Plan4Past is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Lesser General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# Plan4Past is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with Plan4Past. If not, see <https://www.gnu.org/licenses/>. | ||
# | ||
|
||
"""This module contain tests for the compiler module.""" | ||
|
||
from pathlib import Path | ||
from tempfile import TemporaryDirectory | ||
|
||
from pddl.formatter import domain_to_string, problem_to_string | ||
from pddl.parser.domain import DomainParser | ||
from pddl.parser.problem import ProblemParser | ||
from pylogics.parsers import parse_pltl | ||
|
||
from plan4past.compiler import Compiler | ||
from tests.helpers.constants import EXAMPLES_DIR | ||
|
||
|
||
def test_readme_example(val) -> None: | ||
"""Test the example from the README.""" | ||
formula = "on_b_a & O(ontable_c)" | ||
domain_parser = DomainParser() | ||
problem_parser = ProblemParser() | ||
|
||
pddl_example_domain_path = EXAMPLES_DIR / Path("pddl/domain.pddl") | ||
pddl_example_problem_path = EXAMPLES_DIR / Path("pddl/p-0.pddl") | ||
|
||
domain = domain_parser(pddl_example_domain_path.read_text(encoding="utf-8")) | ||
problem = problem_parser(pddl_example_problem_path.read_text(encoding="utf-8")) | ||
goal = parse_pltl(formula) | ||
|
||
compiler = Compiler(domain, problem, goal) | ||
compiler.compile() | ||
compiled_domain, compiled_problem = compiler.result | ||
|
||
with TemporaryDirectory() as tmpdir: | ||
tmpdir_path = Path(tmpdir) | ||
new_domain_path = tmpdir_path / "new-domain.pddl" | ||
new_problem_path = tmpdir_path / "new-problem.pddl" | ||
with open(new_domain_path, "w+", encoding="utf-8") as d: | ||
d.write(domain_to_string(compiled_domain)) | ||
with open(new_problem_path, "w+", encoding="utf-8") as p: | ||
p.write(problem_to_string(compiled_problem)) | ||
|
||
result = val.validate_problem(new_domain_path, new_problem_path) | ||
assert result.is_valid(strict=True) |