afscgap.test.test_flat

Tests for entrypoint into flat implementors.

(c) 2025 Regents of University of California / The Eric and Wendy Schmidt Center for Data Science and the Environment at UC Berkeley.

This file is part of afscgap released under the BSD 3-Clause License. See LICENSE.md.

 1"""
 2Tests for entrypoint into flat implementors.
 3
 4(c) 2025 Regents of University of California / The Eric and Wendy Schmidt Center
 5for Data Science and the Environment at UC Berkeley.
 6
 7This file is part of afscgap released under the BSD 3-Clause License. See
 8LICENSE.md.
 9"""
10import unittest
11import unittest.mock
12
13import afscgap.flat
14
15
16class FlatTests(unittest.TestCase):
17
18    def setUp(self):
19        self._warn_function = unittest.mock.MagicMock()
20        self._meta = unittest.mock.MagicMock()
21        self._meta.get_warn_func = unittest.mock.MagicMock(return_value=self._warn_function)
22        self._meta.get_suppress_large_warning = unittest.mock.MagicMock(return_value=False)
23
24    def test_check_warning_warn(self):
25        afscgap.flat.check_warning(range(0, 4000), self._meta)
26        self._warn_function.assert_called()
27
28    def test_check_warning_noop(self):
29        afscgap.flat.check_warning(range(0, 10), self._meta)
30        self._warn_function.assert_not_called()
class FlatTests(unittest.case.TestCase):
17class FlatTests(unittest.TestCase):
18
19    def setUp(self):
20        self._warn_function = unittest.mock.MagicMock()
21        self._meta = unittest.mock.MagicMock()
22        self._meta.get_warn_func = unittest.mock.MagicMock(return_value=self._warn_function)
23        self._meta.get_suppress_large_warning = unittest.mock.MagicMock(return_value=False)
24
25    def test_check_warning_warn(self):
26        afscgap.flat.check_warning(range(0, 4000), self._meta)
27        self._warn_function.assert_called()
28
29    def test_check_warning_noop(self):
30        afscgap.flat.check_warning(range(0, 10), self._meta)
31        self._warn_function.assert_not_called()

A class whose instances are single test cases.

By default, the test code itself should be placed in a method named 'runTest'.

If the fixture may be used for many test cases, create as many test methods as are needed. When instantiating such a TestCase subclass, specify in the constructor arguments the name of the test method that the instance is to execute.

Test authors should subclass TestCase for their own tests. Construction and deconstruction of the test's environment ('fixture') can be implemented by overriding the 'setUp' and 'tearDown' methods respectively.

If it is necessary to override the __init__ method, the base class __init__ method must always be called. It is important that subclasses should not change the signature of their __init__ method, since instances of the classes are instantiated automatically by parts of the framework in order to be run.

When subclassing TestCase, you can set these attributes:

  • failureException: determines which exception will be raised when the instance's assertion methods fail; test methods raising this exception will be deemed to have 'failed' rather than 'errored'.
  • longMessage: determines whether long messages (including repr of objects used in assert methods) will be printed on failure in addition to any explicit message passed.
  • maxDiff: sets the maximum length of a diff in failure messages by assert methods using difflib. It is looked up as an instance attribute so can be configured by individual tests if required.
def setUp(self):
19    def setUp(self):
20        self._warn_function = unittest.mock.MagicMock()
21        self._meta = unittest.mock.MagicMock()
22        self._meta.get_warn_func = unittest.mock.MagicMock(return_value=self._warn_function)
23        self._meta.get_suppress_large_warning = unittest.mock.MagicMock(return_value=False)

Hook method for setting up the test fixture before exercising it.

def test_check_warning_warn(self):
25    def test_check_warning_warn(self):
26        afscgap.flat.check_warning(range(0, 4000), self._meta)
27        self._warn_function.assert_called()
def test_check_warning_noop(self):
29    def test_check_warning_noop(self):
30        afscgap.flat.check_warning(range(0, 10), self._meta)
31        self._warn_function.assert_not_called()