Skip to content

Commit ef4e6ac

Browse files
authored
Merge pull request #2 from pollen-robotics/1-add-pytest-on-commit
added pytest on commit
2 parents d9c4405 + efb5a32 commit ef4e6ac

File tree

7 files changed

+260
-150
lines changed

7 files changed

+260
-150
lines changed

.github/workflows/pytest.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Pytest
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
tests:
7+
8+
runs-on: ubuntu-22.04
9+
10+
steps:
11+
- uses: actions/checkout@v3
12+
- name: Set up Python 3.10
13+
uses: actions/setup-python@v4
14+
with:
15+
python-version: "3.10"
16+
cache: 'pip' # caching pip dependencies
17+
- name: Install dependencies
18+
run: |
19+
python -m pip install --upgrade pip
20+
pip install .[dev]
21+
- name: Unit tests
22+
run: |
23+
coverage run -m pytest -m noplaco
24+
coverage xml
25+
coverage json
26+
coverage html
27+
- name: Archive code coverage html report
28+
uses: actions/upload-artifact@v4
29+
with:
30+
name: code-coverage-report
31+
path: htmlcov
32+
- name: Get Cover
33+
uses: orgoro/[email protected]
34+
with:
35+
coverageFile: coverage.xml
36+
token: ${{ secrets.GITHUB_TOKEN }}

setup.cfg

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,6 @@ plugins = numpy.typing.mypy_plugin
5252
explicit_package_bases = True
5353

5454
[tool:pytest]
55-
testpaths = tests
55+
testpaths = tests
56+
markers =
57+
noplaco: tests that do not require placo

src/example/movement_test.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
from pathlib import Path
2-
from typing import List
32

43
import numpy as np
4+
import numpy.typing as npt
55
from reachy_placo.ik_reachy_placo import IKReachyQP
66

77
from reachy2_symbolic_ik.symbolic_ik import SymbolicIK
88
from reachy2_symbolic_ik.utils import go_to_position
99

1010

11-
def make_movement_test(symbolic_ik: SymbolicIK, placo_ik: IKReachyQP, goal_pose: List[List[float]]) -> None:
11+
def make_movement_test(symbolic_ik: SymbolicIK, placo_ik: IKReachyQP, goal_pose: npt.NDArray[np.float64]) -> None:
1212
result = symbolic_ik.is_reachable(goal_pose)
1313
if result[0]:
1414
print(int((result[1][1] - result[1][0]) * 50))
@@ -24,10 +24,10 @@ def make_movement_test(symbolic_ik: SymbolicIK, placo_ik: IKReachyQP, goal_pose:
2424
def make_line(
2525
symbolic_ik: SymbolicIK,
2626
placo_ik: IKReachyQP,
27-
start_position: List[float],
28-
end_position: List[float],
29-
start_orientation: List[float],
30-
end_orientation: List[float],
27+
start_position: npt.NDArray[np.float64],
28+
end_position: npt.NDArray[np.float64],
29+
start_orientation: npt.NDArray[np.float64],
30+
end_orientation: npt.NDArray[np.float64],
3131
nb_points: int = 100,
3232
) -> None:
3333
x = np.linspace(start_position[0], end_position[0], nb_points)
@@ -72,10 +72,10 @@ def main_test() -> None:
7272
# goal_pose = [goal_position, goal_orientation]
7373
# make_movement_test(symbolib_ik, placo_ik, goal_pose)
7474

75-
start_position = [0.4, 0.1, -0.4]
76-
end_position = [0.3, -0.2, -0.1]
77-
start_orientation = [0.35, -1.40, 0.17]
78-
end_orientation = [0.0, -0.0, 0.0]
75+
start_position = np.array([0.4, 0.1, -0.4])
76+
end_position = np.array([0.3, -0.2, -0.1])
77+
start_orientation = np.array([0.35, -1.40, 0.17])
78+
end_orientation = np.array([0.0, -0.0, 0.0])
7979
make_line(symbolic_ik, placo_ik, start_position, end_position, start_orientation, end_orientation, nb_points=300)
8080

8181

src/example/symbolic_ik_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
from pathlib import Path
2-
from typing import List
32

43
import numpy as np
4+
import numpy.typing as npt
55
from reachy_placo.ik_reachy_placo import IKReachyQP
66
from scipy.spatial.transform import Rotation as R
77

88
from reachy2_symbolic_ik.symbolic_ik import SymbolicIK
99
from reachy2_symbolic_ik.utils import go_to_position
1010

1111

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

5252
goal_position = [0.4, 0.1, -0.4]
5353
goal_orientation = [np.radians(20), np.radians(-80), np.radians(10)]
54-
goal_pose = [goal_position, goal_orientation]
54+
goal_pose = np.array([goal_position, goal_orientation])
5555
result = symbolib_ik.is_reachable(goal_pose)
5656
if result[0]:
5757
joints = result[2](result[1][0])

0 commit comments

Comments
 (0)