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 70a4bc3 commit 391d16f
Show file tree
Hide file tree
Showing 23 changed files with 304 additions and 455 deletions.
13 changes: 3 additions & 10 deletions colour_datasets/loaders/tests/test_abstract.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# !/usr/bin/env python
"""Define the unit tests for the :mod:`colour_datasets.loaders.abstract` module."""

import unittest

from colour_datasets.loaders import AbstractDatasetLoader

__author__ = "Colour Developers"
Expand All @@ -17,7 +14,7 @@
]


class TestAbstractDatasetLoader(unittest.TestCase):
class TestAbstractDatasetLoader:
"""
Define :class:`colour_datasets.loaders.abstract.AbstractDatasetLoader`
class unit tests methods.
Expand All @@ -29,16 +26,12 @@ def test_required_attributes(self):
required_attributes = ("ID", "record", "id", "content")

for attribute in required_attributes:
self.assertIn(attribute, dir(AbstractDatasetLoader))
assert attribute in dir(AbstractDatasetLoader)

def test_required_methods(self):
"""Test the presence of required methods."""

required_methods = ("__init__", "load", "sync")

for method in required_methods:
self.assertIn(method, dir(AbstractDatasetLoader))


if __name__ == "__main__":
unittest.main()
assert method in dir(AbstractDatasetLoader)
42 changes: 17 additions & 25 deletions colour_datasets/loaders/tests/test_asano2015.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# !/usr/bin/env python
"""Define the unit tests for the :mod:`colour_datasets.loaders.asano2015` module."""

import unittest

import numpy as np
from colour import SpectralShape
Expand All @@ -22,7 +20,7 @@
]


class TestDatasetLoader_Asano2015(unittest.TestCase):
class TestDatasetLoader_Asano2015:
"""
Define :class:`colour_datasets.loaders.asano2015.DatasetLoader_Asano2015`
class unit tests methods.
Expand All @@ -34,15 +32,15 @@ def test_required_attributes(self):
required_attributes = ("ID",)

for attribute in required_attributes:
self.assertIn(attribute, dir(DatasetLoader_Asano2015))
assert attribute in dir(DatasetLoader_Asano2015)

def test_required_methods(self):
"""Test the presence of required methods."""

required_methods = ("__init__", "load", "parse_workbook_Asano2015")

for method in required_methods:
self.assertIn(method, dir(DatasetLoader_Asano2015))
assert method in dir(DatasetLoader_Asano2015)

def test_load(self):
"""
Expand All @@ -51,14 +49,13 @@ def test_load(self):
"""

dataset = DatasetLoader_Asano2015()
self.assertEqual(
sorted(dataset.load().keys()),
["Categorical Observers", "Colour Normal Observers"],
)
assert sorted(dataset.load().keys()) == [
"Categorical Observers",
"Colour Normal Observers",
]

