Coverage for kwai/modules/training/trainings/training_definition_repository.py: 100%

6 statements  

« prev     ^ index     » next       coverage.py v7.3.0, created at 2023-09-05 17:55 +0000

1"""Module that defines an interface for a training definition repository.""" 

2 

3from abc import ABC, abstractmethod 

4from typing import AsyncIterator 

5 

6from kwai.modules.training.trainings.training_definition import ( 

7 TrainingDefinitionEntity, 

8 TrainingDefinitionIdentifier, 

9) 

10from kwai.modules.training.trainings.training_definition_query import ( 

11 TrainingDefinitionQuery, 

12) 

13 

14 

15class TrainingDefinitionNotFoundException(Exception): 

16 """Raised when a training definition can not be found.""" 

17 

18 

19class TrainingDefinitionRepository(ABC): 

20 """A training definition repository.""" 

21 

22 @abstractmethod 

23 def create_query(self) -> TrainingDefinitionQuery: 

24 """Create a query for querying training definitions.""" 

25 raise NotImplementedError 

26 

27 @abstractmethod 

28 async def get_by_id( 

29 self, id_: TrainingDefinitionIdentifier 

30 ) -> TrainingDefinitionEntity: 

31 """Get the training definition with the given id. 

32 

33 Args: 

34 id_: The id of the training definition. 

35 

36 Returns: 

37 A training definition 

38 

39 Raises: 

40 TrainingDefinitionNotFoundException: when the training definition 

41 cannot be found. 

42 """ 

43 

44 @abstractmethod 

45 async def get_all( 

46 self, 

47 query: TrainingDefinitionQuery | None = None, 

48 limit: int | None = None, 

49 offset: int | None = None, 

50 ) -> AsyncIterator[TrainingDefinitionEntity]: 

51 """Return all training definitions of a given query. 

52 

53 Args: 

54 query: The query to use for selecting the rows. 

55 limit: The maximum number of entities to return. 

56 offset: Skip the offset rows before beginning to return entities. 

57 

58 Yields: 

59 A list of applications. 

60 """ 

61 raise NotImplementedError 

62 

63 @abstractmethod 

64 async def create( 

65 self, training_definition: TrainingDefinitionEntity 

66 ) -> TrainingDefinitionEntity: 

67 """Create a new training definition entity. 

68 

69 Args: 

70 training_definition: The training definition to create. 

71 """ 

72 raise NotImplementedError 

73 

74 @abstractmethod 

75 async def update(self, training_definition: TrainingDefinitionEntity): 

76 """Update an application entity. 

77 

78 Args: 

79 training_definition: The training definition to update. 

80 """ 

81 raise NotImplementedError 

82 

83 @abstractmethod 

84 async def delete(self, training_definition: TrainingDefinitionEntity): 

85 """Delete an application entity. 

86 

87 Args: 

88 training_definition: The training definition to delete. 

89 """ 

90 raise NotImplementedError