provide-foundation 0.0.0.dev0__py3-none-any.whl → 0.0.0.dev1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. provide/foundation/__init__.py +12 -20
  2. provide/foundation/archive/__init__.py +23 -0
  3. provide/foundation/archive/base.py +70 -0
  4. provide/foundation/archive/bzip2.py +157 -0
  5. provide/foundation/archive/gzip.py +159 -0
  6. provide/foundation/archive/operations.py +336 -0
  7. provide/foundation/archive/tar.py +164 -0
  8. provide/foundation/archive/zip.py +203 -0
  9. provide/foundation/config/base.py +2 -2
  10. provide/foundation/config/sync.py +19 -4
  11. provide/foundation/core.py +1 -2
  12. provide/foundation/crypto/__init__.py +2 -0
  13. provide/foundation/crypto/certificates/__init__.py +34 -0
  14. provide/foundation/crypto/certificates/base.py +173 -0
  15. provide/foundation/crypto/certificates/certificate.py +290 -0
  16. provide/foundation/crypto/certificates/factory.py +213 -0
  17. provide/foundation/crypto/certificates/generator.py +138 -0
  18. provide/foundation/crypto/certificates/loader.py +130 -0
  19. provide/foundation/crypto/certificates/operations.py +198 -0
  20. provide/foundation/crypto/certificates/trust.py +107 -0
  21. provide/foundation/eventsets/__init__.py +0 -0
  22. provide/foundation/eventsets/display.py +84 -0
  23. provide/foundation/eventsets/registry.py +160 -0
  24. provide/foundation/eventsets/resolver.py +192 -0
  25. provide/foundation/eventsets/sets/das.py +128 -0
  26. provide/foundation/eventsets/sets/database.py +125 -0
  27. provide/foundation/eventsets/sets/http.py +153 -0
  28. provide/foundation/eventsets/sets/llm.py +139 -0
  29. provide/foundation/eventsets/sets/task_queue.py +107 -0
  30. provide/foundation/eventsets/types.py +70 -0
  31. provide/foundation/hub/components.py +7 -133
  32. provide/foundation/logger/__init__.py +3 -10
  33. provide/foundation/logger/config/logging.py +6 -6
  34. provide/foundation/logger/core.py +0 -2
  35. provide/foundation/logger/custom_processors.py +1 -0
  36. provide/foundation/logger/factories.py +11 -2
  37. provide/foundation/logger/processors/main.py +20 -84
  38. provide/foundation/logger/setup/__init__.py +5 -1
  39. provide/foundation/logger/setup/coordinator.py +75 -23
  40. provide/foundation/logger/setup/processors.py +2 -9
  41. provide/foundation/logger/trace.py +27 -0
  42. provide/foundation/metrics/otel.py +10 -10
  43. provide/foundation/process/lifecycle.py +82 -26
  44. provide/foundation/testing/__init__.py +77 -0
  45. provide/foundation/testing/archive/__init__.py +24 -0
  46. provide/foundation/testing/archive/fixtures.py +217 -0
  47. provide/foundation/testing/common/__init__.py +34 -0
  48. provide/foundation/testing/common/fixtures.py +263 -0
  49. provide/foundation/testing/file/__init__.py +40 -0
  50. provide/foundation/testing/file/fixtures.py +523 -0
  51. provide/foundation/testing/logger.py +41 -11
  52. provide/foundation/testing/mocking/__init__.py +46 -0
  53. provide/foundation/testing/mocking/fixtures.py +331 -0
  54. provide/foundation/testing/process/__init__.py +48 -0
  55. provide/foundation/testing/process/fixtures.py +577 -0
  56. provide/foundation/testing/threading/__init__.py +38 -0
  57. provide/foundation/testing/threading/fixtures.py +520 -0
  58. provide/foundation/testing/time/__init__.py +32 -0
  59. provide/foundation/testing/time/fixtures.py +409 -0
  60. provide/foundation/testing/transport/__init__.py +30 -0
  61. provide/foundation/testing/transport/fixtures.py +280 -0
  62. provide/foundation/tools/__init__.py +58 -0
  63. provide/foundation/tools/base.py +348 -0
  64. provide/foundation/tools/cache.py +266 -0
  65. provide/foundation/tools/downloader.py +213 -0
  66. provide/foundation/tools/installer.py +254 -0
  67. provide/foundation/tools/registry.py +223 -0
  68. provide/foundation/tools/resolver.py +321 -0
  69. provide/foundation/tools/verifier.py +186 -0
  70. provide/foundation/tracer/otel.py +7 -11
  71. provide/foundation/transport/__init__.py +155 -0
  72. provide/foundation/transport/base.py +171 -0
  73. provide/foundation/transport/client.py +266 -0
  74. provide/foundation/transport/config.py +209 -0
  75. provide/foundation/transport/errors.py +79 -0
  76. provide/foundation/transport/http.py +232 -0
  77. provide/foundation/transport/middleware.py +366 -0
  78. provide/foundation/transport/registry.py +167 -0
  79. provide/foundation/transport/types.py +45 -0
  80. {provide_foundation-0.0.0.dev0.dist-info → provide_foundation-0.0.0.dev1.dist-info}/METADATA +5 -28
  81. {provide_foundation-0.0.0.dev0.dist-info → provide_foundation-0.0.0.dev1.dist-info}/RECORD +85 -34
  82. provide/foundation/cli/commands/logs/generate_old.py +0 -569
  83. provide/foundation/crypto/certificates.py +0 -896
  84. provide/foundation/logger/emoji/__init__.py +0 -44
  85. provide/foundation/logger/emoji/matrix.py +0 -209
  86. provide/foundation/logger/emoji/sets.py +0 -458
  87. provide/foundation/logger/emoji/types.py +0 -56
  88. provide/foundation/logger/setup/emoji_resolver.py +0 -64
  89. {provide_foundation-0.0.0.dev0.dist-info → provide_foundation-0.0.0.dev1.dist-info}/WHEEL +0 -0
  90. {provide_foundation-0.0.0.dev0.dist-info → provide_foundation-0.0.0.dev1.dist-info}/entry_points.txt +0 -0
  91. {provide_foundation-0.0.0.dev0.dist-info → provide_foundation-0.0.0.dev1.dist-info}/licenses/LICENSE +0 -0
  92. {provide_foundation-0.0.0.dev0.dist-info → provide_foundation-0.0.0.dev1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,331 @@
1
+ """
2
+ Mocking Fixtures and Utilities.
3
+
4
+ Standardized mocking patterns and fixtures for the provide-io ecosystem.
5
+ Reduces boilerplate and ensures consistent mocking across all tests.
6
+ """
7
+
8
+ from unittest.mock import Mock, MagicMock, AsyncMock, PropertyMock, patch, call, ANY
9
+ from typing import Any, Callable
10
+ from collections.abc import Generator
11
+ import sys
12
+
13
+ import pytest
14
+
15
+
16
+ @pytest.fixture
17
+ def mock_factory():
18
+ """
19
+ Factory for creating configured mock objects.
20
+
21
+ Returns:
22
+ Function that creates mock objects with common configurations.
23
+ """
24
+ def _create_mock(name: str = None, **kwargs) -> Mock:
25
+ """
26
+ Create a mock with standard configuration.
27
+
28
+ Args:
29
+ name: Optional name for the mock
30
+ **kwargs: Additional mock configuration
31
+
32
+ Returns:
33
+ Configured Mock object
34
+ """
35
+ defaults = {
36
+ "spec_set": True if "spec" in kwargs else False,
37
+ }
38
+ defaults.update(kwargs)
39
+
40
+ mock = Mock(name=name, **defaults)
41
+ return mock
42
+
43
+ return _create_mock
44
+
45
+
46
+ @pytest.fixture
47
+ def magic_mock_factory():
48
+ """
49
+ Factory for creating MagicMock objects.
50
+
51
+ Returns:
52
+ Function that creates MagicMock objects with common configurations.
53
+ """
54
+ def _create_magic_mock(name: str = None, **kwargs) -> MagicMock:
55
+ """
56
+ Create a MagicMock with standard configuration.
57
+
58
+ Args:
59
+ name: Optional name for the mock
60
+ **kwargs: Additional mock configuration
61
+
62
+ Returns:
63
+ Configured MagicMock object
64
+ """
65
+ return MagicMock(name=name, **kwargs)
66
+
67
+ return _create_magic_mock
68
+
69
+
70
+ @pytest.fixture
71
+ def async_mock_factory():
72
+ """
73
+ Factory for creating AsyncMock objects.
74
+
75
+ Returns:
76
+ Function that creates AsyncMock objects with common configurations.
77
+ """
78
+ def _create_async_mock(name: str = None, return_value=None, side_effect=None, **kwargs) -> AsyncMock:
79
+ """
80
+ Create an AsyncMock with standard configuration.
81
+
82
+ Args:
83
+ name: Optional name for the mock
84
+ return_value: Return value for the async mock
85
+ side_effect: Side effect for the async mock
86
+ **kwargs: Additional mock configuration
87
+
88
+ Returns:
89
+ Configured AsyncMock object
90
+ """
91
+ mock = AsyncMock(name=name, **kwargs)
92
+ if return_value is not None:
93
+ mock.return_value = return_value
94
+ if side_effect is not None:
95
+ mock.side_effect = side_effect
96
+ return mock
97
+
98
+ return _create_async_mock
99
+
100
+
101
+ @pytest.fixture
102
+ def property_mock_factory():
103
+ """
104
+ Factory for creating PropertyMock objects.
105
+
106
+ Returns:
107
+ Function that creates PropertyMock objects.
108
+ """
109
+ def _create_property_mock(return_value=None, side_effect=None, **kwargs) -> PropertyMock:
110
+ """
111
+ Create a PropertyMock.
112
+
113
+ Args:
114
+ return_value: Return value for the property
115
+ side_effect: Side effect for the property
116
+ **kwargs: Additional mock configuration
117
+
118
+ Returns:
119
+ Configured PropertyMock object
120
+ """
121
+ return PropertyMock(return_value=return_value, side_effect=side_effect, **kwargs)
122
+
123
+ return _create_property_mock
124
+
125
+
126
+ @pytest.fixture
127
+ def patch_fixture():
128
+ """
129
+ Fixture for patching objects with automatic cleanup.
130
+
131
+ Returns:
132
+ Function that patches objects and returns the mock.
133
+ """
134
+ patches = []
135
+
136
+ def _patch(target: str, **kwargs) -> Mock:
137
+ """
138
+ Patch a target with automatic cleanup.
139
+
140
+ Args:
141
+ target: The target to patch (module.Class.attribute)
142
+ **kwargs: Additional patch configuration
143
+
144
+ Returns:
145
+ The mock object
146
+ """
147
+ patcher = patch(target, **kwargs)
148
+ mock = patcher.start()
149
+ patches.append(patcher)
150
+ return mock
151
+
152
+ yield _patch
153
+
154
+ # Cleanup all patches
155
+ for patcher in patches:
156
+ patcher.stop()
157
+
158
+
159
+ @pytest.fixture
160
+ def patch_multiple_fixture():
161
+ """
162
+ Fixture for patching multiple objects at once.
163
+
164
+ Returns:
165
+ Function that patches multiple targets.
166
+ """
167
+ patches = []
168
+
169
+ def _patch_multiple(target_module: str, **kwargs) -> dict[str, Mock]:
170
+ """
171
+ Patch multiple attributes in a module.
172
+
173
+ Args:
174
+ target_module: The module to patch in
175
+ **kwargs: Mapping of attribute names to mock objects or DEFAULT
176
+
177
+ Returns:
178
+ Dict mapping attribute names to mock objects
179
+ """
180
+ from unittest.mock import patch as mock_patch
181
+ patcher = mock_patch.multiple(target_module, **kwargs)
182
+ mocks = patcher.start()
183
+ patches.append(patcher)
184
+ return mocks
185
+
186
+ yield _patch_multiple
187
+
188
+ # Cleanup all patches
189
+ for patcher in patches:
190
+ patcher.stop()
191
+
192
+
193
+ @pytest.fixture
194
+ def auto_patch():
195
+ """
196
+ Context manager for automatic patching with cleanup.
197
+
198
+ Returns:
199
+ Patch context manager class.
200
+ """
201
+ class AutoPatch:
202
+ def __init__(self):
203
+ self.patches = []
204
+
205
+ def object(self, target: Any, attribute: str, **kwargs) -> Mock:
206
+ """Patch an object's attribute."""
207
+ patcher = patch.object(target, attribute, **kwargs)
208
+ mock = patcher.start()
209
+ self.patches.append(patcher)
210
+ return mock
211
+
212
+ def dict(self, target: dict, values: dict, **kwargs) -> None:
213
+ """Patch a dictionary."""
214
+ patcher = patch.dict(target, values, **kwargs)
215
+ patcher.start()
216
+ self.patches.append(patcher)
217
+
218
+ def env(self, **env_vars) -> None:
219
+ """Patch environment variables."""
220
+ import os
221
+ patcher = patch.dict(os.environ, env_vars)
222
+ patcher.start()
223
+ self.patches.append(patcher)
224
+
225
+ def cleanup(self):
226
+ """Stop all patches."""
227
+ for patcher in self.patches:
228
+ patcher.stop()
229
+
230
+ patcher = AutoPatch()
231
+ yield patcher
232
+ patcher.cleanup()
233
+
234
+
235
+ @pytest.fixture
236
+ def mock_open_fixture():
237
+ """
238
+ Fixture for mocking file operations.
239
+
240
+ Returns:
241
+ Function that creates a mock for open().
242
+ """
243
+ from unittest.mock import mock_open
244
+
245
+ def _mock_open(read_data: str = None) -> Mock:
246
+ """
247
+ Create a mock for the open() builtin.
248
+
249
+ Args:
250
+ read_data: Optional data to return when reading
251
+
252
+ Returns:
253
+ Mock object for open()
254
+ """
255
+ return mock_open(read_data=read_data)
256
+
257
+ return _mock_open
258
+
259
+
260
+ @pytest.fixture
261
+ def spy_fixture():
262
+ """
263
+ Create a spy (mock that calls through to the original).
264
+
265
+ Returns:
266
+ Function that creates spy objects.
267
+ """
268
+ def _create_spy(obj: Any, method_name: str) -> Mock:
269
+ """
270
+ Create a spy on a method.
271
+
272
+ Args:
273
+ obj: The object to spy on
274
+ method_name: The method name to spy on
275
+
276
+ Returns:
277
+ Mock that wraps the original method
278
+ """
279
+ original = getattr(obj, method_name)
280
+ mock = Mock(wraps=original)
281
+ setattr(obj, method_name, mock)
282
+ return mock
283
+
284
+ return _create_spy
285
+
286
+
287
+ @pytest.fixture
288
+ def assert_mock_calls():
289
+ """
290
+ Helper for asserting mock calls with better error messages.
291
+
292
+ Returns:
293
+ Function for asserting mock calls.
294
+ """
295
+ def _assert_calls(mock: Mock, expected_calls: list, any_order: bool = False):
296
+ """
297
+ Assert that a mock was called with expected calls.
298
+
299
+ Args:
300
+ mock: The mock to check
301
+ expected_calls: List of expected call objects
302
+ any_order: Whether calls can be in any order
303
+ """
304
+ if any_order:
305
+ mock.assert_has_calls(expected_calls, any_order=True)
306
+ else:
307
+ mock.assert_has_calls(expected_calls)
308
+
309
+ return _assert_calls
310
+
311
+
312
+ # Re-export commonly used mock utilities
313
+ __all__ = [
314
+ "Mock",
315
+ "MagicMock",
316
+ "AsyncMock",
317
+ "PropertyMock",
318
+ "patch",
319
+ "call",
320
+ "ANY",
321
+ "mock_factory",
322
+ "magic_mock_factory",
323
+ "async_mock_factory",
324
+ "property_mock_factory",
325
+ "patch_fixture",
326
+ "patch_multiple_fixture",
327
+ "auto_patch",
328
+ "mock_open_fixture",
329
+ "spy_fixture",
330
+ "assert_mock_calls",
331
+ ]
@@ -0,0 +1,48 @@
1
+ """
2
+ Process and async testing fixtures for the provide-io ecosystem.
3
+
4
+ Standard fixtures for testing async code, subprocess operations, and
5
+ event loop management across any project that depends on provide.foundation.
6
+ """
7
+
8
+ from provide.foundation.testing.process.fixtures import (
9
+ clean_event_loop,
10
+ async_timeout,
11
+ mock_async_process,
12
+ async_stream_reader,
13
+ event_loop_policy,
14
+ async_context_manager,
15
+ async_iterator,
16
+ async_queue,
17
+ async_lock,
18
+ mock_async_sleep,
19
+ async_subprocess,
20
+ async_gather_helper,
21
+ async_task_group,
22
+ async_condition_waiter,
23
+ async_mock_server,
24
+ async_pipeline,
25
+ async_rate_limiter,
26
+ async_test_client,
27
+ )
28
+
29
+ __all__ = [
30
+ "clean_event_loop",
31
+ "async_timeout",
32
+ "mock_async_process",
33
+ "async_stream_reader",
34
+ "event_loop_policy",
35
+ "async_context_manager",
36
+ "async_iterator",
37
+ "async_queue",
38
+ "async_lock",
39
+ "mock_async_sleep",
40
+ "async_subprocess",
41
+ "async_gather_helper",
42
+ "async_task_group",
43
+ "async_condition_waiter",
44
+ "async_mock_server",
45
+ "async_pipeline",
46
+ "async_rate_limiter",
47
+ "async_test_client",
48
+ ]