Coverage for frappe_manager / output_manager / globals.py: 100%

10 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-07-02 18:13 +0530

1""" 

2Global OutputHandler singleton. 

3 

4Ensures only one output handler exists at a time, preventing concurrent 

5spinner conflicts with the shared DisplayManager singleton. 

6""" 

7 

8from frappe_manager.output_manager.base import OutputHandler 

9 

10_global_output_handler: OutputHandler | None = None 

11 

12 

13def set_global_output_handler(handler: OutputHandler | None) -> None: 

14 """ 

15 Set the global output handler. 

16 

17 This replaces any existing handler. Should be called: 

18 1. Early in main.py (before app()) with basic handler 

19 2. In app_callback (after parsing) with upgraded handler 

20 3. In test cleanup with None to reset state 

21 

22 Args: 

23 handler: The OutputHandler instance to use globally, or None to clear 

24 """ 

25 global _global_output_handler 

26 _global_output_handler = handler 

27 

28 

29def get_global_output_handler() -> OutputHandler: 

30 """ 

31 Get the global output handler. 

32 

33 Returns: 

34 The global OutputHandler instance 

35 

36 Raises: 

37 RuntimeError: If handler not initialized. This indicates a bug 

38 in initialization order - handler should be set 

39 in main.py:cli_entrypoint() before any commands run. 

40 """ 

41 if _global_output_handler is None: 

42 raise RuntimeError( 

43 "Global output handler not initialized. " 

44 "This should be set in main.py:cli_entrypoint() before app() is called.", 

45 ) 

46 return _global_output_handler 

47 

48 

49def has_global_output_handler() -> bool: 

50 """ 

51 Check if global handler is initialized. 

52 

53 Returns: 

54 True if handler is set, False otherwise 

55 """ 

56 return _global_output_handler is not None