Skip to content

Commit

Permalink
added pytest to test on github
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelGerding committed Mar 10, 2024
1 parent e6a1462 commit 56a145d
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 14 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Unit tests

on:
push:

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.12.2]

steps:
- uses: actions/checkout@v4
- name: Set up python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Display Python version
run: python -c "import sys; print(sys.version)"

- name: install Opencv dependencies
run: |
sudo apt-get update
sudo apt-get install -y libgl1-mesa-glx
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Set PYTHONPATH
run: |
echo "::add-path::src"
echo "::set-env name=PYTHONPATH::src"
echo "PYTHONPATH=src" >> $GITHUB_ENV
- name: Run tests
env:
SKIP_BENCHMARK: 1
run: |
python -m pytest tests
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,5 @@ venv.bak/
# Editor
.idea
.vscode

.pre-commit-config.yaml
9 changes: 3 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
inputs==0.5
numpy==1.26.4
opencv-python==4.9.0.80
packaging==23.2
python-can==4.3.1
pywin32==306
typing_extensions==4.10.0
wrapt==1.16.0

typing~=3.7.4.3
matplotlib~=3.8.3
scipy=1.12.0
scipy==1.12.0
pre-commit==3.6.2
pytest==8.1.1
19 changes: 11 additions & 8 deletions tests/line_detection/test_line_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,36 @@
BENCHMARK_ITERATIONS = 500


def get_path(file: str) -> str:
"""Get the absolute path of the current file."""
current_file = os.path.dirname(os.path.abspath(__file__))
return os.path.normpath(os.path.join(current_file, file))


class TestDetectLines(unittest.TestCase):
"""Tests for the line detection methods."""

def test_line_detection_corner(self) -> None:
"""Test the line detection on the corner image."""
image = cv2.imread("./line_detection/images/corner.jpg")
image = cv2.imread(get_path("./images/corner.jpg"))
self.assertIsNotNone(image, "Image not found")
self.__test_line_detection(image, CORNER)

def test_line_detection_straight(self) -> None:
"""Test the line detection on the straight image."""
image = cv2.imread("./line_detection/images/straight.jpg")
image = cv2.imread(get_path("./images/straight.jpg"))
self.assertIsNotNone(image, "Image not found")
self.__test_line_detection(image, STRAIGHT)

def test_line_detection_crossing(self) -> None:
"""Test the line detection on the crossing image."""
image = cv2.imread("./line_detection/images/crossing.jpg")
image = cv2.imread(get_path("./images/crossing.jpg"))
self.assertIsNotNone(image, "Image not found")
self.__test_line_detection(image, CROSSING)

def test_line_detection_stopline(self) -> None:
"""Test the line detection on the stopline image."""
image = cv2.imread("./line_detection/images/stopline.jpg")
image = cv2.imread(get_path("./images/stopline.jpg"))
self.assertIsNotNone(image, "Image not found")
self.__test_line_detection(image, STOP_LINE)

Expand Down Expand Up @@ -62,10 +68,7 @@ def test_benchmark(self) -> None:
to make sure it is a realistic situation all unstitched_images in the test folder are used.
this benchmark will not include stitching the unstitched_images.
"""
benchmark_images = [
cv2.imread(f"./line_detection/unstitched_images/{img}")
for img in os.listdir("./line_detection/unstitched_images")
]
benchmark_images = [cv2.imread(get_path(f"./images/{img}")) for img in os.listdir(get_path("./images"))]

img_count = len(benchmark_images)

Expand Down

0 comments on commit 56a145d

Please sign in to comment.