Coverage for src/qdrant_loader/config/base.py: 86%

14 statements  

« prev     ^ index     » next       coverage.py v7.8.2, created at 2025-06-04 05:50 +0000

1"""Base configuration interfaces and protocols. 

2 

3This module defines the base interfaces and protocols for all configuration types 

4in the application. These serve as contracts that concrete configuration classes 

5must implement. 

6""" 

7 

8from typing import Any, Protocol 

9 

10from pydantic import BaseModel, ConfigDict 

11 

12 

13class ConfigProtocol(Protocol): 

14 """Protocol for configuration objects. 

15 

16 This protocol defines the minimum interface that all configuration classes 

17 must implement. It serves as a contract for configuration objects. 

18 """ 

19 

20 def to_dict(self) -> dict[str, Any]: 

21 """Convert the configuration to a dictionary. 

22 

23 Returns: 

24 Dict[str, Any]: The configuration as a dictionary. 

25 """ 

26 ... 

27 

28 

29class SourceConfigProtocol(Protocol): 

30 """Protocol for source-specific configurations. 

31 

32 This protocol defines the interface for configurations specific to data sources 

33 like Git, Confluence, or Jira. 

34 """ 

35 

36 def validate(self) -> None: 

37 """Validate the configuration. 

38 

39 Raises: 

40 ValueError: If the configuration is invalid. 

41 """ 

42 ... 

43 

44 

45class BaseConfig(BaseModel): 

46 """Base class for all configuration types. 

47 

48 This class serves as the base for all configuration classes in the application. 

49 It provides common functionality and implements the ConfigProtocol. 

50 """ 

51 

52 model_config = ConfigDict(arbitrary_types_allowed=True, extra="allow") 

53 

54 def to_dict(self) -> dict[str, Any]: 

55 """Convert the configuration to a dictionary. 

56 

57 Returns: 

58 Dict[str, Any]: The configuration as a dictionary. 

59 """ 

60 return self.model_dump() 

61 

62 

63class BaseSourceConfig(BaseConfig): 

64 """Base class for source-specific configurations. 

65 

66 This class serves as the base for all source-specific configuration classes. 

67 It provides common functionality and implements the SourceConfigProtocol. 

68 """ 

69 

70 def validate(self) -> None: 

71 """Validate the configuration. 

72 

73 This method should be overridden by subclasses to implement 

74 source-specific validation logic. 

75 """