Coverage for kwai/modules/training/trainings/training_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 repository of trainings.""" 

2from abc import ABC, abstractmethod 

3from typing import AsyncIterator 

4 

5from kwai.modules.training.trainings.training import TrainingEntity, TrainingIdentifier 

6from kwai.modules.training.trainings.training_query import TrainingQuery 

7 

8 

9class TrainingNotFoundException(Exception): 

10 """Raised when a training can not be found.""" 

11 

12 

13class TrainingRepository(ABC): 

14 """An interface for a repository of trainings.""" 

15 

16 @abstractmethod 

17 def create_query(self) -> TrainingQuery: 

18 """Create a query for querying trainings.""" 

19 raise NotImplementedError 

20 

21 @abstractmethod 

22 async def get_all( 

23 self, 

24 query: TrainingQuery | None = None, 

25 limit: int | None = None, 

26 offset: int | None = None, 

27 ) -> AsyncIterator[TrainingEntity]: 

28 """Return all trainings of a given query. 

29 

30 Args: 

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

32 limit: The maximum number of entities to return. 

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

34 

35 Returns: 

36 A list of trainings. 

37 """ 

38 raise NotImplementedError 

39 

40 @abstractmethod 

41 async def get_by_id(self, id: TrainingIdentifier) -> TrainingEntity: 

42 """Get the training with the given id. 

43 

44 Args: 

45 id: The id of the training. 

46 

47 Returns: 

48 A training entity. 

49 """ 

50 raise NotImplementedError 

51 

52 @abstractmethod 

53 async def create(self, training: TrainingEntity) -> TrainingEntity: 

54 """Save a training. 

55 

56 Args: 

57 training: The training to save. 

58 

59 Returns: 

60 A training entity with an identifier. 

61 """ 

62 raise NotImplementedError 

63 

64 @abstractmethod 

65 async def update(self, training: TrainingEntity) -> None: 

66 """Update a training. 

67 

68 Args: 

69 training: The training to save. 

70 """ 

71 raise NotImplementedError 

72 

73 @abstractmethod 

74 async def delete(self, training: TrainingEntity) -> None: 

75 """Delete a training. 

76 

77 Args: 

78 training: The training to delete. 

79 """ 

80 raise NotImplementedError