summaryrefslogtreecommitdiff
path: root/silx/utils/test
diff options
context:
space:
mode:
authorPicca Frédéric-Emmanuel <picca@synchrotron-soleil.fr>2019-12-23 13:45:09 +0100
committerPicca Frédéric-Emmanuel <picca@synchrotron-soleil.fr>2019-12-23 13:45:09 +0100
commit7ee2fd39b83af94e061ade2a2dac2a6918ac0a07 (patch)
tree720c4f64d9d7b6260f1979f0f4ff188a0b379f1f /silx/utils/test
parent6f3cf570afab1005f81793c83b7ba5766c7c5bab (diff)
parent5d647cf9a6159afd2933da594b9c79ad93d3cd9b (diff)
Update upstream source from tag 'upstream/0.12.0_b0+dfsg'
Update to upstream version '0.12.0~b0+dfsg' with Debian dir 92f448758e24d5e4b53a9474665fea15b0286295
Diffstat (limited to 'silx/utils/test')
-rwxr-xr-x[-rw-r--r--]silx/utils/test/__init__.py2
-rw-r--r--silx/utils/test/test_number.py4
-rwxr-xr-xsilx/utils/test/test_testutils.py96
3 files changed, 102 insertions, 0 deletions
diff --git a/silx/utils/test/__init__.py b/silx/utils/test/__init__.py
index 029523c..252bc05 100644..100755
--- a/silx/utils/test/__init__.py
+++ b/silx/utils/test/__init__.py
@@ -38,6 +38,7 @@ from . import test_debug
from . import test_number
from . import test_external_resources
from . import test_enum
+from . import test_testutils
def suite():
@@ -52,4 +53,5 @@ def suite():
test_suite.addTest(test_number.suite())
test_suite.addTest(test_external_resources.suite())
test_suite.addTest(test_enum.suite())
+ test_suite.addTest(test_testutils.suite())
return test_suite
diff --git a/silx/utils/test/test_number.py b/silx/utils/test/test_number.py
index e4f6bd8..4ac9636 100644
--- a/silx/utils/test/test_number.py
+++ b/silx/utils/test/test_number.py
@@ -101,6 +101,10 @@ class TestConversionTypes(testutils.ParametricTestCase):
dtype = number.min_numerical_convertible_type("1.50")
self.assertEqual(dtype, numpy.float16)
+ def testFloat32(self):
+ dtype = number.min_numerical_convertible_type("-23.172")
+ self.assertEqual(dtype, numpy.float32)
+
def testMantissa32(self):
dtype = number.min_numerical_convertible_type("1400.50")
self.assertEqual(dtype, numpy.float32)
diff --git a/silx/utils/test/test_testutils.py b/silx/utils/test/test_testutils.py
new file mode 100755
index 0000000..c29a703
--- /dev/null
+++ b/silx/utils/test/test_testutils.py
@@ -0,0 +1,96 @@
+# coding: utf-8
+# /*##########################################################################
+#
+# Copyright (c) 2016 European Synchrotron Radiation Facility
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#
+# ###########################################################################*/
+"""Tests for testutils module"""
+
+__authors__ = ["V. Valls"]
+__license__ = "MIT"
+__date__ = "18/11/2019"
+
+
+import unittest
+import logging
+from .. import testutils
+
+
+class TestTestLogging(unittest.TestCase):
+ """Tests for TestLogging."""
+
+ def testRight(self):
+ logger = logging.getLogger(__name__ + "testRight")
+ listener = testutils.TestLogging(logger, error=1)
+ with listener:
+ logger.error("expected")
+ logger.info("ignored")
+
+ def testCustomLevel(self):
+ logger = logging.getLogger(__name__ + "testCustomLevel")
+ listener = testutils.TestLogging(logger, error=1)
+ with listener:
+ logger.error("expected")
+ logger.log(666, "custom level have to be ignored")
+
+ def testWrong(self):
+ logger = logging.getLogger(__name__ + "testWrong")
+ listener = testutils.TestLogging(logger, error=1)
+ with self.assertRaises(RuntimeError):
+ with listener:
+ logger.error("expected")
+ logger.error("not expected")
+
+ def testManyErrors(self):
+ logger = logging.getLogger(__name__ + "testManyErrors")
+ listener = testutils.TestLogging(logger, error=1, warning=2)
+ with self.assertRaises(RuntimeError):
+ with listener:
+ pass
+
+ def testCanBeChecked(self):
+ logger = logging.getLogger(__name__ + "testCanBreak")
+ listener = testutils.TestLogging(logger, error=1, warning=2)
+ with self.assertRaises(RuntimeError):
+ with listener:
+ logger.error("aaa")
+ logger.warning("aaa")
+ self.assertFalse(listener.can_be_checked())
+ logger.error("aaa")
+ # Here we know that it's already wrong without a big cost
+ self.assertTrue(listener.can_be_checked())
+
+ def testWithAs(self):
+ logger = logging.getLogger(__name__ + "testCanBreak")
+ with testutils.TestLogging(logger) as listener:
+ logger.error("aaa")
+ self.assertIsNotNone(listener)
+
+
+def suite():
+ loadTests = unittest.defaultTestLoader.loadTestsFromTestCase
+ test_suite = unittest.TestSuite()
+ test_suite.addTest(loadTests(TestTestLogging))
+ return test_suite
+
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='suite')