From b203778956a96df86917cca9e2ca1e22f906285b Mon Sep 17 00:00:00 2001 From: Jan Domanski Date: Sat, 27 Jul 2024 18:08:55 +0100 Subject: [PATCH] finish the changes, make sure tests are working --- README.md | 14 +++++++++ setup.py | 2 +- tests/__init__.py | 0 tests/integration/__init__.py | 0 main.py => tests/integration/test_qreader.py | 30 ++++++++++--------- tests/preformance/__init__.py | 0 .../preformance/test_performance.py | 14 ++++++--- 7 files changed, 41 insertions(+), 19 deletions(-) create mode 100644 tests/__init__.py create mode 100644 tests/integration/__init__.py rename main.py => tests/integration/test_qreader.py (74%) create mode 100644 tests/preformance/__init__.py rename performance_test.py => tests/preformance/test_performance.py (82%) diff --git a/README.md b/README.md index 6cb3c4c..5a3c2c8 100644 --- a/README.md +++ b/README.md @@ -166,6 +166,20 @@ Image: test_draw_64x64.jpeg -> QReader: ('https://github.com/Eric-Canas/QReader' Note that **QReader** internally uses pyzbar as **decoder**. The improved **detection-decoding rate** that **QReader** achieves comes from the combination of different image pre-processing techniques and the YOLOv8 based **QR** detector that is able to detect **QR** codes in harder conditions than classical _Computer Vision_ methods. +## Running tests + +The tests can be launched via pytest. Make sure you install the test version of the package + +```bash +python -m pip install --editable ".[test]" +``` + +Then, you can run the tests with + +```bash +python -m pytest tests/ +``` + ## Benchmark ### Rotation Test diff --git a/setup.py b/setup.py index 6f815e4..423ef82 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ "qrdet>=2.5", ], extras_require={ - "tests": ["mypy", "pytest"], + "tests": ["mypy", "pytest", "qrcode"], }, classifiers=[ "Development Status :: 5 - Production/Stable", diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/integration/__init__.py b/tests/integration/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/main.py b/tests/integration/test_qreader.py similarity index 74% rename from main.py rename to tests/integration/test_qreader.py index 96fcd35..6379682 100644 --- a/main.py +++ b/tests/integration/test_qreader.py @@ -1,17 +1,13 @@ import os import cv2 +import qrcode from qrdet import BBOX_XYXY from qreader import QReader -SAMPLE_IMG = os.path.join( - os.path.dirname(__file__), "documentation", "resources", "test_draw_64x64.jpeg" -) - -def utf_errors_test(): - import qrcode +def test_utf_errors(): qreader = QReader(model_size="n") image_path = "my_image.png" @@ -26,10 +22,21 @@ def utf_errors_test(): print(f"result = {result[0]}") -def decode_test_set(): +def test_decode_test_set(): images = [ - os.path.join(os.path.dirname(__file__), "testset", filename) - for filename in os.listdir(os.path.join(os.path.dirname(__file__), "testset")) + os.path.join( + os.path.dirname(__file__), + "..", + "..", + "documentation", + "resources", + filename, + ) + for filename in os.listdir( + os.path.join( + os.path.dirname(__file__), "..", "..", "documentation", "resources" + ) + ) ] # Initialize QReader detector = QReader(model_size="n") @@ -49,8 +56,3 @@ def decode_test_set(): pass # decoded_qrs = detector.detect_and_decode(image=img, return_detections=False) print("-------------------") - - -if __name__ == "__main__": - utf_errors_test() - # decode_test_set() diff --git a/tests/preformance/__init__.py b/tests/preformance/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/performance_test.py b/tests/preformance/test_performance.py similarity index 82% rename from performance_test.py rename to tests/preformance/test_performance.py index 693fae4..12aa3fe 100644 --- a/performance_test.py +++ b/tests/preformance/test_performance.py @@ -8,13 +8,18 @@ from qreader import QReader SAMPLE_IMG_1 = os.path.join( - os.path.dirname(__file__), "documentation", "resources", "64x64.png" + os.path.dirname(__file__), "..", "..", "documentation", "resources", "64x64.png" ) SAMPLE_IMG_2 = os.path.join( - os.path.dirname(__file__), "documentation", "resources", "512x512.jpeg" + os.path.dirname(__file__), "..", "..", "documentation", "resources", "512x512.jpeg" ) SAMPLE_IMG_3 = os.path.join( - os.path.dirname(__file__), "documentation", "resources", "1024x1024.jpeg" + os.path.dirname(__file__), + "..", + "..", + "documentation", + "resources", + "1024x1024.jpeg", ) PERFORMANCE_TEST_IAMGES = { @@ -24,7 +29,8 @@ } RUNS_TO_AVERAGE, WARMUP_ITERATIONS = 5, 5 -if __name__ == "__main__": + +def test_performance(): results = {} for shape, img_path in tqdm(PERFORMANCE_TEST_IAMGES.items()): # Read the image