Esempio n. 1
0
    def test_get_example(self):
        N = number('A float', example=1.12)
        assert 1.12 == N.get_example()

        # Default example
        N = number('Pi')
        assert 3.14 == N.get_example()
Esempio n. 2
0
 def test_exclusive_maximum(self):
     N = number('float', maximum=3.3, exclusive_maximum=True)
     # No exception
     N(3.2)
     # number is equal to maximum
     with pytest.raises(TypeSystemError, match='Must be less than 3.3.'):
         N(3.3)
Esempio n. 3
0
 def test_maximum(self):
     N = number('int', maximum=30)
     # No exception
     N(30)
     # Number > max
     with pytest.raises(TypeSystemError,
                        match='Must be less than or equal to 30'):
         N(31)
Esempio n. 4
0
 def test_minimum(self):
     N = number('float', minimum=3.22)
     # No exception
     N(3.23)
     # Number too small
     with pytest.raises(TypeSystemError,
                        match='Must be greater than or equal to 3.22'):
         N(3.21)
Esempio n. 5
0
    def test_multiple_of(self):
        N = integer('int', multiple_of=2)
        # No exception
        N(4)
        # Not multiple
        with pytest.raises(TypeSystemError, match='Must be a multiple of 2.'):
            N(5)

        # Also test with float
        N = number('float', multiple_of=1.1)
        # No exception
        N(2.2)
        # Not multiple
        with pytest.raises(TypeSystemError, match='Must be a multiple of 1.1.'):
            N(5)
Esempio n. 6
0
 def test_type(self):
     N = number('float')
     assert type(N(3.14)) is float
Esempio n. 7
0
 def test_nullable(self):
     N = number('int', nullable=True)
     assert N(None) is None
                       items=Foo,
                       parser=parse_comma_separated_str)
IsAlive = boolean('Is alive?', example=True)
ItemId = integer('item id', minimum=1, example=1, nullable=True)
Item = new_type(Object,
                description='item',
                properties={'item_id': ItemId},
                additional_properties=False,
                required=['item_id'],
                example={'item_id': 1})
IncludeDeleted = boolean('indicates if deleted items should be included.',
                         example=False)
IsDeleted = boolean('Indicates if the item should be marked as deleted',
                    example=False)
Latitude = number('The latitude.',
                  example=44.322804,
                  param_name='location.lat',
                  nullable=True)
Longitude = number('the longitude.',
                   example=-122.34232,
                   param_name='locationLon',
                   nullable=True)
Name = string('name', min_length=1, example='John')
OptIn = boolean('If the user has opted in to gps tracking.',
                param_name='opt-in')


class FooInstance(Object):
    description = 'An instance of foo.'
    properties = {
        'foo': Foo,
        'foo_id': FooId,