Coverage for src/kwai/modules/training/get_training_definition.py: 100%

11 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2024-01-01 00:00 +0000

1"""Module that defines the use case "Get Training Definition".""" 

2 

3from dataclasses import dataclass 

4 

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

6 TrainingDefinitionEntity, 

7 TrainingDefinitionIdentifier, 

8) 

9from kwai.modules.training.trainings.training_definition_repository import ( 

10 TrainingDefinitionRepository, 

11) 

12 

13 

14@dataclass(kw_only=True, frozen=True, slots=True) 

15class GetTrainingDefinitionCommand: 

16 """Input for the use case GetTrainingDefinition.""" 

17 

18 id: int 

19 

20 

21class GetTrainingDefinition: 

22 """Use case for getting a training definition.""" 

23 

24 def __init__(self, repo: TrainingDefinitionRepository): 

25 """Initialize the use case. 

26 

27 Args: 

28 repo: A repository for getting the training definition. 

29 """ 

30 self._repo = repo 

31 

32 async def execute( 

33 self, command: GetTrainingDefinitionCommand 

34 ) -> TrainingDefinitionEntity: 

35 """Execute the use case. 

36 

37 Args: 

38 command: The input for this use case. 

39 

40 Raises: 

41 TrainingDefinitionNotFoundException: raised when the training definition 

42 does not exist. 

43 """ 

44 return await self._repo.get_by_id(TrainingDefinitionIdentifier(command.id))