Coverage for lib/lottie/parsers/sif/sif/frame_time.py: 61%

32 statements  

« prev     ^ index     » next       coverage.py v7.2.2, created at 2023-03-20 16:17 +0100

1import enum 

2 

3 

4class FrameTime: 

5 class Unit(enum.Enum): 

6 Frame = "f" 

7 Seconds = "s" 

8 

9 def __init__(self, value, unit): 

10 self.value = value 

11 self.unit = unit 

12 

13 def __eq__(self, other): 

14 return self.value == other.value and self.unit == other.unit 

15 

16 def __ne__(self, other): 

17 return self.value == other.value and self.unit == other.unit 

18 

19 def __str__(self): 

20 return "%s%s" % (self.value, self.unit.value) 

21 

22 def __repr__(self): 

23 return "<%s %s>" % (self.__class__.__name__, self) 

24 

25 @classmethod 

26 def frame(cls, amount): 

27 return cls(amount, cls.Unit.Frame) 

28 

29 @classmethod 

30 def seconds(cls, amount): 

31 return cls(amount, cls.Unit.Seconds) 

32 

33 @classmethod 

34 def parse_string(cls, value_str, canvas): 

35 if " " in value_str: 35 ↛ 36line 35 didn't jump to line 36, because the condition on line 35 was never true

36 value = 0 

37 unit = cls.Unit.Frame 

38 for sub in value_str.split(): 

39 sv = float(sub[:-1]) 

40 if sub[-1] == "s": 

41 sv *= canvas.fps 

42 value += sv 

43 else: 

44 value = float(value_str[:-1]) 

45 unit = cls.Unit(value_str[-1]) 

46 return FrameTime(value, unit)