def test_custom_value_name(self): expected_message = 'Length of HELLO must be exactly 1. ' \ '2 found instead.' with self.assertRaises(rf.RangeError) as ex: rf.exact_len([2] * 2, 1, 'HELLO') self.assertEqual(expected_message, str(ex.exception)) expected_message = 'Length of HELLO WORLD must be exactly 5. ' \ '2 found instead.' with self.assertRaises(rf.RangeError) as ex: rf.exact_len([2] * 2, 5, 'HELLO WORLD') self.assertEqual(expected_message, str(ex.exception))
def test_custom_exception_type(self): expected_message = 'Length of value must be exactly 100. ' \ '1 found instead.' with self.assertRaises(FileNotFoundError) as ex: rf.exact_len([2], 100, ex=FileNotFoundError) self.assertEqual(expected_message, str(ex.exception)) expected_message = 'Length of HELLO must be exactly 100. ' \ '1 found instead.' with self.assertRaises(FileNotFoundError) as ex: rf.exact_len([2], 100, name='HELLO', ex=FileNotFoundError) self.assertEqual(expected_message, str(ex.exception))
def test_expected_length_must_be_int(self): expected_message = 'Expected length must be an integer. ' \ 'NoneType found instead.' with self.assertRaises(TypeError) as ex: rf.exact_len([2] * 2, None) self.assertEqual(expected_message, str(ex.exception)) expected_message = 'Expected length must be an integer. ' \ 'float found instead.' with self.assertRaises(TypeError) as ex: rf.exact_len([2] * 2, 2.0) self.assertEqual(expected_message, str(ex.exception)) expected_message = 'Expected length must be an integer. ' \ 'float found instead.' with self.assertRaises(TypeError) as ex: rf.exact_len([2] * 2, float('+inf')) self.assertEqual(expected_message, str(ex.exception)) expected_message = 'Expected length must be an integer. ' \ 'float found instead.' with self.assertRaises(TypeError) as ex: rf.exact_len([2] * 2, float('nan')) self.assertEqual(expected_message, str(ex.exception))
def test_negative_expected_length(self): expected_message = 'Expected length must be non-negative. ' \ '-2 found instead.' with self.assertRaises(ValueError) as ex: rf.exact_len([2] * 2, -2) self.assertEqual(expected_message, str(ex.exception))
def test_greater_length(self): expected_message = 'Length of value must be exactly 3. ' \ '5 found instead.' with self.assertRaises(rf.RangeError) as ex: rf.exact_len([2] * 5, 3) self.assertEqual(expected_message, str(ex.exception))
def test_zero_length(self): self.assertEqual([], rf.exact_len([], 0))
def test_proper_length(self): self.assertEqual([2] * 2, rf.exact_len([2] * 2, 2))