Coverage for src/prosemark/adapters/fake_config.py: 100%

11 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-09-24 18:08 +0000

1# Copyright (c) 2024 Prosemark Contributors 

2# This software is licensed under the MIT License 

3 

4"""Fake configuration adapter for testing config management.""" 

5 

6from pathlib import Path 

7 

8from prosemark.ports.config_port import ConfigPort, ProsemarkConfig 

9 

10 

11class FakeConfigPort(ConfigPort): 

12 """In-memory fake implementation of ConfigPort for testing. 

13 

14 Provides minimal configuration management functionality using memory 

15 storage instead of filesystem. Tracks which configuration files have 

16 been created and provides default configuration values. 

17 

18 This fake maintains a set of paths where configs have been created 

19 and returns a minimal valid configuration dictionary. It does not 

20 perform actual file I/O operations. 

21 

22 Examples: 

23 >>> config = FakeConfigPort() 

24 >>> path = Path('/test/.prosemark.yml') 

25 >>> config.create_default_config(path) 

26 >>> config.config_exists(path) 

27 True 

28 >>> config.get_default_config_values() 

29 {'editor': 'vim', 'daily_dir': 'daily', 'binder_file': '_binder.md'} 

30 

31 """ 

32 

33 def __init__(self) -> None: 

34 """Initialize empty fake configuration port.""" 

35 self._created_configs: set[Path] = set() 

36 

37 def create_default_config(self, config_path: Path) -> None: 

38 """Record that a configuration was created at the given path. 

39 

40 Args: 

41 config_path: Path where configuration would be created. 

42 

43 """ 

44 self._created_configs.add(config_path) 

45 

46 def config_exists(self, config_path: Path) -> bool: 

47 """Check if configuration was created at the given path. 

48 

49 Args: 

50 config_path: Path to check for configuration. 

51 

52 Returns: 

53 True if create_default_config was called with this path. 

54 

55 """ 

56 return config_path in self._created_configs 

57 

58 def get_default_config_values(self) -> ProsemarkConfig: 

59 """Return minimal valid default configuration values. 

60 

61 Returns: 

62 Dictionary with minimal configuration for testing. 

63 

64 """ 

65 return { 

66 'editor': 'vim', 

67 'daily_dir': 'daily', 

68 'binder_file': '_binder.md', 

69 }