Skip to content

Commit

Permalink
Drop unittest usage in favour of pytest.
Browse files Browse the repository at this point in the history
  • Loading branch information
KelSolaar committed May 20, 2024
1 parent 46be1eb commit 0bc0fea
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 51 deletions.
52 changes: 22 additions & 30 deletions colour_checker_detection/detection/tests/test_common.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# !/usr/bin/env python
"""
Define the unit tests for the
:mod:`colour_checker_detection.detection.common` module.
"""

import glob
import os
import unittest

import numpy as np
from colour import read_image
Expand Down Expand Up @@ -64,7 +62,7 @@
PNG_FILES = sorted(glob.glob(os.path.join(DETECTION_DIRECTORY, "IMG_19*.png")))


class TestSwatchMasks(unittest.TestCase):
class TestSwatchMasks:
"""
Define :func:`colour_checker_detection.detection.common.swatch_masks`
definition unit tests methods.
Expand Down Expand Up @@ -93,7 +91,7 @@ def test_swatch_masks(self):
)


class TestSwatchColours(unittest.TestCase):
class TestSwatchColours:
"""
Define :func:`colour_checker_detection.detection.common.swatch_colours`
definition unit tests methods.
Expand Down Expand Up @@ -128,7 +126,7 @@ def test_swatch_colours(self):
)


class TestReformatImage(unittest.TestCase):
class TestReformatImage:
"""
Define :func:`colour_checker_detection.detection.common.reformat_image`
definition unit tests methods.
Expand All @@ -147,13 +145,13 @@ def test_reformat_image(self):

path = next(png_file for png_file in PNG_FILES if "1970" in png_file)

self.assertEqual(
reformat_image(read_image(path), 1440).shape[1],
SETTINGS_SEGMENTATION_COLORCHECKER_CLASSIC["working_width"],
assert (
reformat_image(read_image(path), 1440).shape[1]
== SETTINGS_SEGMENTATION_COLORCHECKER_CLASSIC["working_width"]
)


class TestTransformImage(unittest.TestCase):
class TestTransformImage:
"""
Define :func:`colour_checker_detection.detection.common.transform_image`
definition unit tests methods.
Expand Down Expand Up @@ -217,7 +215,7 @@ def test_transform_image(self):
)


class TestDetectContours(unittest.TestCase):
class TestDetectContours:
"""
Define :func:`colour_checker_detection.detection.common.detect_contours`
definition unit tests methods.
Expand All @@ -233,10 +231,10 @@ def test_detect_contours(self):
image[100:140, 50:90] = 1
image[150:190, 140:180] = 1

self.assertEqual(len(detect_contours(image)), 5)
assert len(detect_contours(image)) == 5


class TestIsSquare(unittest.TestCase):
class TestIsSquare:
"""
Define :func:`colour_checker_detection.detection.common.is_square`
definition unit tests methods.
Expand All @@ -249,14 +247,14 @@ def test_is_square(self):
"""

shape = np.array([[0, 0], [1, 0], [1, 1], [0, 1]])
self.assertTrue(is_square(shape))
assert is_square(shape)

shape = np.array([[0, 0.5], [1, 0], [1, 1], [0, 1]])
self.assertFalse(is_square(shape))
self.assertTrue(is_square(shape, 0.5))
assert not is_square(shape)
assert is_square(shape, 0.5)


class TestContourCentroid(unittest.TestCase):
class TestContourCentroid:
"""
Define :func:`colour_checker_detection.detection.common.contour_centroid`
definition unit tests methods.
Expand All @@ -272,7 +270,7 @@ def test_contour_centroid(self):
np.testing.assert_array_equal(contour_centroid(contour), (0.5, 0.5))


class TestScaleContour(unittest.TestCase):
class TestScaleContour:
"""
Define :func:`colour_checker_detection.detection.common.scale_contour`
definition unit tests methods.
Expand All @@ -296,7 +294,7 @@ def test_scale_contour(self):
)


class TestApproximateContour(unittest.TestCase):
class TestApproximateContour:
"""
Define :func:`colour_checker_detection.detection.common.approximate_contour`
definition unit tests methods.
Expand All @@ -321,7 +319,7 @@ def test_approximate_contour(self):
)


class TestQuadrilateraliseContours(unittest.TestCase):
class TestQuadrilateraliseContours:
"""
Define :func:`colour_checker_detection.detection.common.\
quadrilateralise_contours` definition unit tests methods.
Expand Down Expand Up @@ -351,7 +349,7 @@ def test_quadrilateralise_contours(self):
)


class TestRemoveStackedContours(unittest.TestCase):
class TestRemoveStackedContours:
"""
Define :func:`colour_checker_detection.detection.common.\
remove_stacked_contours` definition unit tests methods.
Expand Down Expand Up @@ -382,7 +380,7 @@ def test_remove_stacked_contours(self):
)


