def test_when_base_returns_invalid_when_passed_an_invalid_instance(self):
     val = _when_base(None, Invalid("abc"))
     self.assertTrue(isinstance(val, Invalid))
     self.assertEqual(str(val), "abc")
     val = _when_base(None, InvalidGroup("", [Invalid("a"), Invalid("b")]))
     self.assertTrue(isinstance(val, InvalidGroup))
     self.assertEqual(str(val), "a\nb")
 def test_when_base_returns_function_value_when_passed_a_function(self):
     mocked = Mock(return_value=8)
     self.assertEqual(_when_base(None, mocked), 8)
     mocked.assert_called_once_with(None)
     mocked.reset_mock()
     self.assertEqual(_when_base("abc", mocked), 8)
     mocked.assert_called_once_with("abc")
Example #3
0
 def test_when_base_returns_function_value_when_passed_a_function(self):
     mocked = Mock(return_value=8)
     self.assertEqual(_when_base(None, mocked), 8)
     mocked.assert_called_once_with(None)
     mocked.reset_mock()
     self.assertEqual(_when_base("abc", mocked), 8)
     mocked.assert_called_once_with("abc")
Example #4
0
 def test_when_base_returns_invalid_when_passed_an_invalid_instance(self):
     val = _when_base(None, Invalid("abc"))
     self.assertTrue(isinstance(val, Invalid))
     self.assertEqual(str(val), "abc")
     val = _when_base(None, InvalidGroup("", [Invalid("a"), Invalid("b")]))
     self.assertTrue(isinstance(val, InvalidGroup))
     self.assertEqual(str(val), "a\nb")
 def test_when_base_returns_value_when_passed_a_standard_value(self):
     self.assertEqual(_when_base("abc", "def"), "def")
     self.assertEqual(_when_base(0, None), None)
 def test_when_base_returns_invalid_when_passed_the_invalid_class(self):
     val = _when_base(None, Invalid)
     self.assertTrue(isinstance(val, Invalid))
     self.assertEqual(str(val), "A value is required")
Example #7
0
 def test_when_base_returns_value_when_passed_a_standard_value(self):
     self.assertEqual(_when_base("abc", "def"), "def")
     self.assertEqual(_when_base(0, None), None)
Example #8
0
 def test_when_base_returns_invalid_when_passed_the_invalid_class(self):
     val = _when_base(None, Invalid)
     self.assertTrue(isinstance(val, Invalid))
     self.assertEqual(str(val), "A value is required")