|
1 | 1 | ### Documentation for tests/mocks/config_loader.py |
2 | 2 |
|
3 | | -⚠️ No .pydoc file found at <project-location>/tests/mocks/.pydocs/pydoc.__init__.py. |
4 | 3 | Help on module tests.mocks.config_loader in tests.mocks: |
5 | 4 |
|
6 | 5 | NAME |
7 | 6 | tests.mocks.config_loader - File Path: tests/mocks/config_loader.py |
8 | 7 |
|
9 | 8 | DESCRIPTION |
10 | 9 | Description: |
11 | | - Mock Configuration Loader for Test Environments |
| 10 | + Mock Configuration Loader Module |
12 | 11 |
|
13 | | - This module provides structured mock configuration files for testing purposes. It ensures |
14 | | - that test cases operate with predictable configuration data by loading predefined JSON files |
15 | | - (`mock_requirements.json` and `mock_installed.json`). |
| 12 | + This module provides utilities for loading mock JSON-based configurations used |
| 13 | + in testing environments. It dynamically loads and processes configuration files, |
| 14 | + ensuring structured fallback handling and maintaining data integrity. |
16 | 15 |
|
17 | 16 | Core Features: |
18 | | - - Loads `mock_requirements.json` for testing dependency policies. |
19 | | - - Loads `mock_installed.json` for simulating installed packages. |
20 | | - - Ensures missing configuration fields are automatically populated. |
21 | | - - Prevents test failures due to missing or incomplete configuration files. |
| 17 | + - JSON Configuration Loading: Reads and validates structured JSON files. |
| 18 | + - Base Configuration Handling: Ensures required fields exist in loaded configurations. |
| 19 | + - Mock Data Processing: Allows simulated testing of dependency behaviors. |
| 20 | + - Error Handling: Captures and logs missing or malformed JSON files. |
22 | 21 |
|
23 | | - Expected Behavior: |
24 | | - - If `mock_requirements.json` or `mock_installed.json` is missing, a default structure is used. |
25 | | - - Test cases can rely on consistent configuration values. |
26 | | - - Returns structured dictionaries with all required configuration fields. |
| 22 | + Usage: |
| 23 | + To load mock requirements: |
| 24 | + from tests.mocks.config_loader import load_mock_requirements |
| 25 | + mock_config = load_mock_requirements() |
| 26 | + |
| 27 | + To load installed package mock data: |
| 28 | + from tests.mocks.config_loader import load_mock_installed |
| 29 | + installed_config = load_mock_installed() |
27 | 30 |
|
28 | 31 | Dependencies: |
29 | | - - json (for reading and writing structured data) |
30 | | - - pathlib (for managing file paths) |
| 32 | + - sys - Handles system path modifications. |
| 33 | + - os - Provides file system utilities. |
| 34 | + - json - Loads and validates JSON-based configuration data. |
| 35 | + - pathlib - Ensures safe file path resolution. |
31 | 36 |
|
32 | | - Usage: |
33 | | - ```python |
34 | | - from tests.mocks.config_loader import load_mock_requirements, load_mock_installed |
| 37 | + Global Behavior: |
| 38 | + - Loads mock configuration data dynamically. |
| 39 | + - Ensures missing configuration fields are populated with default values. |
| 40 | + - Prevents errors due to missing or malformed configuration files. |
35 | 41 |
|
36 | | - requirements = load_mock_requirements() |
37 | | - installed = load_mock_installed() |
38 | | - ``` |
| 42 | + Exit Codes: |
| 43 | + - 0: Execution completed successfully. |
| 44 | + - 1: Failure due to configuration loading errors. |
39 | 45 |
|
40 | 46 | FUNCTIONS |
41 | 47 | load_mock_installed() -> dict |
42 | | - Function: load_mock_installed() |
| 48 | + Function: load_mock_installed() -> dict |
43 | 49 |
|
44 | 50 | Description: |
45 | | - Loads and returns the contents of `mock_installed.json`, ensuring |
46 | | - that all required fields are present. If the file is missing, a default |
47 | | - base configuration is returned. |
| 51 | + Loads and returns the contents of `mock_installed.json`, ensuring missing fields are populated. |
48 | 52 |
|
49 | 53 | Parameters: |
50 | 54 | - None |
51 | 55 |
|
52 | 56 | Returns: |
53 | | - - dict: A structured dictionary representing the mock installed package configuration. |
| 57 | + - dict: The processed installed package configuration dictionary. |
54 | 58 |
|
55 | 59 | Behavior: |
56 | | - - If `mock_installed.json` exists, its contents are loaded. |
57 | | - - If the file is missing, a predefined base configuration is used. |
58 | | - - Ensures all required keys are present in the loaded data. |
59 | | - |
60 | | - Example: |
61 | | - ```python |
62 | | - installed = load_mock_installed() |
63 | | - print(installed["packages"]["installation"]["configs"]) |
64 | | - ``` |
65 | | - |
66 | | - Notes: |
67 | | - - Used for testing dependency installations and package state validation. |
68 | | - - Guarantees test cases receive structured data. |
| 60 | + - Ensures structured test data for installed dependencies. |
| 61 | + - Uses `BASE_INSTALLED_CONFIG` as a fallback if the file is missing. |
69 | 62 |
|
70 | 63 | load_mock_requirements() -> dict |
71 | | - Function: load_mock_requirements() |
| 64 | + Function: load_mock_requirements() -> dict |
72 | 65 |
|
73 | 66 | Description: |
74 | | - Loads and returns the contents of `mock_requirements.json`, ensuring |
75 | | - that all required fields are present. If the file is missing, a default |
76 | | - base configuration is returned. |
| 67 | + Loads and returns the contents of `mock_requirements.json`, ensuring missing fields are populated. |
77 | 68 |
|
78 | 69 | Parameters: |
79 | 70 | - None |
80 | 71 |
|
81 | 72 | Returns: |
82 | | - - dict: A structured dictionary representing the mock requirements configuration. |
| 73 | + - dict: The processed configuration dictionary with all necessary fields. |
83 | 74 |
|
84 | 75 | Behavior: |
85 | | - - If `mock_requirements.json` exists, its contents are loaded. |
86 | | - - If the file is missing, a predefined base configuration is used. |
87 | | - - Ensures all required keys are present in the loaded data. |
| 76 | + - Ensures a structured mock environment for package requirements. |
| 77 | + - Uses `BASE_REQUIREMENTS_CONFIG` as a fallback if the file is missing. |
88 | 78 |
|
89 | | - Example: |
90 | | - ```python |
91 | | - config = load_mock_requirements() |
92 | | - print(config["logging"]["enable"]) # True |
93 | | - ``` |
| 79 | + main() -> None |
| 80 | + Function: main() -> None |
94 | 81 |
|
95 | | - Notes: |
96 | | - - Prevents test failures due to missing configuration files. |
97 | | - - Populates default values for missing fields. |
| 82 | + Description: |
| 83 | + Placeholder function for module execution. |
98 | 84 |
|
99 | | - main() -> None |
| 85 | + Parameters: |
| 86 | + - None |
| 87 | + |
| 88 | + Returns: |
| 89 | + - None |
100 | 90 |
|
101 | 91 | DATA |
102 | 92 | BASE_INSTALLED_CONFIG = {'colors': {}, 'environment': {'BREW_AVAILABLE... |
103 | 93 | BASE_REQUIREMENTS_CONFIG = {'colors': {}, 'environment': {'BREW_AVAILA... |
| 94 | + INSTALLED_FILEPATH = '<project-location>/tests/mo... |
| 95 | + LIB_DIR = PosixPath('<project-location>/lib') |
104 | 96 | MOCKS_DIR = PosixPath('<project-location>/tests/m... |
| 97 | + REQUIREMENTS_FILEPATH = '<project-location>/tests... |
| 98 | + SCRIPT_DIR = '<project-location>/tests/mocks' |
| 99 | + installed_config = {'colors': {}, 'environment': {'BREW_AVAILABLE': Fa... |
| 100 | + requirements_config = {'colors': {}, 'environment': {'BREW_AVAILABLE':... |
| 101 | + validation_schema = {'requirements': [{}]} |
105 | 102 |
|
106 | 103 | VERSION |
107 | 104 | 0.1.0 |
|
0 commit comments