예제 #1
0
 def test_convert_to_int(self):
     self.assertIsNone(Argument.convert(conversion_type='int'))
     int_convert_attempts = ((6, 6), (4.5, 4), ('6', 6), ('4.5', '4.5'))
     for int_type, expected in int_convert_attempts:
         self.assertEqual(
             Argument.convert(value=int_type, conversion_type='int'),
             expected)
예제 #2
0
 def test_convert_to_string(self):
     self.assertEqual(Argument.convert(), 'None')
     string_types = ['str', 'string', 'unicode']
     string_converted_attempts = (6, 'a', None, 4.56, {6: "this_string"}, ['a', 'b'])
     for string_type in string_types:
         self.assertEqual(Argument.convert(conversion_type=string_type), 'None')
     for string_type in string_types:
         for attempt in string_converted_attempts:
             self.assertEqual(Argument.convert(value=attempt, conversion_type=string_type), str(attempt))
예제 #3
0
 def test_convert_to_unspecified_type(self):
     unknown_types = ['list', 'dict', 'float', 'tuple', 'set', 'junk']
     attempts = (6, 'a', None, 4.56, {6: "this_string"}, ['a', 'b'])
     for input_type in unknown_types:
         for attempt in attempts:
             self.assertEqual(
                 Argument.convert(value=attempt,
                                  conversion_type=input_type), attempt)