Ejemplo n.º 1
0
 def test_enforce_type(self):
     self.assertEqual(2, rf.exactly(2, 2, dtype=int))
     expected_message = 'Value must be of type int. float found instead.'
     with self.assertRaises(TypeError) as ex:
         rf.exactly(2.0, 2, dtype=int)
     self.assertEqual(expected_message, str(ex.exception))
     expected_message = 'HELLO must be of type int. float found instead.'
     with self.assertRaises(TypeError) as ex:
         rf.exactly(2.0, 3, name='HELLO', dtype=int)
     self.assertEqual(expected_message, str(ex.exception))
Ejemplo n.º 2
0
 def test_custom_exception_type(self):
     expected_message = 'Value must be exactly 100. ' \
                        '2 found instead.'
     with self.assertRaises(FileNotFoundError) as ex:
         rf.exactly(2, 100, ex=FileNotFoundError)
     self.assertEqual(expected_message, str(ex.exception))
     expected_message = 'HELLO must be exactly 100. ' \
                        '2 found instead.'
     with self.assertRaises(FileNotFoundError) as ex:
         rf.exactly(2, 100, name='HELLO', ex=FileNotFoundError)
     self.assertEqual(expected_message, str(ex.exception))
Ejemplo n.º 3
0
 def test_custom_value_name(self):
     expected_message = 'HELLO must be exactly NaN. ' \
                        '2 found instead.'
     with self.assertRaises(rf.RangeError) as ex:
         rf.exactly(2, math.nan, name='HELLO')
     self.assertEqual(expected_message, str(ex.exception))
     expected_message = 'HELLO must be exactly 100. ' \
                        '2 found instead.'
     with self.assertRaises(rf.RangeError) as ex:
         rf.exactly(2, 100, name='HELLO')
     self.assertEqual(expected_message, str(ex.exception))
Ejemplo n.º 4
0
 def test_everything_differs_from_nan(self):
     expected_message = 'Value must be exactly NaN. ' \
                        '2 found instead.'
     with self.assertRaises(rf.RangeError) as ex:
         rf.exactly(2, math.nan)
     self.assertEqual(expected_message, str(ex.exception))
     expected_message = 'Value must be exactly NaN. ' \
                        'inf found instead.'
     with self.assertRaises(rf.RangeError) as ex:
         rf.exactly(math.inf, math.nan)
     self.assertEqual(expected_message, str(ex.exception))
Ejemplo n.º 5
0
 def test_custom_exception_type_does_not_affect_dtype(self):
     with self.assertRaises(FileNotFoundError) as ex:
         rf.exactly(2.0, 100, dtype=float, ex=FileNotFoundError)
     with self.assertRaises(TypeError) as ex:
         rf.exactly(2.0, 100, dtype=int, ex=FileNotFoundError)
Ejemplo n.º 6
0
 def test_nan_equal_to_nan(self):
     self.assertTrue(math.isnan(rf.exactly(math.nan, math.nan)))
Ejemplo n.º 7
0
 def test_not_exact(self):
     expected_message = 'Value must be exactly 100. ' \
                        '2 found instead.'
     with self.assertRaises(rf.RangeError) as ex:
         rf.exactly(2, 100)
     self.assertEqual(expected_message, str(ex.exception))
Ejemplo n.º 8
0
 def test_exact(self):
     for i in range(-50, 50):
         self.assertEqual(i, rf.exactly(i, i))