Skip to content

Commit 67d7d5c

Browse files
authored
Test code clean up (AtsushiSakai#456)
* Test code clean up * Test code clean up * Test code clean up * Test code clean up * Test code clean up * Test code clean up * Test code clean up * Test code clean up * Test code clean up * Test code clean up * Test code clean up * Test code clean up * Test code clean up * Test code clean up * Test code clean up * Test code clean up * Test code clean up * Test code clean up * Test code clean up * Test code clean up * Test code clean up * Test code clean up * Test code clean up * Test code clean up * Test code clean up
1 parent 8861977 commit 67d7d5c

File tree

88 files changed

+850
-1310
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+850
-1310
lines changed
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import os
2+
import sys
3+
4+
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import sys
2+
import os
3+
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

ArmNavigation/n_joint_arm_to_point_control/n_joint_arm_to_point_control.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"""
77
import numpy as np
88

9-
from NLinkArm import NLinkArm
9+
from ArmNavigation.n_joint_arm_to_point_control.NLinkArm import NLinkArm
1010

1111
# Simulation parameters
1212
Kp = 2
File renamed without changes.

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2016 Atsushi Sakai
3+
Copyright (c) 2016 - 2021 Atsushi Sakai
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Localization/__init__.py

Whitespace-only changes.

Mapping/__init__.py

Whitespace-only changes.

Mapping/grid_map_lib/__init__.py

Whitespace-only changes.

Mapping/rectangle_fitting/__init_.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import os
2+
import sys
3+
4+
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

Mapping/rectangle_fitting/rectangle_fitting.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
from enum import Enum
1919
from scipy.spatial.transform import Rotation as Rot
2020

21-
from simulator import VehicleSimulator, LidarSimulator
21+
from Mapping.rectangle_fitting.simulator \
22+
import VehicleSimulator, LidarSimulator
2223

2324
show_animation = True
2425

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import os
2+
import sys
3+
4+
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
5+
sys.path.append(os.path.dirname(
6+
os.path.abspath(__file__)) + "/../ReedsSheppPath/")
7+
sys.path.append(os.path.dirname(
8+
os.path.abspath(__file__)) + "/../RRTStarReedsShepp/")

PathPlanning/ClosedLoopRRTStar/closed_loop_rrt_star_car.py

+7-17
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,13 @@
66
77
"""
88

9-
import os
10-
import sys
11-
129
import matplotlib.pyplot as plt
1310
import numpy as np
11+
import reeds_shepp_path_planning
12+
from rrt_star_reeds_shepp import RRTStarReedsShepp
1413

1514
import pure_pursuit
16-
17-
sys.path.append(os.path.dirname(
18-
os.path.abspath(__file__)) + "/../ReedsSheppPath/")
19-
sys.path.append(os.path.dirname(
20-
os.path.abspath(__file__)) + "/../RRTStarReedsShepp/")
21-
22-
try:
23-
import reeds_shepp_path_planning
24-
import unicycle_model
25-
from rrt_star_reeds_shepp import RRTStarReedsShepp
26-
except ImportError:
27-
raise
15+
import unicycle_model
2816

2917
show_animation = True
3018

@@ -77,7 +65,8 @@ def search_best_feasible_path(self, path_indexs):
7765
for ind in path_indexs:
7866
path = self.generate_final_course(ind)
7967

80-
flag, x, y, yaw, v, t, a, d = self.check_tracking_path_is_feasible(path)
68+
flag, x, y, yaw, v, t, a, d = self.check_tracking_path_is_feasible(
69+
path)
8170

8271
if flag and best_time >= t[-1]:
8372
print("feasible path is found")
@@ -186,7 +175,8 @@ def main(gx=6.0, gy=7.0, gyaw=np.deg2rad(90.0), max_iter=100):
186175
obstacle_list,
187176
[-2.0, 20.0],
188177
max_iter=max_iter)
189-
flag, x, y, yaw, v, t, a, d = closed_loop_rrt_star.planning(animation=show_animation)
178+
flag, x, y, yaw, v, t, a, d = closed_loop_rrt_star.planning(
179+
animation=show_animation)
190180

