Skip to content

Commit 82d97ce

Browse files
authored
add mypy unit test (AtsushiSakai#621)
* add mypy unit test * add mypy unit test * add mypy unit test
1 parent a13ef29 commit 82d97ce

File tree

5 files changed

+58
-37
lines changed

5 files changed

+58
-37
lines changed

.github/workflows/Linux_CI.yml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,6 @@ jobs:
2828
run: |
2929
python -m pip install --upgrade pip
3030
python -m pip install -r requirements.txt
31-
- name: install coverage
32-
run: pip install coverage
33-
- name: install mypy
34-
run: pip install mypy
35-
- name: mypy check
36-
run: |
37-
mypy -p AerialNavigation
38-
mypy -p ArmNavigation
39-
mypy -p Bipedal
40-
mypy -p Control
41-
mypy -p Localization
42-
mypy -p Mapping
43-
mypy -p PathPlanning
44-
mypy -p PathTracking
45-
mypy -p SLAM
4631
- name: do all unit tests
4732
run: bash runtests.sh
4833

.github/workflows/MacOS_CI.yml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,5 @@ jobs:
3535
python -m pip install --upgrade pip
3636
pip install numpy # cvxpy install workaround
3737
pip install -r requirements.txt
38-
- name: install coverage
39-
run: pip install coverage
40-
- name: install mypy
41-
run: pip install mypy
42-
- name: mypy check
43-
run: |
44-
mypy -p AerialNavigation
45-
mypy -p ArmNavigation
46-
mypy -p Bipedal
47-
mypy -p Control
48-
mypy -p Localization
49-
mypy -p Mapping
50-
mypy -p PathPlanning
51-
mypy -p PathTracking
52-
mypy -p SLAM
5338
- name: do all unit tests
5439
run: bash runtests.sh

PathPlanning/DStarLite/d_star_lite.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ def __init__(self, ox: list, oy: list):
6464
for x, y in zip(ox, oy)]
6565
self.start = Node(0, 0)
6666
self.goal = Node(0, 0)
67-
self.U = list()
67+
self.U = list() # type: ignore
6868
self.km = 0.0
6969
self.kold = 0.0
70-
self.rhs = list()
71-
self.g = list()
72-
self.detected_obstacles = list()
70+
self.rhs = list() # type: ignore
71+
self.g = list() # type: ignore
72+
self.detected_obstacles = list() # type: ignore
7373
if show_animation:
74-
self.detected_obstacles_for_plotting_x = list()
75-
self.detected_obstacles_for_plotting_y = list()
74+
self.detected_obstacles_for_plotting_x = list() # type: ignore
75+
self.detected_obstacles_for_plotting_y = list() # type: ignore
7676

7777
def create_grid(self, val: float):
7878
grid = list()
@@ -248,7 +248,7 @@ def compare_paths(self, path1: list, path2: list):
248248
return False
249249
return True
250250

251-
def display_path(self, path: list, colour: str, alpha: int = 1):
251+
def display_path(self, path: list, colour: str, alpha: float = 1.0):
252252
px = [(node.x + self.x_min_world) for node in path]
253253
py = [(node.y + self.y_min_world) for node in path]
254254
drawing = plt.plot(px, py, colour, alpha=alpha)

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ matplotlib == 3.5.1
55
cvxpy == 1.1.18
66
pytest == 6.2.5 # For unit test
77
pytest-xdist == 2.5.0 # For unit test
8+
mypy == 0.931 # For unit test
89
flake8 == 4.0.1 # For unit test
910
sphinx == 4.3.2 # For sphinx documentation
1011
sphinx_rtd_theme == 1.0.0

tests/test_mypy_type_check.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import os
2+
import subprocess
3+
4+
import conftest
5+
6+
SUBPACKAGE_LIST = [
7+
"AerialNavigation",
8+
"ArmNavigation",
9+
"Bipedal",
10+
"Control",
11+
"Localization",
12+
"Mapping",
13+
"PathPlanning",
14+
"PathTracking",
15+
"SLAM",
16+
]
17+
18+
19+
def run_mypy(dir_name, project_path, config_path):
20+
res = subprocess.run(
21+
['mypy',
22+
'--config-file',
23+
config_path,
24+
'-p',
25+
dir_name],
26+
cwd=project_path,
27+
stdout=subprocess.PIPE,
28+
encoding='utf-8')
29+
return res.returncode, res.stdout
30+
31+
32+
def test():
33+
project_dir_path = os.path.dirname(
34+
os.path.dirname(os.path.abspath(__file__)))
35+
print(f"{project_dir_path=}")
36+
37+
config_path = os.path.join(project_dir_path, "mypy.ini")
38+
print(f"{config_path=}")
39+
40+
for sub_package_name in SUBPACKAGE_LIST:
41+
rc, errors = run_mypy(sub_package_name, project_dir_path, config_path)
42+
if errors:
43+
print(errors)
44+
else:
45+
print("No lint errors found.")
46+
assert rc == 0
47+
48+
49+
if __name__ == '__main__':
50+
conftest.run_this_test(__file__)

0 commit comments

Comments
 (0)