Skip to content

Commit

Permalink
Update precommit configurations and testing suite (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
franklinselva authored Apr 5, 2024
2 parents 69cd330 + 982d68a commit a2b5909
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 51 deletions.
36 changes: 18 additions & 18 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,31 @@ name: Main Workflow
on: [push]

jobs:
basic_checks:
runs-on: ubuntu-latest
name: Basic Checks

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.8"

- name: Precommit checks
uses: pre-commit/action@v3.0.1

build:
runs-on: ubuntu-20.04
name: Build & Test

steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.8"

Expand All @@ -19,22 +36,5 @@ jobs:
python3 -m pip install --upgrade pip
python3 -m pip install -e ".[engines]"
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install black mypy pylint isort pytest
- name: Check formatting with Black
run: python3 -m black --check . --config pyproject.toml

- name: Check types with MyPy
run: python3 -m mypy up_esb/ --config-file pyproject.toml --ignore-missing-imports

- name: Check code quality with Pylint
run: python3 -m pylint up_esb/ --rcfile pyproject.toml --fail-under=8.0

- name: Check imports with isort
run: python3 -m isort --check-only . --settings-path pyproject.toml

- name: Run tests with pytest
run: python3 -m pytest -v tests/
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 23.11.0
rev: 24.3.0
hooks:
- id: black
args: [--config=pyproject.toml]
Expand All @@ -26,14 +26,14 @@ repos:
--disable=import-error,
]
- repo: https://github.com/pycqa/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort
files: "\\.(py)$"
args: [--settings-path=pyproject.toml]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.7.1" # Use the sha / tag you want to point at
rev: "v1.9.0" # Use the sha / tag you want to point at
hooks:
- id: mypy
files: "up_esb/.*\\.py$"
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Setup script for the package."""

#!/usr/bin/env python
import setuptools

Expand Down
2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def get_example_plans() -> Union[List[SequentialPlan], List[TimeTriggeredPlan]]:
plans = {}
for element in example_problems:
if element in available_plans:
plans[element] = example_problems[element].plan
plans[element] = example_problems[element].valid_plans[-1]

return plans

Expand Down
58 changes: 35 additions & 23 deletions tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from unified_planning.plans.partial_order_plan import PartialOrderPlan
from unified_planning.shortcuts import * # pylint: disable=unused-wildcard-import
from unified_planning.test.examples import get_example_problems
from unified_planning.test.examples.realistic import get_example_problems

from up_esb.components.graph import plan_to_dependency_graph

Expand All @@ -29,7 +28,8 @@
class TestPartialOrderPlanGeneration(unittest.TestCase):
def test_partial_order_plan_to_dependency_graph(self):
example_problems = get_example_problems()
problem, plan = example_problems["robot_fluent_of_user_type"]
problem = example_problems["robot_fluent_of_user_type"].problem
plan = example_problems["robot_fluent_of_user_type"].valid_plans[-1]
pop = plan.convert_to(PlanKind.PARTIAL_ORDER_PLAN, problem)
assert isinstance(pop, PartialOrderPlan)
dep_graph = plan_to_dependency_graph(pop)
Expand All @@ -44,16 +44,19 @@ class TestSequentialPlanTranslation(unittest.TestCase):
def test_simple_translation(self):
problems = get_example_problems()

for _, plan in problems.values():
if isinstance(plan, SequentialPlan):
dep_graph = plan_to_dependency_graph(plan)
actions = ["start"] + [str(action) for action in plan.actions] + ["end"]
graph_actions = []
for node in dep_graph.nodes(data=True):
graph_actions.append(node[1]["node_name"])
for test_case in problems.values():
if not test_case.valid_plans:
continue
for plan in test_case.valid_plans:
if isinstance(plan, SequentialPlan):
dep_graph = plan_to_dependency_graph(plan)
actions = ["start"] + [str(action) for action in plan.actions] + ["end"]
graph_actions = []
for node in dep_graph.nodes(data=True):
graph_actions.append(node[1]["node_name"])

# Check if all actions are ordered correctly
self.assertEqual(actions, graph_actions)
# Check if all actions are ordered correctly
self.assertEqual(actions, graph_actions)

def test_special_cases(self):
"""Test translation for special cases."""
Expand Down Expand Up @@ -98,18 +101,27 @@ class TestTimeTriggeredPlanTrasnslation(unittest.TestCase):
def test_simple_translation(self):
problems = get_example_problems()

for _, plan in problems.values():
if isinstance(plan, TimeTriggeredPlan):
dep_graph = plan_to_dependency_graph(plan)
actions = ["start"] + [str(action) for _, action, _ in plan.timed_actions] + ["end"]
graph_actions = []
for node in dep_graph.nodes(data=True):
node_name = node[1]["node_name"]
if node_name not in ["start", "end"]:
node_name = node[1]["node_name"].split(")")[0] + ")"
graph_actions.append(node_name)

self.assertEqual(actions, graph_actions)
for test_case in problems.values():
if not test_case.valid_plans:
continue

for plan in test_case.valid_plans:
if isinstance(plan, TimeTriggeredPlan):
dep_graph = plan_to_dependency_graph(plan)
actions = (
["start"] + [str(action) for _, action, _ in plan.timed_actions] + ["end"]
)
graph_actions = []
for node in dep_graph.nodes(data=True):
node_name = node[1]["node_name"]
if node_name not in ["start", "end"]:
node_name = node[1]["node_name"].split(")")[0]
# FIXME: This is a hack to remove the time from the action name
if "(" in node_name:
node_name += ")"
graph_actions.append(node_name)

self.assertEqual(actions, graph_actions)

def test_special_cases(self):
Location = UserType("Location")
Expand Down
14 changes: 9 additions & 5 deletions up_esb/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,15 @@ def create_fluent(
assert name not in self._fluents, f"Fluent {name} already exists!"
self._fluents[name] = Fluent(
name,
self.get_type(result_api_type)
if result_api_type
else self.get_type(signature["return"])
if signature and "return" in signature.keys()
else BoolType(),
(
self.get_type(result_api_type)
if result_api_type
else (
self.get_type(signature["return"])
if signature and "return" in signature.keys()
else BoolType()
)
),
OrderedDict(
(parameter_name, self.get_type(api_type))
for parameter_name, api_type in (
Expand Down
6 changes: 5 additions & 1 deletion up_esb/components/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,13 @@ def _time_triggered_plan_to_dependency_graph(plan: TimeTriggeredPlan) -> nx.DiGr
duration = 0.0
parameters, preconditions, postconditions = _process_action(action)

# TODO: Check this logic with respect to UP
node_name = f"{str(action)}({duration})"
if duration <= 1.0:
node_name = str(action)
dependency_graph.add_node(
child_id,
node_name=f"{str(action)}({duration})",
node_name=node_name,
action=action.action.name,
parameters=parameters,
preconditions=preconditions,
Expand Down
1 change: 1 addition & 0 deletions up_esb/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Exceptions for the execution module"""

from up_esb.execution import ActionResult
from up_esb.status import ActionNodeStatus, ConditionStatus

Expand Down
1 change: 1 addition & 0 deletions up_esb/execution/executor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Executor for executing tasks."""

from threading import Condition, Lock, Thread
from typing import NamedTuple

Expand Down
1 change: 1 addition & 0 deletions up_esb/status.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Status Enum for up_esb"""

from enum import Enum, auto


Expand Down

0 comments on commit a2b5909

Please sign in to comment.