191181
if not flag:
192182
print("cannot find feasible path")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import os
2+
import sys
3+
4+
GRID_MAP_LIB = os.path.dirname(os.path.abspath(__file__)) + \
5+
"/../../Mapping/"
6+
7+
sys.path.append(GRID_MAP_LIB)

PathPlanning/GridBasedSweepCPP/grid_based_sweep_coverage_path_planner.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,12 @@
55
"""
66

77
import math
8-
import os
9-
import sys
108
from enum import IntEnum
119

1210
import matplotlib.pyplot as plt
1311
import numpy as np
1412
from scipy.spatial.transform import Rotation as Rot
15-
16-
sys.path.append(os.path.relpath("../../Mapping/grid_map_lib/"))
17-
try:
18-
from grid_map_lib import GridMap
19-
except ImportError:
20-
raise
13+
from Mapping.grid_map_lib.grid_map_lib import GridMap
2114

2215
do_animation = True
2316

PathPlanning/HybridAStar/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import os
2+
import sys
3+
4+
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import os
2+
import sys
3+
4+
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

PathTracking/__init__.py

Whitespace-only changes.

__init__.py

Whitespace-only changes.

runtests.sh

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env bash
22
echo "Run test suites! "
3-
# tests: include unittest based tests
3+
4+
# === pytest based test runner ===
45
# -Werror: warning as error
56
# --durations=0: show ranking of test durations
6-
pytest tests -Werror --durations=0
7+
# -l (--showlocals); show local variables when test failed
8+
pytest tests -l -Werror --durations=0

tests/conftest.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""Path hack to make tests work."""
2+
import sys
3+
import os
4+
import pytest
5+
6+
TEST_DIR = os.path.dirname(os.path.abspath(__file__))
7+
sys.path.append(TEST_DIR) # to import this file from test code.
8+
ROOT_DIR = os.path.dirname(TEST_DIR)
9+
sys.path.append(ROOT_DIR)
10+
11+
12+
def run_this_test(file):
13+
pytest.main([os.path.abspath(file)])

tests/test_LQR_planner.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
import sys
2-
from unittest import TestCase
3-
4-
sys.path.append("./PathPlanning/LQRPlanner")
5-
1+
import conftest # Add root path to sys.path
62
from PathPlanning.LQRPlanner import LQRplanner as m
73

8-
print(__file__)
94

5+
def test_1():
6+
m.SHOW_ANIMATION = False
7+
m.main()
108

11-
class Test(TestCase):
129

13-
def test1(self):
14-
m.SHOW_ANIMATION = False
15-
m.main()
10+
if __name__ == '__main__':
11+
conftest.run_this_test(__file__)

tests/test_a_star.py

+7-16
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
1-
from unittest import TestCase
2-
import sys
3-
import os
4-
sys.path.append(os.path.dirname(__file__) + "/../")
5-
try:
6-
from PathPlanning.AStar import a_star as m
7-
except:
8-
raise
1+
import conftest
2+
from PathPlanning.AStar import a_star as m
93

104

11-
class Test(TestCase):
5+
def test_1():
6+
m.show_animation = False
7+
m.main()
128

13-
def test1(self):
14-
m.show_animation = False
15-
m.main()
169

17-
18-
if __name__ == '__main__': # pragma: no cover
19-
test = Test()
20-
test.test1()
10+
if __name__ == '__main__':
11+
conftest.run_this_test(__file__)
+9-20
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
1-
from unittest import TestCase
2-
import os
3-
import sys
1+
import conftest
2+
from PathPlanning.AStar import a_star_searching_from_two_side as m
43

5-
sys.path.append(os.path.dirname(__file__) + '/../')
64

7-
try:
8-
from PathPlanning.AStar import a_star_searching_from_two_side as m
9-
except ImportError:
10-
raise
5+
def test1():
6+
m.show_animation = False
7+
m.main(800)
118

129

