Coverage for src/rok4_tools/tmsizer_utils/processors/processor.py: 88%

17 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-11-06 17:15 +0000

1"""Provide abstract class to define a unit processing data for tmsizer tool. 

2 

3The module contains the following classes: 

4 

5- `Processor` - Abstract class for all kinds of processor 

6""" 

7 

8from typing import Dict, List, Tuple, Union, Iterator 

9 

10from rok4.tile_matrix_set import TileMatrixSet 

11 

12class Processor: 

13 """Abstract class for a processor 

14 

15 A processor is a unit which treat data, item by item, and generate other items. An item could be a string, a tuple...  

16  

17 The output format define what the processor generate. 

18 

19 Attributes: 

20 _processed (int): Count of input item processed 

21 _format (str): Processor's output items' format 

22 """ 

23 

24 tms = None 

25 """tms (TileMatrixSet): Pivot TMS for all processors""" 

26 

27 def __init__(self, format: str = "UNKNOWN") -> None: 

28 """Constructor method 

29 

30 Set the output format and the processed count to 0. 

31 

32 Args: 

33 format (str, optional): Processor's output items' format. Defaults to "UNKNOWN". 

34 """ 

35 self._processed = 0 

36 self._format = format 

37 

38 def process(self) -> Iterator: 

39 """Abstract method for the processor's treatment function, as stream 

40 

41 Raises: 

42 NotImplementedError: Subclasses have to implement this function 

43 """ 

44 raise NotImplementedError("Subclasses have to implement this function") 

45 

46 @classmethod 

47 def set_tms(cls, tms: TileMatrixSet): 

48 """Set the pivot TMS for all processors 

49 

50 Args: 

51 tms (TileMatrixSet): Pivot TMS for processings 

52 """ 

53 cls.tms = tms 

54 

55 @property 

56 def format(self) -> str: 

57 """Get the output format 

58 

59 Returns: 

60 str: Processor's output items' format 

61 """ 

62 return self._format 

63 

64 def __str__(self) -> str: 

65 return f"Processor : abstract class, only instance of subclasses can be used to treat data"