Exemplo n.º 1
0
 def test_boolean_parser_returns_false(self):
     """
     Tests that the boolean parser returns false for string values
     that say 'false'.
     """
     self.assertFalse(FieldValueParsers.boolean_parser('false'))
     self.assertFalse(FieldValueParsers.boolean_parser('FALSE'))
Exemplo n.º 2
0
 def test_boolean_parser_returns_true(self):
     """
     Tests that the boolean parser returns true for string values that
     say 'true'
     """
     self.assertTrue(FieldValueParsers.boolean_parser('true'))
     self.assertTrue(FieldValueParsers.boolean_parser('TRUE'))
Exemplo n.º 3
0
    def test_int_parser_raises_error(self):
        """
        Tests that the integer parser raises a FieldValueParsingError
        with the correct message if the given string is not an integer.
        """
        with self.assertRaises(FieldValueParsingError) as error:
            FieldValueParsers.int_parser('meh')

        self.assertEqual(
            str(error.exception),
            FieldValueParsers.INVALID_INTEGER_VALUE.format('meh'),
        )
Exemplo n.º 4
0
    def test_float_parser_raises_error(self):
        """
        Tests that the float parser raises a FieldValueParsingError
        with a INVALID_FLOAT_VALUE message if the given string is not
        a float.
        """
        with self.assertRaises(FieldValueParsingError) as error:
            FieldValueParsers.float_parser('meh')

        self.assertEqual(
            str(error.exception),
            FieldValueParsers.INVALID_FLOAT_VALUE.format('meh'),
        )
Exemplo n.º 5
0
    def test_boolean_parser_raises_error(self):
        """
        Tests that the boolean parser raises a FieldValueParsingError
        with an INVALID_BOOLEAN_CHOICE message if the given value is
        not 'true' or 'false'
        """
        with self.assertRaises(FieldValueParsingError) as error:
            FieldValueParsers.boolean_parser('blah')

        self.assertEqual(
            str(error.exception),
            FieldValueParsers.INVALID_BOOLEAN_CHOICE,
        )
Exemplo n.º 6
0
 def test_int_parser_returns_int(self):
     """
     Tests that the integer parser parses an integer from a string.
     """
     self.assertEqual(FieldValueParsers.int_parser('4'), 4)
Exemplo n.º 7
0
 def test_text_parser_returns(self):
     """
     Tests that the text parser simply returns the given value.
     """
     self.assertEqual(FieldValueParsers.text_parser('meh'), 'meh')
Exemplo n.º 8
0
 def test_float_parser_returns_float(self):
     """
     Tests that the float parser parses a float.
     """
     self.assertEqual(FieldValueParsers.float_parser('4.5'), 4.5)