class TestSampleColourChecker(unittest.TestCase):
class TestSampleColourChecker:
"""
Define :func:`colour_checker_detection.detection.common.\
remove_stacked_contours` definition unit tests methods.
Expand Down Expand Up @@ -440,12 +438,6 @@ def test_sample_colour_checker(self):
atol=TOLERANCE_ABSOLUTE_TESTS,
)

self.assertTupleEqual(colour_checkers_data.swatch_masks.shape, (24, 4))
self.assertTupleEqual(colour_checkers_data.colour_checker.shape, (960, 1440, 3))
self.assertTupleEqual(
colour_checkers_data.quadrilateral.shape, quadrilateral.shape
)


if __name__ == "__main__":
unittest.main()
assert colour_checkers_data.swatch_masks.shape == (24, 4)
assert colour_checkers_data.colour_checker.shape == (960, 1440, 3)
assert colour_checkers_data.quadrilateral.shape == quadrilateral.shape
18 changes: 6 additions & 12 deletions colour_checker_detection/detection/tests/test_inference.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# !/usr/bin/env python
"""
Define the unit tests for the
:mod:`colour_checker_detection.detection.inference` module.
Expand All @@ -8,7 +7,6 @@
import os
import platform
import sys
import unittest

import numpy as np
from colour import read_image
Expand Down Expand Up @@ -40,7 +38,7 @@
PNG_FILES = sorted(glob.glob(os.path.join(DETECTION_DIRECTORY, "IMG_19*.png")))[:-2]


class TestInferencerDefault(unittest.TestCase):
class TestInferencerDefault:
"""
Define :func:`colour_checker_detection.detection.inference.\
inferencer_default` definition unit tests methods.
Expand Down Expand Up @@ -74,12 +72,12 @@ def test_inferencer_default(self):

for i, png_file in enumerate(PNG_FILES):
results = inferencer_default(png_file)
self.assertTrue(results[0][0] > 0.85)
self.assertEqual(int(results[0][1]), 0)
self.assertTupleEqual(results[0][2].shape, shapes[i])
assert results[0][0] > 0.85
assert int(results[0][1]) == 0
assert results[0][2].shape == shapes[i]


class TestDetectColourCheckersInference(unittest.TestCase):
class TestDetectColourCheckersInference:
"""
Define :func:`colour_checker_detection.detection.inference.\
detect_colour_checkers_inference` definition unit tests methods.
Expand Down Expand Up @@ -286,8 +284,4 @@ def test_detect_colour_checkers_inference(self):
),
)

self.assertTupleEqual(quadrilateral.shape, (4, 2))


if __name__ == "__main__":
unittest.main()
assert quadrilateral.shape == (4, 2)
12 changes: 3 additions & 9 deletions colour_checker_detection/detection/tests/test_segmentation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# !/usr/bin/env python
"""
Define the unit tests for the
:mod:`colour_checker_detection.detection.segmentation` module.
Expand All @@ -7,7 +6,6 @@
import glob
import os
import platform
import unittest

import numpy as np
from colour import read_image
Expand Down Expand Up @@ -39,7 +37,7 @@
PNG_FILES = sorted(glob.glob(os.path.join(DETECTION_DIRECTORY, "IMG_19*.png")))


class TestSegmenterDefault(unittest.TestCase):
class TestSegmenterDefault:
"""
Define :func:`colour_checker_detection.detection.segmentation.\
segmenter_default` definition unit tests methods.
Expand Down Expand Up @@ -129,7 +127,7 @@ def test_segmenter_default(self):
)


class TestDetectColourCheckersSegmentation(unittest.TestCase):
class TestDetectColourCheckersSegmentation:
"""
Define :func:`colour_checker_detection.detection.segmentation.\
detect_colour_checkers_segmentation` definition unit tests methods.
Expand Down Expand Up @@ -392,8 +390,4 @@ def test_detect_colour_checkers_segmentation(self):
),
)

self.assertTupleEqual(quadrilateral.shape, (4, 2))


if __name__ == "__main__":
unittest.main()
assert quadrilateral.shape == (4, 2)
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ convention = "numpy"
"colour-checker-detection/examples/*" = ["INP", "T201", "T203"]
"docs/*" = ["INP"]
"tasks.py" = ["INP"]
"test_*" = ["S101"]
"utilities/*" = ["EXE001", "INP"]
"utilities/unicode_to_ascii.py" = ["RUF001"]

Expand Down

0 comments on commit 0bc0fea

Please sign in to comment.