Skip to content

Commit

Permalink
Merge pull request #2 from pollen-robotics/1-add-pytest-on-commit
Browse files Browse the repository at this point in the history
added pytest on commit
  • Loading branch information
Drenayaz authored Feb 8, 2024
2 parents d9c4405 + efb5a32 commit ef4e6ac
Show file tree
Hide file tree
Showing 7 changed files with 260 additions and 150 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Pytest

on: [pull_request]

jobs:
tests:

runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: 'pip' # caching pip dependencies
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .[dev]
- name: Unit tests
run: |
coverage run -m pytest -m noplaco
coverage xml
coverage json
coverage html
- name: Archive code coverage html report
uses: actions/upload-artifact@v4
with:
name: code-coverage-report
path: htmlcov
- name: Get Cover
uses: orgoro/[email protected]
with:
coverageFile: coverage.xml
token: ${{ secrets.GITHUB_TOKEN }}
4 changes: 3 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,6 @@ plugins = numpy.typing.mypy_plugin
explicit_package_bases = True

[tool:pytest]
testpaths = tests
testpaths = tests
markers =
noplaco: tests that do not require placo
20 changes: 10 additions & 10 deletions src/example/movement_test.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from pathlib import Path
from typing import List

import numpy as np
import numpy.typing as npt
from reachy_placo.ik_reachy_placo import IKReachyQP

from reachy2_symbolic_ik.symbolic_ik import SymbolicIK
from reachy2_symbolic_ik.utils import go_to_position


def make_movement_test(symbolic_ik: SymbolicIK, placo_ik: IKReachyQP, goal_pose: List[List[float]]) -> None:
def make_movement_test(symbolic_ik: SymbolicIK, placo_ik: IKReachyQP, goal_pose: npt.NDArray[np.float64]) -> None:
result = symbolic_ik.is_reachable(goal_pose)
if result[0]:
print(int((result[1][1] - result[1][0]) * 50))
Expand All @@ -24,10 +24,10 @@ def make_movement_test(symbolic_ik: SymbolicIK, placo_ik: IKReachyQP, goal_pose:
def make_line(
symbolic_ik: SymbolicIK,
placo_ik: IKReachyQP,
start_position: List[float],
end_position: List[float],
start_orientation: List[float],
end_orientation: List[float],
start_position: npt.NDArray[np.float64],
end_position: npt.NDArray[np.float64],
start_orientation: npt.NDArray[np.float64],
end_orientation: npt.NDArray[np.float64],
nb_points: int = 100,
) -> None:
x = np.linspace(start_position[0], end_position[0], nb_points)
Expand Down Expand Up @@ -72,10 +72,10 @@ def main_test() -> None:
# goal_pose = [goal_position, goal_orientation]
# make_movement_test(symbolib_ik, placo_ik, goal_pose)

start_position = [0.4, 0.1, -0.4]
end_position = [0.3, -0.2, -0.1]
start_orientation = [0.35, -1.40, 0.17]
end_orientation = [0.0, -0.0, 0.0]
start_position = np.array([0.4, 0.1, -0.4])
end_position = np.array([0.3, -0.2, -0.1])
start_orientation = np.array([0.35, -1.40, 0.17])
end_orientation = np.array([0.0, -0.0, 0.0])
make_line(symbolic_ik, placo_ik, start_position, end_position, start_orientation, end_orientation, nb_points=300)


Expand Down
6 changes: 3 additions & 3 deletions src/example/symbolic_ik_test.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from pathlib import Path
from typing import List

import numpy as np
import numpy.typing as npt
from reachy_placo.ik_reachy_placo import IKReachyQP
from scipy.spatial.transform import Rotation as R

from reachy2_symbolic_ik.symbolic_ik import SymbolicIK
from reachy2_symbolic_ik.utils import go_to_position


def are_joints_correct(placo_ik: IKReachyQP, joints: List[float], goal_pose: List[List[float]]) -> bool:
def are_joints_correct(placo_ik: IKReachyQP, joints: npt.NDArray[np.float64], goal_pose: npt.NDArray[np.float64]) -> bool:
go_to_position(placo_ik, joints, wait=0)
T_torso_tip = placo_ik.robot.get_T_a_b("torso", "r_tip_joint")
position = T_torso_tip[:3, 3]
Expand Down Expand Up @@ -51,7 +51,7 @@ def main_test() -> None:

goal_position = [0.4, 0.1, -0.4]
goal_orientation = [np.radians(20), np.radians(-80), np.radians(10)]
goal_pose = [goal_position, goal_orientation]
goal_pose = np.array([goal_position, goal_orientation])
result = symbolib_ik.is_reachable(goal_pose)
if result[0]:
joints = result[2](result[1][0])
Expand Down
Loading

0 comments on commit ef4e6ac

Please sign in to comment.