Exemplo n.º 1
0
 def test_cast_as(self):
     kwargs = {"message": "",
               "cast_as": IntVar,
               "number_of_retries": -1,
               "error_message": "",
               "valid_input": [],
               "raise_on_invalid": False}
     with mock.patch('reusables.sanitizers._get_input', return_value=1):
         self.assertRaises(TestException,
                           reusables.sanitized_input, **kwargs)
     with mock.patch('reusables.sanitizers._get_input', return_value='1'):
         assert isinstance(reusables.sanitized_input(cast_as=IntVar), IntVar), "Success"
         assert not isinstance(reusables.sanitized_input(cast_as=IntVar), int), "Failure"
Exemplo n.º 2
0
 def test_cast_int(self):
     kwargs = {"message": "",
               "cast_as": int,
               "number_of_retries": -1,
               "error_message": "",
               "valid_input": [],
               "raise_on_invalid": False}
     with mock.patch('reusables.sanitizers._get_input', return_value="32"):
         self.assertEqual(32, reusables.sanitized_input(**kwargs))
Exemplo n.º 3
0
 def test_chain_cast(self):
     kwargs = {"message": "",
               "cast_as": "int, float",
               "number_of_retries": -1,
               "error_message": "",
               "valid_input": [],
               "raise_on_invalid": False}
     with mock.patch('reusables.sanitizers._get_input', return_value="3.2"):
         assert isinstance(reusables.sanitized_input(cast_as=[int, float]), int)
         self.assertRaises(ValueError, reusables.sanitized_input, **kwargs)
Exemplo n.º 4
0
 def test_cast_successful(self):
     with mock.patch('reusables.sanitizers._get_input', return_value='1'):
         assert isinstance(reusables.sanitized_input(cast_as=int), int), 'Success'
         assert not isinstance(reusables.sanitized_input(cast_as=str), int), 'Failure'
         assert isinstance(reusables.sanitized_input(cast_as=str), str), 'Success'