Esempio n. 1
0
 def test_max_decimal_places__good(self, value, places, digits):
     f = DecimalField(
         max_decimal_places=places,
         max_digits=digits,
         coerce=True,
         field='foo',
     )
     d: Decimal = f.prepare_value(value)
     for error in f.validate(d):
         raise error
Esempio n. 2
0
    class Faust(Record, avro_name="net.mastery.Faust"):
        """My docstring"""

        # Primitive types
        boolean: bool
        integer: int32
        longint: int
        floating_pt: float32
        double: float
        byte_string: bytes
        text_string: str
        # Complex types
        color: Colors
        words: List[str]
        counts: Dict[str, int]
        numeric: Union[int, float]
        # Logical Types
        many_digits: Decimal
        usd: Decimal = DecimalField(max_digits=20, max_decimal_places=2)
        calendar_date: date
        daily_time: time
        daily_time_millis: time_millis
        timestamp: datetime
        timestamp_millis: datetime_millis
        uuid: UUID
        # Pythonic types
        optional: Optional[str]  # Faust auto-defaults this to None.
        default: str = "a default"
        # Nested
        nested: Optional[Nested] = None
        # Recursive
        recursive: Optional["Faust"] = None
Esempio n. 3
0
    def test_init_options(self):
        assert DecimalField(max_digits=3).max_digits == 3
        assert DecimalField(max_decimal_places=4).max_decimal_places == 4

        f = DecimalField(max_digits=3, max_decimal_places=4)
        f2 = f.clone()
        assert f2.max_digits == 3
        assert f2.max_decimal_places == 4

        f3 = DecimalField()
        assert f3.max_digits is None
        assert f3.max_decimal_places is None
        f4 = f3.clone()
        assert f4.max_digits is None
        assert f4.max_decimal_places is None
Esempio n. 4
0
 class X(Record, validation=True):
     foo: Decimal = DecimalField(max_digits=3)
Esempio n. 5
0
 class Order(Record, validation=True):
     price: Decimal = DecimalField()
     quantity: int = IntegerField()
     side: str = StringField()
     foo: float = FloatField(required=False, default=3.33)
Esempio n. 6
0
 def field(self):
     return DecimalField(model=X, field='foo')
Esempio n. 7
0
 def test_max_digits__bad(self, value):
     f = DecimalField(max_digits=4, coerce=True, field='foo')
     with pytest.raises(ValidationError):
         raise next(f.validate(value))
Esempio n. 8
0
 def test_infinite(self, value):
     f = DecimalField(coerce=True, field='foo')
     with pytest.raises(ValidationError):
         raise next(f.validate(value))
Esempio n. 9
0
 def test_max_decimal_places__bad(self, value):
     f = DecimalField(max_decimal_places=4, coerce=True, field="foo")
     with pytest.raises(ValidationError):
         raise next(f.validate(value))