Coverage for stricto/int.py: 100%

20 statements  

« prev     ^ index     » next       coverage.py v7.4.1, created at 2024-02-08 22:10 +0100

1"""Module providing the Int() Class""" 

2from .generic import GenericType 

3from .error import Error, ErrorType 

4 

5 

6class Int(GenericType): 

7 """ 

8 A Int type 

9 """ 

10 

11 def __init__(self, **kwargs): 

12 """ 

13 available arguments 

14 

15 min : minimal value 

16 max : maximal value 

17 

18 """ 

19 self._min = kwargs.pop("min", kwargs.pop("minimum", None)) 

20 self._max = kwargs.pop("max", kwargs.pop("maximum", None)) 

21 GenericType.__init__(self, **kwargs) 

22 

23 def check_type( 

24 self, 

25 value, 

26 ): 

27 if isinstance(value, (int, Int)): 

28 return True 

29 raise Error(ErrorType.WRONGTYPE, "Must be a int", self.path_name()) 

30 

31 def check_constraints(self, value): 

32 

33 GenericType.check_constraints(self, value) 

34 

35 if self._min is not None: 

36 if value < self._min: 

37 raise Error(ErrorType.LENGTH, "Must be above Minimal", self.path_name()) 

38 if self._max is not None: 

39 if value > self._max: 

40 raise Error(ErrorType.LENGTH, "Must be below Maximal", self.path_name()) 

41 return True