Example #1
0
class Example(Structure):
    i = Integer(maximum=10)
    s = String(maxLength=5)
    array = Array[Integer(multiplesOf=5), Number]
    embedded = StructureReference(a1=Integer(), a2=Float())
    simplestruct = SimpleStruct
    all = AllOf[Number, Integer]
    enum = Enum(values=[1, 2, 3])
Example #2
0
class Example(Structure):
    i = Integer(maximum=10)
    s = String(maxLength=5)
    a = Array[Integer(multiplesOf=5), Number]
    foo = StructureReference(a1=Integer(), a2=Float())
    ss = SimpleStruct
    all = AllOf[Number, Integer]
    any = AnyOf[Number(minimum=1), Integer]
    one = OneOf[Number(minimum=1), Integer]
    no = NotField(fields=[String])
    enum = Enum(values=[1, 2, 3])
Example #3
0
class Example(Structure):
    anything = Anything
    i = Integer(maximum=10)
    s = String(maxLength=5)
    any = AnyOf[Array[Person], Person]
    complex_allof = AllOf[
        AnyOf[Integer,
              Person], BigPerson]  # this is stupid, but we do it for testing
    people = Array[Person]
    array_of_one_of = Array[OneOf[
        Float, Integer, Person,
        StructureReference(a1=Integer(), a2=Float())]]
    array = Array[Integer(multiplesOf=5), OneOf[Array[Person], Number]]
    embedded = StructureReference(a1=Integer(), a2=Float())
    simplestruct = SimpleStruct
    all = AllOf[Number, Integer]
    enum = Enum(values=[1, 2, 3])
    _required = []
Example #4
0
class Person(Structure):
    _required = ['ssid']
    name = String(pattern='[A-Za-z]+$', maxLength=8)
    ssid = String(minLength=3, pattern='[A-Za-z]+$')
    num = Integer(maximum=30,
                  minimum=10,
                  multiplesOf="dd",
                  exclusiveMaximum=False)
    foo = StructureReference(a=String(),
                             b=StructureReference(c=Number(minimum=10),
                                                  d=Number(maximum=10)))
Example #5
0
class Example(Structure):
    _additionalProperties = True
    _required = []
    a = AllOf(
        [Number(multiplesOf=5, maximum=20, minimum=-10), Integer, Positive])
    # Can also omit the parens
    b = AnyOf[Number(maximum=20, minimum=-10), Integer(), Positive, String]
    c = OneOf([
        Number(multiplesOf=5, maximum=20, minimum=-10), Integer, Positive,
        String
    ])
    d = NotField([Number(multiplesOf=5, maximum=20, minimum=-10), String])
    e = AllOf([])
    broken = AllOf[String, Integer]
    f = NotField[Number]
    g = AnyOf[Foo, Integer]
Example #6
0
 class Foo(Structure):
     a = Array(items=Integer())
Example #7
0
 class A(Structure):
     i = Integer()
Example #8
0
 class Foo(Structure):
     a = Integer
     b = Array[NotField[String(maxLength=3), Integer(minimum=4)]]
Example #9
0
 class Blah(Structure):
     x = Integer(default=5)
     y = Integer
     _required = []
     _ignore_none = True
Example #10
0
class MixedTypesExample(Structure):
    i: Integer(maximum=10)
    s: String(maxLength=5)
    s1: str
    a: dict
    simple: SimpleStruct
Example #11
0
 class ExampleWithTyping(Structure):
     mylist: List[List[int]]
     i: Integer(minimum=50)
     myset: FrozenSet
Example #12
0
 class Example(Structure):
     f: Float() = 0.5
     map: dict
     arr: Array[SimpleStruct] = [SimpleStruct(name="John")]
     i = Integer(default=5)
     _required = ['arr', i]
Example #13
0
class B(Structure):
    e = Integer(minimum=0, maximum=10, exclusiveMaximum=True)
Example #14
0
def test_invalid_defaults_raise_error2():
    with pytest.raises(ValueError) as excinfo:
        Integer(minimum=5, default=2)
Example #15
0
 class Foo(Structure):
     i = Integer(default="x")
 def func() -> Field:
     return Integer(minimum=10)