From 2f6f20f5eae600e290656108bdeb95c43bb823d4 Mon Sep 17 00:00:00 2001 From: Thomas Mansencal Date: Mon, 20 May 2024 22:20:38 +1200 Subject: [PATCH] Drop `unittest` usage in favour of `pytest`. --- .../tests/test_absolute_luminance.py | 12 +- .../calibration/tests/test_debevec1997.py | 10 +- colour_hdri/distortion/tests/test_vignette.py | 30 ++- colour_hdri/exposure/tests/test_common.py | 16 +- colour_hdri/exposure/tests/test_dsc.py | 20 +- colour_hdri/generation/tests/test_hdri.py | 8 +- .../tests/test_weighting_functions.py | 12 +- colour_hdri/models/tests/test_adobe_dng.py | 17 +- colour_hdri/models/tests/test_rgb.py | 10 +- colour_hdri/process/tests/test_dng.py | 26 +-- colour_hdri/recovery/tests/test_recovery.py | 18 +- .../sampling/tests/test_grossberg2003.py | 8 +- .../tests/test_variance_minimization.py | 74 +++---- .../global_operators/tests/test_operators.py | 30 ++- colour_hdri/utilities/tests/test_common.py | 47 ++--- colour_hdri/utilities/tests/test_exif.py | 181 ++++++++---------- colour_hdri/utilities/tests/test_image.py | 52 +++-- pyproject.toml | 1 + 18 files changed, 224 insertions(+), 348 deletions(-) diff --git a/colour_hdri/calibration/tests/test_absolute_luminance.py b/colour_hdri/calibration/tests/test_absolute_luminance.py index 7055cdf..7b79af2 100644 --- a/colour_hdri/calibration/tests/test_absolute_luminance.py +++ b/colour_hdri/calibration/tests/test_absolute_luminance.py @@ -1,4 +1,3 @@ -# !/usr/bin/env python """ Define the unit tests for the :mod:`colour_hdri.calibration.absolute_luminance` module. @@ -7,7 +6,6 @@ from __future__ import annotations import os -import unittest import numpy as np from colour import read_image @@ -42,7 +40,7 @@ ) -class TestUpperHemisphereIlluminanceLagarde2016(unittest.TestCase): +class TestUpperHemisphereIlluminanceLagarde2016: """ Define :func:`colour_hdri.calibration.absolute_luminance.\ upper_hemisphere_illuminance_Lagarde2016` definition unit tests methods. @@ -73,7 +71,7 @@ def test_upper_hemisphere_illuminance_Lagarde2016(self): ) -class TestUpperHemisphereIlluminanceWeightsLagarde2016(unittest.TestCase): +class TestUpperHemisphereIlluminanceWeightsLagarde2016: """ Define :func:`colour_hdri.calibration.absolute_luminance.\ upper_hemisphere_illuminance_weights_Lagarde2016` definition unit tests @@ -130,7 +128,7 @@ def test_upper_hemisphere_illuminance_weights_Lagarde2016(self): ) -class TestAbsoluteLuminanceCalibrationLagarde2016(unittest.TestCase): +class TestAbsoluteLuminanceCalibrationLagarde2016: """ Define :func:`colour_hdri.calibration.absolute_luminance.\ absolute_luminance_calibration_Lagarde2016` definition unit tests methods. @@ -171,7 +169,3 @@ def test_absolute_luminance_calibration_Lagarde2016(self): rtol=0.0000001, atol=0.0000001, ) - - -if __name__ == "__main__": - unittest.main() diff --git a/colour_hdri/calibration/tests/test_debevec1997.py b/colour_hdri/calibration/tests/test_debevec1997.py index 8e87b3d..3e38187 100644 --- a/colour_hdri/calibration/tests/test_debevec1997.py +++ b/colour_hdri/calibration/tests/test_debevec1997.py @@ -1,4 +1,3 @@ -# !/usr/bin/env python """ Define the unit tests for the :mod:`colour_hdri.calibration.debevec1997` module. @@ -7,7 +6,6 @@ from __future__ import annotations import os -import unittest import numpy as np from colour.hints import List @@ -45,7 +43,7 @@ IMAGES_JPG: List[str] = filter_files(ROOT_RESOURCES_FROBISHER_001, ("jpg",)) -class TestGSolve(unittest.TestCase): +class TestGSolve: """ Define :func:`colour_hdri.calibration.debevec1997.g_solve` definition unit tests methods. @@ -87,7 +85,7 @@ def test_g_solve(self): ) -class TestCameraResponseFunctionsDebevec1997(unittest.TestCase): +class TestCameraResponseFunctionsDebevec1997: """ Define :func:`colour_hdri.calibration.debevec1997.\ camera_response_functions_Debevec1997` definition unit tests methods. @@ -110,7 +108,3 @@ def test_camera_response_function_Debevec1997(self): ), atol=0.00001, ) - - -if __name__ == "__main__": - unittest.main() diff --git a/colour_hdri/distortion/tests/test_vignette.py b/colour_hdri/distortion/tests/test_vignette.py index 68a7ada..3c7bbc9 100644 --- a/colour_hdri/distortion/tests/test_vignette.py +++ b/colour_hdri/distortion/tests/test_vignette.py @@ -1,4 +1,3 @@ -# !/usr/bin/env python """ Define the unit tests for the :mod:`colour_hdri.distortion.vignette` module. """ @@ -6,7 +5,6 @@ from __future__ import annotations import os -import unittest import numpy as np from colour.constants import TOLERANCE_ABSOLUTE_TESTS @@ -55,7 +53,7 @@ ) -class TestApplyRadialGradient(unittest.TestCase): +class TestApplyRadialGradient: """ Define :func:`colour_hdri.distortion.vignette.apply_radial_gradient` definition unit tests methods. @@ -122,7 +120,7 @@ def test_apply_radial_gradient(self): ) -class TestParabolic2DFunction(unittest.TestCase): +class TestParabolic2DFunction: """ Define :func:`colour_hdri.distortion.vignette.parabolic_2D_function` definition unit tests methods. @@ -194,7 +192,7 @@ def test_parabolic_2D_function(self): ) -class TestHyperbolicCosine2DFunction(unittest.TestCase): +class TestHyperbolicCosine2DFunction: """ Define :func:`colour_hdri.distortion.vignette.hyperbolic_cosine_2D_function` definition unit tests methods. @@ -266,7 +264,7 @@ def test_hyperbolic_cosine_2D_function(self): ) -class TestVignettePrincipalPoint(unittest.TestCase): +class TestVignettePrincipalPoint: """ Define :func:`colour_hdri.distortion.vignette.vignette_principal_point` definition unit tests methods. @@ -285,7 +283,7 @@ def test_vignette_principal_point(self): ) -class TestCharacteriseVignette2DFunction(unittest.TestCase): +class TestCharacteriseVignette2DFunction: """ Define :func:`colour_hdri.distortion.vignette.\ characterise_vignette_2D_function` definition unit tests methods. @@ -378,7 +376,7 @@ def test_characterise_vignette_2D_function(self): ) -class TestCorrectVignette2DFunction(unittest.TestCase): +class TestCorrectVignette2DFunction: """ Define :func:`colour_hdri.distortion.vignette.correct_vignette_2D_function` definition unit tests methods. @@ -508,7 +506,7 @@ def test_correct_vignette_2D_function(self): ) -class TestCharacteriseVignetteBivariateSpline(unittest.TestCase): +class TestCharacteriseVignetteBivariateSpline: """ Define :func:`colour_hdri.distortion.vignette.\ characterise_vignette_bivariate_spline` definition unit tests methods. @@ -541,7 +539,7 @@ def test_characterise_vignette_bivariate_spline(self): ) -class TestCorrectVignetteBivariateSpline(unittest.TestCase): +class TestCorrectVignetteBivariateSpline: """ Define :func:`colour_hdri.distortion.vignette.\ correct_vignette_bivariate_spline` definition unit tests methods. @@ -611,7 +609,7 @@ def test_correct_vignette_bivariate_spline(self): ) -class TestRadialSamplingFunction(unittest.TestCase): +class TestRadialSamplingFunction: """ Define :func:`colour_hdri.distortion.vignette.radial_sampling_function` definition unit tests methods. @@ -822,7 +820,7 @@ def test_radial_sampling_function(self): ) -class TestVignetteSamplingCoordinates(unittest.TestCase): +class TestVignetteSamplingCoordinates: """ Define :func:`colour_hdri.distortion.vignette.vignette_sampling_coordinates` definition unit tests methods. @@ -1009,7 +1007,7 @@ def test_vignette_sampling_coordinates(self): ) -class TestCharacteriseVignetteRBF(unittest.TestCase): +class TestCharacteriseVignetteRBF: """ Define :func:`colour_hdri.distortion.vignette.characterise_vignette_RBF` definition unit tests methods. @@ -1211,7 +1209,7 @@ def test_characterise_vignette_RBF(self): ) -class TestCorrectVignetteRBF(unittest.TestCase): +class TestCorrectVignetteRBF: """ Define :func:`colour_hdri.distortion.vignette.correct_vignette_RBF` definition unit tests methods. @@ -1279,7 +1277,3 @@ def test_correct_vignette_RBF(self): ), atol=TOLERANCE_ABSOLUTE_TESTS, ) - - -if __name__ == "__main__": - unittest.main() diff --git a/colour_hdri/exposure/tests/test_common.py b/colour_hdri/exposure/tests/test_common.py index 6ca6fc8..0abd802 100644 --- a/colour_hdri/exposure/tests/test_common.py +++ b/colour_hdri/exposure/tests/test_common.py @@ -1,7 +1,5 @@ -# !/usr/bin/env python """Define the unit tests for the :mod:`colour_hdri.exposure.common` module.""" -import unittest import numpy as np from colour.constants import TOLERANCE_ABSOLUTE_TESTS @@ -29,7 +27,7 @@ ] -class TestAverageLuminance(unittest.TestCase): +class TestAverageLuminance: """ Define :func:`colour_hdri.exposure.common.average_luminance` definition unit tests methods. @@ -49,7 +47,7 @@ def test_average_luminance(self): ) -class TestAverageIlluminance(unittest.TestCase): +class TestAverageIlluminance: """ Define :func:`colour_hdri.exposure.common.average_illuminance` definition unit tests methods. @@ -72,7 +70,7 @@ def test_average_illuminance(self): ) -class TestLuminanceToExposureValue(unittest.TestCase): +class TestLuminanceToExposureValue: """ Define :func:`colour_hdri.exposure.common.luminance_to_exposure_value` definition unit tests methods. @@ -95,7 +93,7 @@ def test_luminance_to_exposure_value(self): ) -class TestIlluminanceToExposureValue(unittest.TestCase): +class TestIlluminanceToExposureValue: """ Define :func:`colour_hdri.exposure.common.illuminance_to_exposure_value` definition unit tests methods. @@ -118,7 +116,7 @@ def test_illuminance_to_exposure_value(self): ) -class TestAdjustExposure(unittest.TestCase): +class TestAdjustExposure: """ Define :func:`colour_hdri.exposure.common.adjust_exposure` definition unit tests methods. @@ -132,7 +130,3 @@ def test_adjust_exposure(self): np.array([0.5, 1.0, 1.5, 2.0]), atol=TOLERANCE_ABSOLUTE_TESTS, ) - - -if __name__ == "__main__": - unittest.main() diff --git a/colour_hdri/exposure/tests/test_dsc.py b/colour_hdri/exposure/tests/test_dsc.py index bb920e9..3917d66 100644 --- a/colour_hdri/exposure/tests/test_dsc.py +++ b/colour_hdri/exposure/tests/test_dsc.py @@ -1,7 +1,5 @@ -# !/usr/bin/env python """Define the unit tests for the :mod:`colour_hdri.exposure.dsc` module.""" -import unittest import numpy as np from colour.constants import TOLERANCE_ABSOLUTE_TESTS @@ -34,7 +32,7 @@ ] -class TestQFactor(unittest.TestCase): +class TestQFactor: """ Define :func:`colour_hdri.exposure.dsc.q_factor` definition unit tests methods. @@ -54,7 +52,7 @@ def test_q_factor(self): ) -class TestFocalPlaneExposure(unittest.TestCase): +class TestFocalPlaneExposure: """ Define :func:`colour_hdri.exposure.dsc.focal_plane_exposure` definition unit tests methods. @@ -80,7 +78,7 @@ def test_focal_plane_exposure(self): ) -class TestArithmeticMeanFocalPlaneExposure(unittest.TestCase): +class TestArithmeticMeanFocalPlaneExposure: """ Define :func:`colour_hdri.exposure.dsc.\ arithmetic_mean_focal_plane_exposure` definition unit tests methods. @@ -103,7 +101,7 @@ def test_arithmetic_mean_focal_plane_exposure(self): ) -class TestSaturationBasedSpeedFocalPlaneExposure(unittest.TestCase): +class TestSaturationBasedSpeedFocalPlaneExposure: """ Define :func:`colour_hdri.exposure.dsc.\ saturation_based_speed_focal_plane_exposure` definition unit tests methods. @@ -133,7 +131,7 @@ def test_saturation_based_speed_focal_plane_exposure(self): ) -class TestExposureIndexValues(unittest.TestCase): +class TestExposureIndexValues: """ Define :func:`colour_hdri.exposure.dsc.exposure_index_values` definition unit tests methods. @@ -152,7 +150,7 @@ def test_exposure_index_values(self): ) -class TestExposureValue100(unittest.TestCase): +class TestExposureValue100: """ Define :func:`colour_hdri.exposure.dsc.exposure_value_100` definition unit tests methods. @@ -175,7 +173,7 @@ def test_exposure_value_100(self): ) -class TestPhotometricExposureScaleFactorLagarde2014(unittest.TestCase): +class TestPhotometricExposureScaleFactorLagarde2014: """ Define :func:`colour_hdri.exposure.dsc.\ photometric_exposure_scale_factor_Lagarde2014` definition unit tests @@ -198,7 +196,3 @@ def test_photometric_exposure_scale_factor_Lagarde2014(self): np.array([0.00005221, 0.00037884, 0.00135554]), atol=TOLERANCE_ABSOLUTE_TESTS, ) - - -if __name__ == "__main__": - unittest.main() diff --git a/colour_hdri/generation/tests/test_hdri.py b/colour_hdri/generation/tests/test_hdri.py index 9879222..b397f7b 100644 --- a/colour_hdri/generation/tests/test_hdri.py +++ b/colour_hdri/generation/tests/test_hdri.py @@ -1,10 +1,8 @@ -# !/usr/bin/env python """Define the unit tests for the :mod:`colour_hdri.generation.radiance` module.""" from __future__ import annotations import os -import unittest import numpy as np from colour import RGB_COLOURSPACES @@ -38,7 +36,7 @@ IMAGES_JPG: List[str] = filter_files(ROOT_RESOURCES_FROBISHER_001, ("jpg",)) -class TestImageStackToHDRI(unittest.TestCase): +class TestImageStackToHDRI: """ Define :func:`colour_hdri.generation.radiance.image_stack_to_HDRI` definition unit tests methods. @@ -84,7 +82,3 @@ def test_image_stack_to_HDRI(self): rtol=0.0001, atol=0.0001, ) - - -if __name__ == "__main__": - unittest.main() diff --git a/colour_hdri/generation/tests/test_weighting_functions.py b/colour_hdri/generation/tests/test_weighting_functions.py index b150ad3..d095622 100644 --- a/colour_hdri/generation/tests/test_weighting_functions.py +++ b/colour_hdri/generation/tests/test_weighting_functions.py @@ -1,10 +1,8 @@ -# !/usr/bin/env python """ Define the unit tests for the :mod:`colour_hdri.generation.weighting_functions` module. """ -import unittest import numpy as np from colour.constants import TOLERANCE_ABSOLUTE_TESTS @@ -29,7 +27,7 @@ ] -class TestNormalDistributionFunction(unittest.TestCase): +class TestNormalDistributionFunction: """ Define :func:`colour_hdri.generation.weighting_functions.\ normal_distribution_function` definition unit tests methods. @@ -99,7 +97,7 @@ def test_normal_distribution_function(self): ) -class TestHatFunction(unittest.TestCase): +class TestHatFunction: """ Define :func:`colour_hdri.generation.weighting_functions.hat_function` definition unit tests methods. @@ -131,7 +129,7 @@ def test_hat_function(self): ) -class TestWeightingFunctionDebevec1997(unittest.TestCase): +class TestWeightingFunctionDebevec1997: """ Define :func:`colour_hdri.generation.weighting_functions.\ weighting_function_Debevec1997` definition unit tests methods. @@ -199,7 +197,3 @@ def test_weighting_function_Debevec1997(self): ), atol=TOLERANCE_ABSOLUTE_TESTS, ) - - -if __name__ == "__main__": - unittest.main() diff --git a/colour_hdri/models/tests/test_adobe_dng.py b/colour_hdri/models/tests/test_adobe_dng.py index d6b33d1..44c433d 100644 --- a/colour_hdri/models/tests/test_adobe_dng.py +++ b/colour_hdri/models/tests/test_adobe_dng.py @@ -1,4 +1,3 @@ -# !/usr/bin/env python """ Define the unit tests for the :mod:`colour_hdri.models.dng` module. @@ -10,8 +9,6 @@ from __future__ import annotations -import unittest - import numpy as np from colour.constants import TOLERANCE_ABSOLUTE_TESTS from colour.hints import NDArrayFloat @@ -99,7 +96,7 @@ ) -class TestMatrixInterpolated(unittest.TestCase): +class TestMatrixInterpolated: """ Define :func:`colour_hdri.models.adobe_dng.matrix_interpolated` definition unit tests methods. @@ -149,7 +146,7 @@ def test_matrix_interpolated(self): ) -class TestXy_to_camera_neutral(unittest.TestCase): +class TestXy_to_camera_neutral: """ Define :func:`colour_hdri.models.adobe_dng.\ xy_to_camera_neutral` definition unit tests methods. @@ -207,7 +204,7 @@ def test_xy_to_camera_neutral(self): ) -class TestCamera_neutral_to_xy(unittest.TestCase): +class TestCamera_neutral_to_xy: """ Define :func:`colour_hdri.models.adobe_dng.\ camera_neutral_to_xy` definition unit tests methods. @@ -265,7 +262,7 @@ def test_camera_neutral_to_xy(self): ) -class TestMatrix_XYZ_to_camera_space(unittest.TestCase): +class TestMatrix_XYZ_to_camera_space: """ Define :func:`colour_hdri.models.adobe_dng.\ matrix_XYZ_to_camera_space` definition unit tests methods. @@ -343,7 +340,7 @@ def test_matrix_XYZ_to_camera_space(self): ) -class TestMatrix_Camera_space_to_XYZ(unittest.TestCase): +class TestMatrix_Camera_space_to_XYZ: """ Define :func:`colour_hdri.models.adobe_dng.\ matrix_camera_space_to_XYZ` definition unit tests methods. @@ -450,7 +447,3 @@ def test_matrix_camera_space_to_XYZ(self): M_reference, atol=TOLERANCE_ABSOLUTE_TESTS, ) - - -if __name__ == "__main__": - unittest.main() diff --git a/colour_hdri/models/tests/test_rgb.py b/colour_hdri/models/tests/test_rgb.py index b90ef59..605524a 100644 --- a/colour_hdri/models/tests/test_rgb.py +++ b/colour_hdri/models/tests/test_rgb.py @@ -1,7 +1,5 @@ -# !/usr/bin/env python """Define the unit tests for the :mod:`colour_hdri.models.rgb` module.""" -import unittest import numpy as np from colour.constants import TOLERANCE_ABSOLUTE_TESTS @@ -21,7 +19,7 @@ ] -class TestCameraSpaceToRGB(unittest.TestCase): +class TestCameraSpaceToRGB: """ Define :func:`colour_hdri.models.rgb.camera_space_to_RGB` definition unit tests methods. @@ -53,7 +51,7 @@ def test_camera_space_to_RGB(self): ) -class TestCameraSpaceTosRGB(unittest.TestCase): +class TestCameraSpaceTosRGB: """ Define :func:`colour_hdri.models.rgb.camera_space_to_sRGB` definition unit tests methods. @@ -76,7 +74,3 @@ def test_camera_space_to_sRGB(self): np.array([0.75643502, 0.86831555, 0.60447061]), atol=TOLERANCE_ABSOLUTE_TESTS, ) - - -if __name__ == "__main__": - unittest.main() diff --git a/colour_hdri/process/tests/test_dng.py b/colour_hdri/process/tests/test_dng.py index 1de6e4c..f67afa1 100644 --- a/colour_hdri/process/tests/test_dng.py +++ b/colour_hdri/process/tests/test_dng.py @@ -1,4 +1,3 @@ -# !/usr/bin/env python """Define the unit tests for the :mod:`colour_hdri.process.adobe_dng` module.""" from __future__ import annotations @@ -7,7 +6,6 @@ import platform import shutil import tempfile -import unittest import zipfile import numpy as np @@ -45,18 +43,18 @@ IMAGES_RAW: List[str] = filter_files(ROOT_RESOURCES_FROBISHER_001, ("CR2",)) -class TestConvertRawFilesToDngFiles(unittest.TestCase): +class TestConvertRawFilesToDngFiles: """ Define :func:`colour_hdri.process.adobe_dng.\ convert_raw_files_to_dng_files` definition unit tests methods. """ - def setUp(self): + def setup_method(self): """Initialise the common tests attributes.""" self._temporary_directory = tempfile.mkdtemp() - def tearDown(self): + def teardown_method(self): """After tests actions.""" shutil.rmtree(self._temporary_directory) @@ -87,18 +85,18 @@ def test_convert_raw_files_to_dng_files(self): ) -class TestConvertDngFilesToIntermediateFiles(unittest.TestCase): +class TestConvertDngFilesToIntermediateFiles: """ Define :func:`colour_hdri.process.adobe_dng.\ convert_dng_files_to_intermediate_files` definition unit tests methods. """ - def setUp(self): + def setup_method(self): """Initialise the common tests attributes.""" self._temporary_directory = tempfile.mkdtemp() - def tearDown(self): + def teardown_method(self): """After tests actions.""" shutil.rmtree(self._temporary_directory) @@ -164,7 +162,7 @@ def test_convert_dng_files_to_intermediate_files(self): ) -class TestReadDngFilesExifTags(unittest.TestCase): +class TestReadDngFilesExifTags: """ Define :func:`colour_hdri.process.adobe_dng.\ read_dng_files_exif_tags` definition unit tests methods. @@ -178,9 +176,9 @@ def test_read_dng_files_exif_tags(self): reference_dng_files = sorted(filter_files(ROOT_PROCESS, ("dng",))) exif_tags = read_dng_files_exif_tags(reference_dng_files) - self.assertEqual(len(exif_tags), 3) - self.assertIn("EXIF", exif_tags[0]) - self.assertIn("Make", exif_tags[0]["EXIF"]) + assert len(exif_tags) == 3 + assert "EXIF" in exif_tags[0] + assert "Make" in exif_tags[0]["EXIF"] np.testing.assert_allclose( exif_tags[0]["EXIF"]["Exposure Time"], @@ -191,7 +189,3 @@ def test_read_dng_files_exif_tags(self): np.testing.assert_array_equal( exif_tags[0]["EXIF"]["Reduction Matrix 1"], np.identity(3) ) - - -if __name__ == "__main__": - unittest.main() diff --git a/colour_hdri/recovery/tests/test_recovery.py b/colour_hdri/recovery/tests/test_recovery.py index 5e467f8..4da849e 100644 --- a/colour_hdri/recovery/tests/test_recovery.py +++ b/colour_hdri/recovery/tests/test_recovery.py @@ -1,4 +1,3 @@ -# !/usr/bin/env python """Define the unit tests for the :mod:`colour_hdri.recovery.highlights` module.""" from __future__ import annotations @@ -10,7 +9,6 @@ import shutil import subprocess import tempfile -import unittest import numpy as np from colour import read_image @@ -64,18 +62,18 @@ ) -class TestHighlightsRecoveryBlend(unittest.TestCase): +class TestHighlightsRecoveryBlend: """ Define :func:`colour_hdri.recovery.highlights.highlights_recovery_blend` definition unit tests methods. """ - def setUp(self): + def setup_method(self): """Initialise the common tests attributes.""" self._temporary_directory = tempfile.mkdtemp() - def tearDown(self): + def teardown_method(self): """After tests actions.""" shutil.rmtree(self._temporary_directory) @@ -124,18 +122,18 @@ def test_highlights_recovery_blend(self): ) -class TestHighlightsRecoveryLCHab(unittest.TestCase): +class TestHighlightsRecoveryLCHab: """ Define :func:`colour_hdri.recovery.highlights.highlights_recovery_LCHab` definition unit tests methods. """ - def setUp(self): + def setup_method(self): """Initialise the common tests attributes.""" self._temporary_directory = tempfile.mkdtemp() - def tearDown(self): + def teardown_method(self): """After tests actions.""" shutil.rmtree(self._temporary_directory) @@ -183,7 +181,3 @@ def test_highlights_recovery_LCHab(self): np.testing.assert_allclose( test_tiff_file, reference_exr_file, rtol=0.0001, atol=0.0001 ) - - -if __name__ == "__main__": - unittest.main() diff --git a/colour_hdri/sampling/tests/test_grossberg2003.py b/colour_hdri/sampling/tests/test_grossberg2003.py index bd243f5..fa9f3eb 100644 --- a/colour_hdri/sampling/tests/test_grossberg2003.py +++ b/colour_hdri/sampling/tests/test_grossberg2003.py @@ -1,4 +1,3 @@ -# !/usr/bin/env python """ Define the unit tests for the :mod:`colour_hdri.sampling.grossberg2003` module. @@ -7,7 +6,6 @@ from __future__ import annotations import os -import unittest import numpy as np from colour.constants import TOLERANCE_ABSOLUTE_TESTS @@ -40,7 +38,7 @@ IMAGES_JPG: List[str] = filter_files(ROOT_RESOURCES_FROBISHER_001, ("jpg",)) -class TestSamplesGrossberg2003(unittest.TestCase): +class TestSamplesGrossberg2003: """ Define :func:`colour_hdri.sampling.grossberg2003.\ samples_Grossberg2003` definition unit tests methods. @@ -59,7 +57,3 @@ def test_samples_Grossberg2003(self): ), atol=TOLERANCE_ABSOLUTE_TESTS, ) - - -if __name__ == "__main__": - unittest.main() diff --git a/colour_hdri/sampling/tests/test_variance_minimization.py b/colour_hdri/sampling/tests/test_variance_minimization.py index 0357abd..b6d6b10 100644 --- a/colour_hdri/sampling/tests/test_variance_minimization.py +++ b/colour_hdri/sampling/tests/test_variance_minimization.py @@ -1,4 +1,3 @@ -# !/usr/bin/env python """ Define the unit tests for the :mod:`colour_hdri.sampling.variance_minimization` module. @@ -7,7 +6,6 @@ from __future__ import annotations import os -import unittest import numpy as np from colour import RGB_COLOURSPACES, RGB_luminance, read_image @@ -42,7 +40,7 @@ ) -class TestLuminanceVariance(unittest.TestCase): +class TestLuminanceVariance: """ Define :func:`colour_hdri.sampling.variance_minimization.\ luminance_variance` definition unit tests methods. @@ -61,7 +59,7 @@ def test_luminance_variance(self): ) -class TestFindRegionsVarianceMinimizationViriyothai2009(unittest.TestCase): +class TestFindRegionsVarianceMinimizationViriyothai2009: """ Define :func:`colour_hdri.sampling.variance_minimization.\ find_regions_variance_minimization_Viriyothai2009` definition unit tests @@ -89,44 +87,38 @@ def test_find_regions_variance_minimization_Viriyothai2009(self): Y = RGB_luminance(image, colourspace.primaries, colourspace.whitepoint) regions = find_regions_variance_minimization_Viriyothai2009(Y, n=1) - self.assertListEqual(regions, [(0, 256, 0, 156), (0, 256, 156, 256)]) + assert regions == [(0, 256, 0, 156), (0, 256, 156, 256)] regions = find_regions_variance_minimization_Viriyothai2009(Y, n=2) - self.assertListEqual( - regions, - [ - (0, 97, 0, 156), - (97, 256, 0, 156), - (0, 100, 156, 256), - (100, 256, 156, 256), - ], - ) + assert regions == [ + (0, 97, 0, 156), + (97, 256, 0, 156), + (0, 100, 156, 256), + (100, 256, 156, 256), + ] regions = find_regions_variance_minimization_Viriyothai2009(Y, n=4) - self.assertListEqual( - regions, - [ - (0, 39, 0, 91), - (39, 97, 0, 91), - (0, 39, 91, 156), - (39, 97, 91, 156), - (97, 159, 0, 92), - (97, 159, 92, 156), - (159, 256, 0, 93), - (159, 256, 93, 156), - (0, 42, 156, 216), - (42, 100, 156, 216), - (0, 44, 216, 256), - (44, 100, 216, 256), - (100, 163, 156, 215), - (100, 163, 215, 256), - (163, 256, 156, 216), - (163, 256, 216, 256), - ], - ) - - -class TestHighlightRegionsVarianceMinimization(unittest.TestCase): + assert regions == [ + (0, 39, 0, 91), + (39, 97, 0, 91), + (0, 39, 91, 156), + (39, 97, 91, 156), + (97, 159, 0, 92), + (97, 159, 92, 156), + (159, 256, 0, 93), + (159, 256, 93, 156), + (0, 42, 156, 216), + (42, 100, 156, 216), + (0, 44, 216, 256), + (44, 100, 216, 256), + (100, 163, 156, 215), + (100, 163, 215, 256), + (163, 256, 156, 216), + (163, 256, 216, 256), + ] + + +class TestHighlightRegionsVarianceMinimization: """ Define :func:`colour_hdri.sampling.variance_minimization.\ highlight_regions_variance_minimization` definition unit tests methods. @@ -166,7 +158,7 @@ def test_highlight_regions_variance_minimization(self): ) -class TestLightProbeSamplingVarianceMinimizationViriyothai2009(unittest.TestCase): +class TestLightProbeSamplingVarianceMinimizationViriyothai2009: """ Define :func:`colour_hdri.sampling.variance_minimization.\ light_probe_sampling_variance_minimization_Viriyothai2009` definition unit @@ -267,7 +259,3 @@ def test_light_probe_sampling_variance_minimization_Viriyothai2009(self): ] ), ) - - -if __name__ == "__main__": - unittest.main() diff --git a/colour_hdri/tonemapping/global_operators/tests/test_operators.py b/colour_hdri/tonemapping/global_operators/tests/test_operators.py index 9e068ed..461aca4 100644 --- a/colour_hdri/tonemapping/global_operators/tests/test_operators.py +++ b/colour_hdri/tonemapping/global_operators/tests/test_operators.py @@ -1,10 +1,8 @@ -# !/usr/bin/env python """ Define the unit tests for the :mod:`colour_hdri.tonemapping.global_operators.operators` module. """ -import unittest import numpy as np from colour.constants import TOLERANCE_ABSOLUTE_TESTS @@ -47,7 +45,7 @@ ] -class TestLogAverage(unittest.TestCase): +class TestLogAverage: """ Define :func:`colour_hdri.utilities.common.log_average` definition unit tests methods. @@ -64,7 +62,7 @@ def test_log_average(self): ) -class TestTonemappingOperatorSimple(unittest.TestCase): +class TestTonemappingOperatorSimple: """ Define :func:`colour_hdri.tonemapping.global_operators.operators.\ tonemapping_operator_simple` definition unit tests methods. @@ -107,7 +105,7 @@ def test_tonemapping_operator_simple(self): ) -class TestTonemappingOperatorNormalisation(unittest.TestCase): +class TestTonemappingOperatorNormalisation: """ Define :func:`colour_hdri.tonemapping.global_operators.operators.\ tonemapping_operator_normalisation` definition unit tests methods. @@ -150,7 +148,7 @@ def test_tonemapping_operator_normalisation(self): ) -class TestTonemappingOperatorGamma(unittest.TestCase): +class TestTonemappingOperatorGamma: """ Define :func:`colour_hdri.tonemapping.global_operators.operators.\ tonemapping_operator_gamma` definition unit tests methods. @@ -195,7 +193,7 @@ def test_tonemapping_operator_gamma(self): ) -class TestTonemappingOperatorLogarithmic(unittest.TestCase): +class TestTonemappingOperatorLogarithmic: """ Define :func:`colour_hdri.tonemapping.global_operators.operators.\ tonemapping_operator_logarithmic` definition unit tests methods. @@ -240,7 +238,7 @@ def test_tonemapping_operator_logarithmic(self): ) -class TestTonemappingOperatorExponential(unittest.TestCase): +class TestTonemappingOperatorExponential: """ Define :func:`colour_hdri.tonemapping.global_operators.operators.\ tonemapping_operator_exponential` definition unit tests methods. @@ -285,7 +283,7 @@ def test_tonemapping_operator_exponential(self): ) -class TestTonemappingOperatorLogarithmicMapping(unittest.TestCase): +class TestTonemappingOperatorLogarithmicMapping: """ Define :func:`colour_hdri.tonemapping.global_operators.operators.\ tonemapping_operator_logarithmic_mapping` definition unit tests methods. @@ -330,7 +328,7 @@ def test_tonemapping_operator_logarithmic_mapping(self): ) -class TestTonemappingOperatorExponentiationMapping(unittest.TestCase): +class TestTonemappingOperatorExponentiationMapping: """ Define :func:`colour_hdri.tonemapping.global_operators.operators.\ tonemapping_operator_exponentiation_mapping` definition unit tests methods. @@ -375,7 +373,7 @@ def test_tonemapping_operator_exponentiation_mapping(self): ) -class TestTonemappingOperatorSchlick1994(unittest.TestCase): +class TestTonemappingOperatorSchlick1994: """ Define :func:`colour_hdri.tonemapping.global_operators.operators.\ tonemapping_operator_Schlick1994` definition unit tests methods. @@ -419,7 +417,7 @@ def test_tonemapping_operator_Schlick1994(self): ) -class TestTonemappingOperatorTumblin1999(unittest.TestCase): +class TestTonemappingOperatorTumblin1999: """ Define :func:`colour_hdri.tonemapping.global_operators.operators.\ tonemapping_operator_Tumblin1999` definition unit tests methods. @@ -465,7 +463,7 @@ def test_tonemapping_operator_Tumblin1999(self): ) -class TestTonemappingOperatorReinhard2004(unittest.TestCase): +class TestTonemappingOperatorReinhard2004: """ Define :func:`colour_hdri.tonemapping.global_operators.operators.\ tonemapping_operator_Reinhard2004` definition unit tests methods. @@ -512,7 +510,7 @@ def test_tonemapping_operator_Reinhard2004(self): ) -class TestTonemappingOperatorFilmic(unittest.TestCase): +class TestTonemappingOperatorFilmic: """ Define :func:`colour_hdri.tonemapping.global_operators.operators.\ tonemapping_operator_filmic` definition unit tests methods. @@ -561,7 +559,3 @@ def test_tonemapping_operator_filmic(self): ), atol=TOLERANCE_ABSOLUTE_TESTS, ) - - -if __name__ == "__main__": - unittest.main() diff --git a/colour_hdri/utilities/tests/test_common.py b/colour_hdri/utilities/tests/test_common.py index cfe8531..4a562c2 100644 --- a/colour_hdri/utilities/tests/test_common.py +++ b/colour_hdri/utilities/tests/test_common.py @@ -1,10 +1,8 @@ -# !/usr/bin/env python """Define the unit tests for the :mod:`colour_hdri.utilities.common` module.""" from __future__ import annotations import os -import unittest from colour_hdri import ROOT_RESOURCES_TESTS from colour_hdri.utilities import ( @@ -32,7 +30,7 @@ ROOT_RESOURCES_FROBISHER_001: str = os.path.join(ROOT_RESOURCES_TESTS, "frobisher_001") -class TestVivification(unittest.TestCase): +class TestVivification: """ Define :func:`colour_hdri.utilities.common.vivification` definition unit tests methods. @@ -43,11 +41,11 @@ def test_vivification(self): vivified = vivification() vivified["my"]["attribute"] = 1 - self.assertIn("attribute", vivified["my"].keys()) - self.assertEqual(vivified["my"]["attribute"], 1) + assert "attribute" in vivified["my"] + assert vivified["my"]["attribute"] == 1 -class TestVivifiedToDict(unittest.TestCase): +class TestVivifiedToDict: """ Define :func:`colour_hdri.utilities.common.vivified_to_dict` definition unit tests methods. @@ -59,12 +57,12 @@ def test_vivified_to_dict(self): vivified = vivification() vivified["my"]["attribute"] = 1 vivified_as_dict = vivified_to_dict(vivified) - self.assertIsInstance({}, type(vivified_as_dict)) - self.assertIn("attribute", vivified_as_dict["my"].keys()) - self.assertEqual(vivified_as_dict["my"]["attribute"], 1) + assert isinstance({}, type(vivified_as_dict)) + assert "attribute" in vivified_as_dict["my"] + assert vivified_as_dict["my"]["attribute"] == 1 -class TestPathExists(unittest.TestCase): +class TestPathExists: """ Define :func:`colour_hdri.utilities.common.path_exists` definition unit tests methods. @@ -73,11 +71,11 @@ class TestPathExists(unittest.TestCase): def test_path_exists(self): """Test :func:`colour_hdri.utilities.common.path_exists` definition.""" - self.assertTrue(path_exists(__file__)) - self.assertFalse(path_exists("")) + assert path_exists(__file__) + assert not path_exists("") -class TestFilterFiles(unittest.TestCase): +class TestFilterFiles: """ Define :func:`colour_hdri.utilities.common.filter_files` definition unit tests methods. @@ -87,18 +85,11 @@ def test_filter_files(self): """Test :func:`colour_hdri.utilities.common.filter_files` definition.""" raw_files = filter_files(ROOT_RESOURCES_FROBISHER_001, ("CR2", "jpg")) - self.assertListEqual( - sorted(map(os.path.basename, raw_files)), - [ - "IMG_2600.CR2", - "IMG_2600.jpg", - "IMG_2601.CR2", - "IMG_2601.jpg", - "IMG_2602.CR2", - "IMG_2602.jpg", - ], - ) - - -if __name__ == "__main__": - unittest.main() + assert sorted(map(os.path.basename, raw_files)) == [ + "IMG_2600.CR2", + "IMG_2600.jpg", + "IMG_2601.CR2", + "IMG_2601.jpg", + "IMG_2602.CR2", + "IMG_2602.jpg", + ] diff --git a/colour_hdri/utilities/tests/test_exif.py b/colour_hdri/utilities/tests/test_exif.py index cd40022..a027a1b 100644 --- a/colour_hdri/utilities/tests/test_exif.py +++ b/colour_hdri/utilities/tests/test_exif.py @@ -1,4 +1,3 @@ -# !/usr/bin/env python """Define the unit tests for the :mod:`colour_hdri.utilities.exif` module.""" from __future__ import annotations @@ -6,7 +5,6 @@ import os import shutil import tempfile -import unittest import numpy as np from colour.constants import TOLERANCE_ABSOLUTE_TESTS @@ -54,7 +52,7 @@ ROOT_RESOURCES_FROBISHER_001: str = os.path.join(ROOT_RESOURCES_TESTS, "frobisher_001") -class TestParseExifString(unittest.TestCase): +class TestParseExifString: """ Define :func:`colour_hdri.utilities.exif.parse_exif_string` definition unit tests methods. @@ -64,10 +62,10 @@ def test_parse_exif_string(self): """Test :func:`colour_hdri.utilities.exif.parse_exif_string` definition.""" exif_tag = EXIFTag("EXIF", "Make", "Canon", "271") - self.assertEqual(parse_exif_string(exif_tag), "Canon") + assert parse_exif_string(exif_tag) == "Canon" -class TestParseExifNumber(unittest.TestCase): +class TestParseExifNumber: """ Define :func:`colour_hdri.utilities.exif.parse_exif_number` definition unit tests methods. @@ -77,13 +75,13 @@ def test_parse_exif_number(self): """Test :func:`colour_hdri.utilities.exif.parse_exif_number` definition.""" exif_tag = EXIFTag("EXIF", "Focal Length", "16", "37386") - self.assertEqual(parse_exif_number(exif_tag), 16) + assert parse_exif_number(exif_tag) == 16 exif_tag = EXIFTag("EXIF", "Focal Length", "16", "37386") - self.assertIsInstance(parse_exif_number(exif_tag, np.int_), np.int_) + assert isinstance(parse_exif_number(exif_tag, np.int_), np.int_) -class TestParseExifFraction(unittest.TestCase): +class TestParseExifFraction: """ Define :func:`colour_hdri.utilities.exif.parse_exif_fraction` definition unit tests methods. @@ -110,7 +108,7 @@ def test_parse_exif_fraction(self): ) -class TestParseExifArray(unittest.TestCase): +class TestParseExifArray: """ Define :func:`colour_hdri.utilities.exif.parse_exif_array` definition unit tests methods. @@ -158,7 +156,7 @@ def test_parse_exif_array(self): ) -class TestParseExifData(unittest.TestCase): +class TestParseExifData: """ Define :func:`colour_hdri.utilities.exif.parse_exif_data` definition unit tests methods. @@ -167,27 +165,20 @@ class TestParseExifData(unittest.TestCase): def test_parse_exif_data(self): """Test :func:`colour_hdri.utilities.exif.parse_exif_data` definition.""" - self.assertListEqual( - parse_exif_data("[XMP] - Description :"), - ["XMP", "-", "Description", ""], - ) + assert parse_exif_data( + "[XMP] - Description :" + ) == ["XMP", "-", "Description", ""] - self.assertListEqual( - parse_exif_data( - "[EXIF] 296 Resolution Unit : 2" - ), - ["EXIF", "296", "Resolution Unit", "2"], - ) + assert parse_exif_data( + "[EXIF] 296 Resolution Unit : 2" + ) == ["EXIF", "296", "Resolution Unit", "2"] - self.assertListEqual( - parse_exif_data( - "[ICC_Profile] 8 Profile Version : 528" - ), - ["ICC_Profile", "8", "Profile Version", "528"], - ) + assert parse_exif_data( + "[ICC_Profile] 8 Profile Version : 528" + ) == ["ICC_Profile", "8", "Profile Version", "528"] -class TestReadExifTags(unittest.TestCase): +class TestReadExifTags: """ Define :func:`colour_hdri.utilities.exif.read_exif_tags` definition unit tests methods. @@ -199,65 +190,59 @@ def test_read_exif_tags(self): test_jpg_image = filter_files(ROOT_RESOURCES_FROBISHER_001, ("jpg",))[0] exif_data = vivified_to_dict(read_exif_tags(test_jpg_image)) - self.assertIsInstance(exif_data, type({})) - - self.assertListEqual( - sorted(exif_data.keys()), - [ - "Composite", - "EXIF", - "ExifTool", - "File", - "ICC_Profile", - "JFIF", - "Photoshop", - "XMP", - ], - ) + assert isinstance(exif_data, type({})) - self.assertListEqual( - sorted(exif_data["EXIF"].values(), key=lambda x: x[0].name), + assert sorted(exif_data.keys()) == [ + "Composite", + "EXIF", + "ExifTool", + "File", + "ICC_Profile", + "JFIF", + "Photoshop", + "XMP", + ] + + assert sorted(exif_data["EXIF"].values(), key=lambda x: x[0].name) == [ + [EXIFTag("EXIF", "Camera Model Name", "EOS 5D Mark II", "272")], + [EXIFTag("EXIF", "Create Date", "2015:09:19 03:39:20", "36868")], [ - [EXIFTag("EXIF", "Camera Model Name", "EOS 5D Mark II", "272")], - [EXIFTag("EXIF", "Create Date", "2015:09:19 03:39:20", "36868")], - [ - EXIFTag( - "EXIF", - "Date/Time Original", - "2015:09:19 03:39:20", - "36867", - ) - ], - [EXIFTag("EXIF", "Exif Image Height", "426", "40963")], - [EXIFTag("EXIF", "Exif Image Width", "640", "40962")], - [EXIFTag("EXIF", "Exposure Time", "0.125", "33434")], - [EXIFTag("EXIF", "F Number", "8", "33437")], - [EXIFTag("EXIF", "Focal Length", "16", "37386")], - [EXIFTag("EXIF", "ISO", "100", "34855")], - [EXIFTag("EXIF", "Make", "Canon", "271")], - [EXIFTag("EXIF", "Modify Date", "2015:09:19 03:39:20", "306")], - [EXIFTag("EXIF", "Orientation", "1", "274")], - [EXIFTag("EXIF", "Photometric Interpretation", "2", "262")], - [EXIFTag("EXIF", "Resolution Unit", "2", "296")], - [EXIFTag("EXIF", "Software", "Photos 1.0.1", "305")], - [EXIFTag("EXIF", "X Resolution", "72", "282")], - [EXIFTag("EXIF", "Y Resolution", "72", "283")], + EXIFTag( + "EXIF", + "Date/Time Original", + "2015:09:19 03:39:20", + "36867", + ) ], - ) - - -class TestCopyExifTags(unittest.TestCase): + [EXIFTag("EXIF", "Exif Image Height", "426", "40963")], + [EXIFTag("EXIF", "Exif Image Width", "640", "40962")], + [EXIFTag("EXIF", "Exposure Time", "0.125", "33434")], + [EXIFTag("EXIF", "F Number", "8", "33437")], + [EXIFTag("EXIF", "Focal Length", "16", "37386")], + [EXIFTag("EXIF", "ISO", "100", "34855")], + [EXIFTag("EXIF", "Make", "Canon", "271")], + [EXIFTag("EXIF", "Modify Date", "2015:09:19 03:39:20", "306")], + [EXIFTag("EXIF", "Orientation", "1", "274")], + [EXIFTag("EXIF", "Photometric Interpretation", "2", "262")], + [EXIFTag("EXIF", "Resolution Unit", "2", "296")], + [EXIFTag("EXIF", "Software", "Photos 1.0.1", "305")], + [EXIFTag("EXIF", "X Resolution", "72", "282")], + [EXIFTag("EXIF", "Y Resolution", "72", "283")], + ] + + +class TestCopyExifTags: """ Define :func:`colour_hdri.utilities.exif.copy_exif_tags` definition unit tests methods. """ - def setUp(self): + def setup_method(self): """Initialise the common tests attributes.""" self._temporary_directory = tempfile.mkdtemp() - def tearDown(self): + def teardown_method(self): """After tests actions.""" shutil.rmtree(self._temporary_directory) @@ -271,25 +256,25 @@ def test_copy_exif_tags(self): ) shutil.copyfile(reference_jpg_image, test_jpg_image) - self.assertEqual(read_exif_tag(test_jpg_image, "Aperture"), "8.0") + assert read_exif_tag(test_jpg_image, "Aperture") == "8.0" delete_exif_tags(test_jpg_image) - self.assertEqual(read_exif_tag(test_jpg_image, "Aperture"), "") + assert read_exif_tag(test_jpg_image, "Aperture") == "" copy_exif_tags(reference_jpg_image, test_jpg_image) - self.assertEqual(read_exif_tag(test_jpg_image, "Aperture"), "8.0") + assert read_exif_tag(test_jpg_image, "Aperture") == "8.0" -class TestUpdateExifTags(unittest.TestCase): +class TestUpdateExifTags: """ Define :func:`colour_hdri.utilities.exif.update_exif_tags` definition unit tests methods. """ - def setUp(self): + def setup_method(self): """Initialise the common tests attributes.""" self._temporary_directory = tempfile.mkdtemp() - def tearDown(self): + def teardown_method(self): """After tests actions.""" shutil.rmtree(self._temporary_directory) @@ -306,26 +291,26 @@ def test_update_exif_tags(self): ) shutil.copyfile(reference_jpg_image, test_jpg_image) delete_exif_tags(test_jpg_image) - self.assertEqual(read_exif_tag(test_jpg_image, "Aperture"), "") + assert read_exif_tag(test_jpg_image, "Aperture") == "" test_jpg_images.append(test_jpg_image) update_exif_tags(zip(reference_jpg_images, test_jpg_images)) for test_jpg_image in test_jpg_images: - self.assertEqual(read_exif_tag(test_jpg_image, "Aperture"), "8.0") + assert read_exif_tag(test_jpg_image, "Aperture") == "8.0" -class TestDeleteExifTags(unittest.TestCase): +class TestDeleteExifTags: """ Define :func:`colour_hdri.utilities.exif.delete_exif_tags` definition unit tests methods. """ - def setUp(self): + def setup_method(self): """Initialise the common tests attributes.""" self._temporary_directory = tempfile.mkdtemp() - def tearDown(self): + def teardown_method(self): """After tests actions.""" shutil.rmtree(self._temporary_directory) @@ -339,12 +324,12 @@ def test_delete_exif_tags(self): ) shutil.copyfile(reference_jpg_image, test_jpg_image) - self.assertEqual(read_exif_tag(test_jpg_image, "Aperture"), "8.0") + assert read_exif_tag(test_jpg_image, "Aperture") == "8.0" delete_exif_tags(test_jpg_image) - self.assertEqual(read_exif_tag(test_jpg_image, "Aperture"), "") + assert read_exif_tag(test_jpg_image, "Aperture") == "" -class TestReadExifTag(unittest.TestCase): +class TestReadExifTag: """ Define :func:`colour_hdri.utilities.exif.read_exif_tag` definition unit tests methods. @@ -355,23 +340,23 @@ def test_read_exif_tag(self): test_jpg_image = filter_files(ROOT_RESOURCES_FROBISHER_001, ("jpg",))[0] - self.assertEqual(read_exif_tag(test_jpg_image, "Aperture"), "8.0") - self.assertEqual(read_exif_tag(test_jpg_image, "ExposureTime"), "1/8") - self.assertEqual(read_exif_tag(test_jpg_image, "ISO"), "100") + assert read_exif_tag(test_jpg_image, "Aperture") == "8.0" + assert read_exif_tag(test_jpg_image, "ExposureTime") == "1/8" + assert read_exif_tag(test_jpg_image, "ISO") == "100" -class TestWriteExifTag(unittest.TestCase): +class TestWriteExifTag: """ Define :func:`colour_hdri.utilities.exif.write_exif_tag` definition unit tests methods. """ - def setUp(self): + def setup_method(self): """Initialise the common tests attributes.""" self._temporary_directory = tempfile.mkdtemp() - def tearDown(self): + def teardown_method(self): """After tests actions.""" shutil.rmtree(self._temporary_directory) @@ -386,10 +371,6 @@ def test_write_exif_tag(self): shutil.copyfile(reference_jpg_image, test_jpg_image) # *Aperture* exif tag is not writeable, changing for *FNumber*. - self.assertEqual(read_exif_tag(test_jpg_image, "FNumber"), "8.0") + assert read_exif_tag(test_jpg_image, "FNumber") == "8.0" write_exif_tag(test_jpg_image, "FNumber", "16.0") - self.assertEqual(read_exif_tag(test_jpg_image, "FNumber"), "16.0") - - -if __name__ == "__main__": - unittest.main() + assert read_exif_tag(test_jpg_image, "FNumber") == "16.0" diff --git a/colour_hdri/utilities/tests/test_image.py b/colour_hdri/utilities/tests/test_image.py index 54bbb96..e55e97b 100644 --- a/colour_hdri/utilities/tests/test_image.py +++ b/colour_hdri/utilities/tests/test_image.py @@ -1,10 +1,8 @@ -# !/usr/bin/env python """Define the unit tests for the :mod:`colour_hdri.utilities.image` module.""" from __future__ import annotations import os -import unittest import numpy as np from colour.constants import TOLERANCE_ABSOLUTE_TESTS @@ -27,13 +25,13 @@ ROOT_RESOURCES_FROBISHER_001: str = os.path.join(ROOT_RESOURCES_TESTS, "frobisher_001") -class TestImage(unittest.TestCase): +class TestImage: """ Define :class:`colour_hdri.utilities.image.Image` class unit tests methods. """ - def setUp(self): + def setup_method(self): """Initialise the common tests attributes.""" self._test_jpg_image = filter_files(ROOT_RESOURCES_FROBISHER_001, ("jpg",))[0] @@ -44,7 +42,7 @@ def test_required_attributes(self): required_attributes = ("path", "data", "metadata") for attribute in required_attributes: - self.assertIn(attribute, dir(Image)) + assert attribute in dir(Image) def test_required_methods(self): """Test the presence of required methods.""" @@ -52,35 +50,35 @@ def test_required_methods(self): required_methods = ("__init__", "read_data", "read_metadata") for method in required_methods: - self.assertIn(method, dir(Image)) + assert method in dir(Image) def test_read_data(self): """Test :attr:`colour_hdri.utilities.image.Image.read_data` method.""" image = Image(self._test_jpg_image) - self.assertIsNone(image.data) - self.assertTupleEqual(image.read_data().shape, (426, 640, 3)) + assert image.data is None + assert image.read_data().shape == (426, 640, 3) def test_read_metadata(self): """Test :attr:`colour_hdri.utilities.image.Image.end` method.""" image = Image(self._test_jpg_image) - self.assertEqual(image.metadata, None) + assert image.metadata is None np.testing.assert_array_equal( np.array(image.read_metadata()), np.array([8.0, 0.125, 100.0, np.nan, np.nan, np.nan]), ) -class TestImageStack(unittest.TestCase): +class TestImageStack: """ Define :class:`colour_hdri.utilities.image.ImageStack` class unit tests methods. """ - def setUp(self): + def setup_method(self): """Initialise the common tests attributes.""" self._test_jpg_images = filter_files(ROOT_RESOURCES_FROBISHER_001, ("jpg",)) @@ -103,7 +101,7 @@ def test_required_methods(self): ) for method in required_methods: - self.assertIn(method, dir(ImageStack)) + assert method in dir(ImageStack) def test__getitem__(self): """ @@ -112,7 +110,7 @@ def test__getitem__(self): """ for image in self._image_stack: - self.assertIsInstance(image, Image) + assert isinstance(image, Image) def test__setitem__(self): """ @@ -126,7 +124,7 @@ def test__setitem__(self): image.read_metadata() image_stack.insert(0, image) - self.assertEqual(image_stack[0], image) + assert image_stack[0] == image def test__delitem__(self): """ @@ -138,12 +136,12 @@ def test__delitem__(self): del image_stack[0] - self.assertEqual(len(image_stack), 2) + assert len(image_stack) == 2 def test__len__(self): """Test :attr:`colour_hdri.utilities.image.ImageStack.__len__` method.""" - self.assertEqual(len(self._image_stack), 3) + assert len(self._image_stack) == 3 def test__getattr__(self): """ @@ -151,7 +149,7 @@ def test__getattr__(self): method. """ - self.assertTupleEqual(self._image_stack.data.shape, (426, 640, 3, 3)) + assert self._image_stack.data.shape == (426, 640, 3, 3) np.testing.assert_allclose( self._image_stack.f_number, @@ -159,7 +157,7 @@ def test__getattr__(self): atol=TOLERANCE_ABSOLUTE_TESTS, ) - self.assertEqual(self._image_stack[0].metadata.f_number, 8) + assert self._image_stack[0].metadata.f_number == 8 np.testing.assert_allclose( self._image_stack.exposure_time, @@ -167,13 +165,13 @@ def test__getattr__(self): atol=TOLERANCE_ABSOLUTE_TESTS, ) - self.assertEqual(self._image_stack[0].metadata.exposure_time, 0.125) + assert self._image_stack[0].metadata.exposure_time == 0.125 np.testing.assert_array_equal( self._image_stack.black_level, np.array([np.nan, np.nan, np.nan]) ) - self.assertEqual(self._image_stack[0].metadata.black_level, None) + assert self._image_stack[0].metadata.black_level is None def test__setattr__(self): """ @@ -183,11 +181,11 @@ def test__setattr__(self): image_stack = ImageStack().from_files(self._test_jpg_images) - self.assertTupleEqual(image_stack.data.shape, (426, 640, 3, 3)) + assert image_stack.data.shape == (426, 640, 3, 3) image_stack.data = np.random.random((20, 10, 3, 3)) - self.assertTupleEqual(image_stack.data.shape, (20, 10, 3, 3)) + assert image_stack.data.shape == (20, 10, 3, 3) np.testing.assert_allclose( image_stack.f_number, @@ -203,7 +201,7 @@ def test__setattr__(self): atol=TOLERANCE_ABSOLUTE_TESTS, ) - self.assertEqual(image_stack[0].metadata.f_number, 1) + assert image_stack[0].metadata.f_number == 1 np.testing.assert_array_equal( image_stack.black_level, np.array([np.nan, np.nan, np.nan]) @@ -217,7 +215,7 @@ def test__setattr__(self): atol=TOLERANCE_ABSOLUTE_TESTS, ) - self.assertEqual(image_stack[0].metadata.black_level, 2048) + assert image_stack[0].metadata.black_level == 2048 def test_from_files(self): """ @@ -226,8 +224,4 @@ def test_from_files(self): """ image_stack = ImageStack().from_files(reversed(self._test_jpg_images)) - self.assertListEqual(list(image_stack.path), self._test_jpg_images) - - -if __name__ == "__main__": - unittest.main() + assert list(image_stack.path) == self._test_jpg_images diff --git a/pyproject.toml b/pyproject.toml index 054dc68..bb2e7b0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -206,6 +206,7 @@ convention = "numpy" "colour_hdri/examples/*" = ["INP", "T201", "T203"] "docs/*" = ["INP"] "tasks.py" = ["INP"] +"test_*" = ["S101"] "utilities/*" = ["EXE001", "INP"] "utilities/unicode_to_ascii.py" = ["RUF001"]