13-
class Test(TestCase):
14-
15-
def test1(self):
16-
m.show_animation = False
17-
m.main(800)
18-
19-
def test2(self):
20-
m.show_animation = False
21-
m.main(5000) # increase obstacle number, block path
10+
def test2():
11+
m.show_animation = False
12+
m.main(5000) # increase obstacle number, block path
2213

2314

2415
if __name__ == '__main__':
25-
test = Test()
26-
test.test1()
27-
test.test2()
16+
conftest.run_this_test(__file__)

tests/test_a_star_variants.py

+44-50
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,44 @@
1-
import PathPlanning.AStar.a_star_variants as astar
2-
from unittest import TestCase
3-
import sys
4-
import os
5-
sys.path.append(os.path.dirname(__file__) + "/../")
6-
7-
8-
class Test(TestCase):
9-
10-
def test(self):
11-
# A* with beam search
12-
astar.show_animation = False
13-
14-
astar.use_beam_search = True
15-
astar.main()
16-
self.reset_all()
17-
18-
# A* with iterative deepening
19-
astar.use_iterative_deepening = True
20-
astar.main()
21-
self.reset_all()
22-
23-
# A* with dynamic weighting
24-
astar.use_dynamic_weighting = True
25-
astar.main()
26-
self.reset_all()
27-
28-
# theta*
29-
astar.use_theta_star = True
30-
astar.main()
31-
self.reset_all()
32-
33-
# A* with jump point
34-
astar.use_jump_point = True
35-
astar.main()
36-
self.reset_all()
37-
38-
@staticmethod
39-
def reset_all():
40-
astar.show_animation = False
41-
astar.use_beam_search = False
42-
astar.use_iterative_deepening = False
43-
astar.use_dynamic_weighting = False
44-
astar.use_theta_star = False
45-
astar.use_jump_point = False
46-
47-
48-
if __name__ == '__main__': # pragma: no cover
49-
test = Test()
50-
test.test()
1+
import PathPlanning.AStar.a_star_variants as a_star
2+
import conftest
3+
4+
5+
def test_1():
6+
# A* with beam search
7+
a_star.show_animation = False
8+
9+
a_star.use_beam_search = True
10+
a_star.main()
11+
reset_all()
12+
13+
# A* with iterative deepening
14+
a_star.use_iterative_deepening = True
15+
a_star.main()
16+
reset_all()
17+
18+
# A* with dynamic weighting
19+
a_star.use_dynamic_weighting = True
20+
a_star.main()
21+
reset_all()
22+
23+
# theta*
24+
a_star.use_theta_star = True
25+
a_star.main()
26+
reset_all()
27+
28+
# A* with jump point
29+
a_star.use_jump_point = True
30+
a_star.main()
31+
reset_all()
32+
33+
34+
def reset_all():
35+
a_star.show_animation = False
36+
a_star.use_beam_search = False
37+
a_star.use_iterative_deepening = False
38+
a_star.use_dynamic_weighting = False
39+
a_star.use_theta_star = False
40+
a_star.use_jump_point = False
41+
42+
43+
if __name__ == '__main__':
44+
conftest.run_this_test(__file__)

tests/test_batch_informed_rrt_star.py

+8-19
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
1-
from unittest import TestCase
2-
import sys
3-
import os
41
import random
5-
sys.path.append(os.path.dirname(__file__) + "/../")
6-
try:
7-
from PathPlanning.BatchInformedRRTStar import batch_informed_rrtstar as m
8-
except ImportError:
9-
raise
102

11-
print(__file__)
3+
import conftest
4+
from PathPlanning.BatchInformedRRTStar import batch_informed_rrtstar as m
125

13-
random.seed(12345)
146

7+
def test_1():
8+
m.show_animation = False
9+
random.seed(12345)
10+
m.main(maxIter=10)
1511

16-
class Test(TestCase):
1712

18-
def test1(self):
19-
m.show_animation = False
20-
m.main(maxIter=10)
21-
22-
23-
if __name__ == '__main__': # pragma: no cover
24-
test = Test()
25-
test.test1()
13+
if __name__ == '__main__':
14+
conftest.run_this_test(__file__)

0 commit comments

Comments
 (0)