self.assertEqual(
dataset.content["Categorical Observers"][1].XYZ_2.shape,
SpectralShape(390, 780, 5),
assert dataset.content["Categorical Observers"][1].XYZ_2.shape == SpectralShape(
390, 780, 5
)

np.testing.assert_allclose(
Expand Down Expand Up @@ -91,10 +88,9 @@ def test_load(self):
atol=TOLERANCE_ABSOLUTE_TESTS,
)

self.assertEqual(
dataset.content["Colour Normal Observers"][1].XYZ_2.shape,
SpectralShape(390, 780, 5),
)
assert dataset.content["Colour Normal Observers"][
1
].XYZ_2.shape == SpectralShape(390, 780, 5)

np.testing.assert_allclose(
dataset.content["Colour Normal Observers"][1].XYZ_2[390],
Expand Down Expand Up @@ -126,13 +122,13 @@ def test_load(self):
atol=TOLERANCE_ABSOLUTE_TESTS,
)

self.assertEqual(
dataset.content["Colour Normal Observers"][151].others["Location"],
"Darmstadt",
assert (
dataset.content["Colour Normal Observers"][151].others["Location"]
== "Darmstadt"
)


class TestBuildAsano2015(unittest.TestCase):
class TestBuildAsano2015:
"""
Define :func:`colour_datasets.loaders.asano2015.build_Asano2015`
definition unit tests methods.
Expand All @@ -144,8 +140,4 @@ def test_build_Asano2015(self):
definition.
"""

self.assertIs(build_Asano2015(), build_Asano2015())


if __name__ == "__main__":
unittest.main()
assert build_Asano2015() is build_Asano2015()
25 changes: 9 additions & 16 deletions colour_datasets/loaders/tests/test_brendel2020.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
module.
"""

import unittest

from colour import SpectralShape

from colour_datasets.loaders import (
Expand All @@ -25,7 +23,7 @@
]


class TestDatasetLoader_Brendel2020(unittest.TestCase):
class TestDatasetLoader_Brendel2020:
"""
Define :class:`colour_datasets.loaders.brendel2020.\
DatasetLoader_Brendel2020` class unit tests methods.
Expand All @@ -37,15 +35,15 @@ def test_required_attributes(self):
required_attributes = ("ID",)

for attribute in required_attributes:
self.assertIn(attribute, dir(DatasetLoader_Brendel2020))
assert attribute in dir(DatasetLoader_Brendel2020)

def test_required_methods(self):
"""Test the presence of required methods."""

required_methods = ("__init__", "load")

for method in required_methods:
self.assertIn(method, dir(DatasetLoader_Brendel2020))
assert method in dir(DatasetLoader_Brendel2020)

def test_load(self):
"""
Expand All @@ -55,15 +53,14 @@ def test_load(self):

dataset = DatasetLoader_Brendel2020()

self.assertEqual(len(dataset.load()), 29)
assert len(dataset.load()) == 29

self.assertEqual(
dataset.content["556nm - LED 11 - Brendel (2020)"].shape,
SpectralShape(350, 700, 2),
)
assert dataset.content[
"556nm - LED 11 - Brendel (2020)"
].shape == SpectralShape(350, 700, 2)


class TestBuildBrendel2020(unittest.TestCase):
class TestBuildBrendel2020:
"""
Define :func:`colour_datasets.loaders.brendel2020.build_Brendel2020`
definition unit tests methods.
Expand All @@ -75,8 +72,4 @@ def test_build_Brendel2020(self):
definition.
"""

self.assertIs(build_Brendel2020(), build_Brendel2020())


if __name__ == "__main__":
unittest.main()
assert build_Brendel2020() is build_Brendel2020()
26 changes: 11 additions & 15 deletions colour_datasets/loaders/tests/test_dyer2017.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# !/usr/bin/env python
"""Define the unit tests for the :mod:`colour_datasets.loaders.dyer2017` module."""

import unittest

import numpy as np
from colour.constants import TOLERANCE_ABSOLUTE_TESTS
Expand All @@ -21,7 +19,7 @@
]


class TestDatasetLoader_Dyer2017(unittest.TestCase):
class TestDatasetLoader_Dyer2017:
"""
Define :class:`colour_datasets.loaders.dyer2017.DatasetLoader_Dyer2017`
class unit tests methods.
Expand All @@ -33,15 +31,15 @@ def test_required_attributes(self):
required_attributes = ("ID",)

for attribute in required_attributes:
self.assertIn(attribute, dir(DatasetLoader_Dyer2017))
assert attribute in dir(DatasetLoader_Dyer2017)

def test_required_methods(self):
"""Test the presence of required methods."""

required_methods = ("__init__", "load")

for method in required_methods:
self.assertIn(method, dir(DatasetLoader_Dyer2017))
assert method in dir(DatasetLoader_Dyer2017)

def test_load(self):
"""
Expand All @@ -50,10 +48,12 @@ def test_load(self):
"""

dataset = DatasetLoader_Dyer2017()
self.assertListEqual(
sorted(dataset.load().keys()),
["camera", "cmf", "illuminant", "training"],
)
assert sorted(dataset.load().keys()) == [
"camera",
"cmf",
"illuminant",
"training",
]

np.testing.assert_allclose(
dataset.load()["camera"]["canon eos 5d mark ii"][555],
Expand Down Expand Up @@ -282,7 +282,7 @@ def test_load(self):
)


class TestBuildDyer2017(unittest.TestCase):
class TestBuildDyer2017:
"""
Define :func:`colour_datasets.loaders.dyer2017.build_Dyer2017`
definition unit tests methods.
Expand All @@ -294,8 +294,4 @@ def test_build_Dyer2017(self):
definition.
"""

self.assertIs(build_Dyer2017(), build_Dyer2017())


if __name__ == "__main__":
unittest.main()
assert build_Dyer2017() is build_Dyer2017()
60 changes: 24 additions & 36 deletions colour_datasets/loaders/tests/test_ebner1998.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# !/usr/bin/env python
"""Define the unit tests for the :mod:`colour_datasets.loaders.ebner1998` module."""

import unittest

import numpy as np
from colour.constants import TOLERANCE_ABSOLUTE_TESTS

Expand All @@ -21,7 +18,7 @@
]


class TestDatasetLoader_Ebner1998(unittest.TestCase):
class TestDatasetLoader_Ebner1998:
"""
Define :class:`colour_datasets.loaders.ebner1998.DatasetLoader_Ebner1998`
class unit tests methods.
Expand All @@ -33,15 +30,15 @@ def test_required_attributes(self):
required_attributes = ("ID",)

for attribute in required_attributes:
self.assertIn(attribute, dir(DatasetLoader_Ebner1998))
assert attribute in dir(DatasetLoader_Ebner1998)

def test_required_methods(self):
"""Test the presence of required methods."""

required_methods = ("__init__", "load")

for method in required_methods:
self.assertIn(method, dir(DatasetLoader_Ebner1998))
assert method in dir(DatasetLoader_Ebner1998)

def test_load(self):
"""
Expand All @@ -50,30 +47,25 @@ def test_load(self):
"""

dataset = DatasetLoader_Ebner1998()
self.assertListEqual(
sorted(dataset.load().keys()), ["Constant Perceived-Hue Data"]
)

self.assertListEqual(
sorted(dataset.load()["Constant Perceived-Hue Data"].keys()),
[
0,
24,
48,
72,
96,
120,
144,
168,
192,
216,
240,
264,
288,
312,
336,
],
)
assert sorted(dataset.load().keys()) == ["Constant Perceived-Hue Data"]

assert sorted(dataset.load()["Constant Perceived-Hue Data"].keys()) == [
0,
24,
48,
72,
96,
120,
144,
168,
192,
216,
240,
264,
288,
312,
336,
]

np.testing.assert_allclose(
dataset.load()["Constant Perceived-Hue Data"][96].XYZ_r,
Expand Down Expand Up @@ -127,7 +119,7 @@ def test_load(self):
)


class TestBuildEbner1998(unittest.TestCase):
class TestBuildEbner1998:
"""
Define :func:`colour_datasets.loaders.ebner1998.build_Ebner1998`
definition unit tests methods.
Expand All @@ -139,8 +131,4 @@ def test_build_Ebner1998(self):
definition.
"""

self.assertIs(build_Ebner1998(), build_Ebner1998())


if __name__ == "__main__":
unittest.main()
assert build_Ebner1998() is build_Ebner1998()
Loading

0 comments on commit 391d16f

Please sign in to comment.