Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
import matplotlib.pyplot as plt
import numpy as np
import math
import sys
import pathlib

sys.path.append(str(pathlib.Path(__file__).parent.parent.parent))
from utils.angle import angle_mod


Expand Down
3 changes: 3 additions & 0 deletions Mapping/ndt_map/ndt_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import matplotlib.pyplot as plt
import numpy as np
from collections import defaultdict
import sys
import pathlib

sys.path.append(str(pathlib.Path(__file__).parent.parent.parent))
from Mapping.grid_map_lib.grid_map_lib import GridMap
from utils.plot import plot_covariance_ellipse

Expand Down
3 changes: 3 additions & 0 deletions Mapping/normal_vector_estimation/normal_vector_estimation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import numpy as np
from matplotlib import pyplot as plt
import sys
import pathlib

sys.path.append(str(pathlib.Path(__file__).parent.parent.parent))
from utils.plot import plot_3d_vector_arrow, plot_triangle, set_equal_3d_axis

show_animation = True
Expand Down
4 changes: 4 additions & 0 deletions PathPlanning/ClosedLoopRRTStar/unicycle_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

import math
import numpy as np
import sys
import pathlib

sys.path.append(str(pathlib.Path(__file__).parent.parent.parent))
from utils.angle import angle_mod

dt = 0.05 # [s]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import math
import numpy as np
from scipy.interpolate import interp1d
import sys
import pathlib

sys.path.append(str(pathlib.Path(__file__).parent.parent.parent))
from utils.angle import angle_mod

# motion parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
import matplotlib.pyplot as plt
from enum import Enum
from dataclasses import dataclass
import sys
import pathlib

sys.path.append(str(pathlib.Path(__file__).parent.parent.parent))
from PathPlanning.TimeBasedPathPlanning.Node import NodePath, Position

@dataclass
Expand Down
4 changes: 4 additions & 0 deletions PathPlanning/TimeBasedPathPlanning/PriorityBasedPlanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"""

import numpy as np
import sys
import pathlib

sys.path.append(str(pathlib.Path(__file__).parent.parent.parent))
from PathPlanning.TimeBasedPathPlanning.GridWithDynamicObstacles import (
Grid,
Interval,
Expand Down
4 changes: 4 additions & 0 deletions PathPlanning/TimeBasedPathPlanning/SafeInterval.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"""

import numpy as np
import sys
import pathlib

sys.path.append(str(pathlib.Path(__file__).parent.parent.parent))
from PathPlanning.TimeBasedPathPlanning.GridWithDynamicObstacles import (
Grid,
Interval,
Expand Down
4 changes: 4 additions & 0 deletions PathPlanning/TimeBasedPathPlanning/SpaceTimeAStar.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"""

import numpy as np
import sys
import pathlib

sys.path.append(str(pathlib.Path(__file__).parent.parent.parent))
from PathPlanning.TimeBasedPathPlanning.GridWithDynamicObstacles import (
Grid,
ObstacleArrangement,
Expand Down
4 changes: 4 additions & 0 deletions SLAM/EKFSLAM/ekf_slam.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

import matplotlib.pyplot as plt
import numpy as np
import sys
import pathlib

sys.path.append(str(pathlib.Path(__file__).parent.parent.parent))
from utils.angle import angle_mod

# EKF state covariance
Expand Down
4 changes: 4 additions & 0 deletions SLAM/FastSLAM1/fast_slam1.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

import matplotlib.pyplot as plt
import numpy as np
import sys
import pathlib

sys.path.append(str(pathlib.Path(__file__).parent.parent.parent))
from utils.angle import angle_mod

# Fast SLAM covariance
Expand Down
4 changes: 4 additions & 0 deletions SLAM/FastSLAM2/fast_slam2.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

import matplotlib.pyplot as plt
import numpy as np
import sys
import pathlib

sys.path.append(str(pathlib.Path(__file__).parent.parent.parent))
from utils.angle import angle_mod

# Fast SLAM covariance
Expand Down
55 changes: 55 additions & 0 deletions tests/test_run_from_script_directory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""
Check that examples can be started from their own directory, as described in
"How to run sample codes" (``cd <example dir>`` and ``python <script>.py``).

Each script is loaded in a fresh interpreter whose working directory is the
script's directory, without the repository root on ``sys.path``.
``runpy.run_path`` does not set ``__name__`` to ``"__main__"``, so only the
module level code (the imports) runs, not the simulation.
"""
import os
import subprocess
import sys

import pytest

import conftest

SCRIPTS = [
"ArmNavigation/two_joint_arm_to_point_control/"
"two_joint_arm_to_point_control.py",
"Mapping/ndt_map/ndt_map.py",
"Mapping/normal_vector_estimation/normal_vector_estimation.py",
"PathPlanning/ClosedLoopRRTStar/closed_loop_rrt_star_car.py",
"PathPlanning/ClosedLoopRRTStar/pure_pursuit.py",
"PathPlanning/ClosedLoopRRTStar/unicycle_model.py",
"PathPlanning/ModelPredictiveTrajectoryGenerator/trajectory_generator.py",
"PathPlanning/ModelPredictiveTrajectoryGenerator/lookup_table_generator.py",
"PathPlanning/TimeBasedPathPlanning/GridWithDynamicObstacles.py",
"PathPlanning/TimeBasedPathPlanning/PriorityBasedPlanner.py",
"PathPlanning/TimeBasedPathPlanning/SafeInterval.py",
"PathPlanning/TimeBasedPathPlanning/SpaceTimeAStar.py",
"SLAM/EKFSLAM/ekf_slam.py",
"SLAM/FastSLAM1/fast_slam1.py",
"SLAM/FastSLAM2/fast_slam2.py",
]


@pytest.mark.parametrize("script", SCRIPTS)
def test_load_from_script_directory(script):
script_path = os.path.join(conftest.ROOT_DIR, *script.split("/"))
env = {key: value for key, value in os.environ.items()
if key != "PYTHONPATH"}
env["MPLBACKEND"] = "Agg"

result = subprocess.run(
[sys.executable, "-c",
f"import runpy; runpy.run_path({script_path!r})"],
cwd=os.path.dirname(script_path), env=env,
capture_output=True, text=True)

assert result.returncode == 0, result.stderr


if __name__ == '__main__':
conftest.run_this_test(__file__)