def test_validate_function_catches_value_errors_and_raises_invalid(self):
     func = Mock(side_effect=ValueError)
     with self.assertRaises(Invalid) as cm:
         Schema._validate_function(func, "abc", [])
     self.assertEqual(str(cm.exception), "Invalid value given")
     self.assertEqual(cm.exception.data, "abc")
     with self.assertRaises(Invalid) as cm:
         Schema._validate_function(func, "def", ["a"])
     self.assertEqual(str(cm.exception), "Invalid value given @ data[a]")
     self.assertEqual(cm.exception.data, "def")
예제 #2
0
 def test_validate_function_catches_value_errors_and_raises_invalid(self):
     func = Mock(side_effect=ValueError)
     with self.assertRaises(Invalid) as cm:
         Schema._validate_function(func, "abc", [])
     self.assertEqual(str(cm.exception), "Invalid value given")
     self.assertEqual(cm.exception.data, "abc")
     with self.assertRaises(Invalid) as cm:
         Schema._validate_function(func, "def", ["a"])
     self.assertEqual(str(cm.exception), "Invalid value given @ data[a]")
     self.assertEqual(cm.exception.data, "def")
 def test_validate_function_catches_and_raises_invalid(self):
     invalid = Invalid("abc", 4)
     func = Mock(side_effect=invalid)
     with self.assertRaises(Invalid) as cm:
         Schema._validate_function(func, 2, [])
     self.assertEqual(str(cm.exception), "abc")
     self.assertEqual(cm.exception.data, 4)
     with self.assertRaises(Invalid) as cm:
         Schema._validate_function(func, 3, [1, "a"])
     self.assertEqual(str(cm.exception), "abc @ data[1][a]")
     self.assertEqual(cm.exception.data, 4)
예제 #4
0
 def test_validate_function_catches_and_raises_invalid(self):
     invalid = Invalid("abc", 4)
     func = Mock(side_effect=invalid)
     with self.assertRaises(Invalid) as cm:
         Schema._validate_function(func, 2, [])
     self.assertEqual(str(cm.exception), "abc")
     self.assertEqual(cm.exception.data, 4)
     with self.assertRaises(Invalid) as cm:
         Schema._validate_function(func, 3, [1, "a"])
     self.assertEqual(str(cm.exception), "abc @ data[1][a]")
     self.assertEqual(cm.exception.data, 4)
 def test_validate_function_catches_and_raises_invalid_group(self):
     invalid_group = InvalidGroup(
         "", [Invalid("abc", 8), Invalid("def", 9, [3])], 4)
     func = Mock(side_effect=invalid_group)
     with self.assertRaises(InvalidGroup) as cm:
         Schema._validate_function(func, 2, [])
     ex = cm.exception
     self.assertEqual(map(str, ex.errors), ["abc", "def @ data[3]"])
     self.assertEqual([e.data for e in ex.errors], [8, 9])
     self.assertEqual(ex.data, 4)
     with self.assertRaises(InvalidGroup) as cm:
         Schema._validate_function(func, 3, [1, "a"])
     ex = cm.exception
     self.assertEqual(
         map(str, ex.errors), ["abc @ data[1][a]", "def @ data[1][a][3]"])
     self.assertEqual([e.data for e in ex.errors], [8, 9])
     self.assertEqual(ex.data, 4)
예제 #6
0
 def test_validate_function_catches_and_raises_invalid_group(self):
     invalid_group = InvalidGroup(
         "", [Invalid("abc", 8), Invalid("def", 9, [3])], 4)
     func = Mock(side_effect=invalid_group)
     with self.assertRaises(InvalidGroup) as cm:
         Schema._validate_function(func, 2, [])
     ex = cm.exception
     self.assertEqual(map(str, ex.errors), ["abc", "def @ data[3]"])
     self.assertEqual([e.data for e in ex.errors], [8, 9])
     self.assertEqual(ex.data, 4)
     with self.assertRaises(InvalidGroup) as cm:
         Schema._validate_function(func, 3, [1, "a"])
     ex = cm.exception
     self.assertEqual(map(str, ex.errors),
                      ["abc @ data[1][a]", "def @ data[1][a][3]"])
     self.assertEqual([e.data for e in ex.errors], [8, 9])
     self.assertEqual(ex.data, 4)
 def test_validate_function_returns_the_value_from_the_function(self):
     func = Mock(return_value=1)
     self.assertEqual(Schema._validate_function(func, "abc", []), 1)
 def test_validate_function_calls_the_function(self):
     func = Mock()
     Schema._validate_function(func, "abc", [])
     func.assert_called_once_with("abc")
예제 #9
0
 def test_validate_function_returns_the_value_from_the_function(self):
     func = Mock(return_value=1)
     self.assertEqual(Schema._validate_function(func, "abc", []), 1)
예제 #10
0
 def test_validate_function_calls_the_function(self):
     func = Mock()
     Schema._validate_function(func, "abc", [])
     func.assert_called_once_with("abc")