Skip to content

Commit

Permalink
add mypy unit test (AtsushiSakai#621)
Browse files Browse the repository at this point in the history
* add mypy unit test

* add mypy unit test

* add mypy unit test
  • Loading branch information
AtsushiSakai authored Jan 8, 2022
1 parent a13ef29 commit 82d97ce
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 37 deletions.
15 changes: 0 additions & 15 deletions .github/workflows/Linux_CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,6 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
- name: install coverage
run: pip install coverage
- name: install mypy
run: pip install mypy
- name: mypy check
run: |
mypy -p AerialNavigation
mypy -p ArmNavigation
mypy -p Bipedal
mypy -p Control
mypy -p Localization
mypy -p Mapping
mypy -p PathPlanning
mypy -p PathTracking
mypy -p SLAM
- name: do all unit tests
run: bash runtests.sh

Expand Down
15 changes: 0 additions & 15 deletions .github/workflows/MacOS_CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,5 @@ jobs:
python -m pip install --upgrade pip
pip install numpy # cvxpy install workaround
pip install -r requirements.txt
- name: install coverage
run: pip install coverage
- name: install mypy
run: pip install mypy
- name: mypy check
run: |
mypy -p AerialNavigation
mypy -p ArmNavigation
mypy -p Bipedal
mypy -p Control
mypy -p Localization
mypy -p Mapping
mypy -p PathPlanning
mypy -p PathTracking
mypy -p SLAM
- name: do all unit tests
run: bash runtests.sh
14 changes: 7 additions & 7 deletions PathPlanning/DStarLite/d_star_lite.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ def __init__(self, ox: list, oy: list):
for x, y in zip(ox, oy)]
self.start = Node(0, 0)
self.goal = Node(0, 0)
self.U = list()
self.U = list() # type: ignore
self.km = 0.0
self.kold = 0.0
self.rhs = list()
self.g = list()
self.detected_obstacles = list()
self.rhs = list() # type: ignore
self.g = list() # type: ignore
self.detected_obstacles = list() # type: ignore
if show_animation:
self.detected_obstacles_for_plotting_x = list()
self.detected_obstacles_for_plotting_y = list()
self.detected_obstacles_for_plotting_x = list() # type: ignore
self.detected_obstacles_for_plotting_y = list() # type: ignore

def create_grid(self, val: float):
grid = list()
Expand Down Expand Up @@ -248,7 +248,7 @@ def compare_paths(self, path1: list, path2: list):
return False
return True

def display_path(self, path: list, colour: str, alpha: int = 1):
def display_path(self, path: list, colour: str, alpha: float = 1.0):
px = [(node.x + self.x_min_world) for node in path]
py = [(node.y + self.y_min_world) for node in path]
drawing = plt.plot(px, py, colour, alpha=alpha)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ matplotlib == 3.5.1
cvxpy == 1.1.18
pytest == 6.2.5 # For unit test
pytest-xdist == 2.5.0 # For unit test
mypy == 0.931 # For unit test
flake8 == 4.0.1 # For unit test
sphinx == 4.3.2 # For sphinx documentation
sphinx_rtd_theme == 1.0.0
Expand Down
50 changes: 50 additions & 0 deletions tests/test_mypy_type_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import os
import subprocess

import conftest

SUBPACKAGE_LIST = [
"AerialNavigation",
"ArmNavigation",
"Bipedal",
"Control",
"Localization",
"Mapping",
"PathPlanning",
"PathTracking",
"SLAM",
]


def run_mypy(dir_name, project_path, config_path):
res = subprocess.run(
['mypy',
'--config-file',
config_path,
'-p',
dir_name],
cwd=project_path,
stdout=subprocess.PIPE,
encoding='utf-8')
return res.returncode, res.stdout


def test():
project_dir_path = os.path.dirname(
os.path.dirname(os.path.abspath(__file__)))
print(f"{project_dir_path=}")

config_path = os.path.join(project_dir_path, "mypy.ini")
print(f"{config_path=}")

for sub_package_name in SUBPACKAGE_LIST:
rc, errors = run_mypy(sub_package_name, project_dir_path, config_path)
if errors:
print(errors)
else:
print("No lint errors found.")
assert rc == 0


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

0 comments on commit 82d97ce

Please sign in to comment.