provide-foundation 0.0.0.dev0__py3-none-any.whl → 0.0.0.dev2__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 (161) hide show
  1. provide/foundation/__init__.py +41 -23
  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 +334 -0
  7. provide/foundation/archive/tar.py +164 -0
  8. provide/foundation/archive/zip.py +203 -0
  9. provide/foundation/cli/__init__.py +2 -2
  10. provide/foundation/cli/commands/deps.py +13 -7
  11. provide/foundation/cli/commands/logs/__init__.py +1 -1
  12. provide/foundation/cli/commands/logs/query.py +1 -1
  13. provide/foundation/cli/commands/logs/send.py +1 -1
  14. provide/foundation/cli/commands/logs/tail.py +1 -1
  15. provide/foundation/cli/decorators.py +11 -10
  16. provide/foundation/cli/main.py +1 -1
  17. provide/foundation/cli/testing.py +2 -35
  18. provide/foundation/cli/utils.py +21 -17
  19. provide/foundation/config/__init__.py +35 -2
  20. provide/foundation/config/base.py +2 -2
  21. provide/foundation/config/converters.py +479 -0
  22. provide/foundation/config/defaults.py +67 -0
  23. provide/foundation/config/env.py +4 -19
  24. provide/foundation/config/loader.py +9 -3
  25. provide/foundation/config/sync.py +19 -4
  26. provide/foundation/console/input.py +5 -5
  27. provide/foundation/console/output.py +35 -13
  28. provide/foundation/context/__init__.py +8 -4
  29. provide/foundation/context/core.py +85 -109
  30. provide/foundation/core.py +1 -2
  31. provide/foundation/crypto/__init__.py +2 -0
  32. provide/foundation/crypto/certificates/__init__.py +34 -0
  33. provide/foundation/crypto/certificates/base.py +173 -0
  34. provide/foundation/crypto/certificates/certificate.py +290 -0
  35. provide/foundation/crypto/certificates/factory.py +213 -0
  36. provide/foundation/crypto/certificates/generator.py +138 -0
  37. provide/foundation/crypto/certificates/loader.py +130 -0
  38. provide/foundation/crypto/certificates/operations.py +198 -0
  39. provide/foundation/crypto/certificates/trust.py +107 -0
  40. provide/foundation/errors/__init__.py +2 -3
  41. provide/foundation/errors/decorators.py +0 -231
  42. provide/foundation/errors/types.py +0 -97
  43. provide/foundation/eventsets/__init__.py +0 -0
  44. provide/foundation/eventsets/display.py +84 -0
  45. provide/foundation/eventsets/registry.py +160 -0
  46. provide/foundation/eventsets/resolver.py +192 -0
  47. provide/foundation/eventsets/sets/das.py +128 -0
  48. provide/foundation/eventsets/sets/database.py +125 -0
  49. provide/foundation/eventsets/sets/http.py +153 -0
  50. provide/foundation/eventsets/sets/llm.py +139 -0
  51. provide/foundation/eventsets/sets/task_queue.py +107 -0
  52. provide/foundation/eventsets/types.py +70 -0
  53. provide/foundation/file/directory.py +13 -22
  54. provide/foundation/file/lock.py +3 -1
  55. provide/foundation/hub/components.py +77 -515
  56. provide/foundation/hub/config.py +151 -0
  57. provide/foundation/hub/discovery.py +62 -0
  58. provide/foundation/hub/handlers.py +81 -0
  59. provide/foundation/hub/lifecycle.py +194 -0
  60. provide/foundation/hub/manager.py +4 -4
  61. provide/foundation/hub/processors.py +44 -0
  62. provide/foundation/integrations/__init__.py +11 -0
  63. provide/foundation/{observability → integrations}/openobserve/__init__.py +10 -7
  64. provide/foundation/{observability → integrations}/openobserve/auth.py +1 -1
  65. provide/foundation/{observability → integrations}/openobserve/client.py +12 -12
  66. provide/foundation/{observability → integrations}/openobserve/commands.py +3 -3
  67. provide/foundation/integrations/openobserve/config.py +37 -0
  68. provide/foundation/{observability → integrations}/openobserve/formatters.py +1 -1
  69. provide/foundation/{observability → integrations}/openobserve/otlp.py +1 -1
  70. provide/foundation/{observability → integrations}/openobserve/search.py +2 -2
  71. provide/foundation/{observability → integrations}/openobserve/streaming.py +4 -4
  72. provide/foundation/logger/__init__.py +3 -10
  73. provide/foundation/logger/config/logging.py +68 -298
  74. provide/foundation/logger/config/telemetry.py +41 -121
  75. provide/foundation/logger/core.py +0 -2
  76. provide/foundation/logger/custom_processors.py +1 -0
  77. provide/foundation/logger/factories.py +11 -2
  78. provide/foundation/logger/processors/main.py +20 -84
  79. provide/foundation/logger/setup/__init__.py +5 -1
  80. provide/foundation/logger/setup/coordinator.py +76 -24
  81. provide/foundation/logger/setup/processors.py +2 -9
  82. provide/foundation/logger/trace.py +27 -0
  83. provide/foundation/metrics/otel.py +10 -10
  84. provide/foundation/observability/__init__.py +2 -2
  85. provide/foundation/process/__init__.py +9 -0
  86. provide/foundation/process/exit.py +47 -0
  87. provide/foundation/process/lifecycle.py +115 -59
  88. provide/foundation/resilience/__init__.py +35 -0
  89. provide/foundation/resilience/circuit.py +164 -0
  90. provide/foundation/resilience/decorators.py +220 -0
  91. provide/foundation/resilience/fallback.py +193 -0
  92. provide/foundation/resilience/retry.py +325 -0
  93. provide/foundation/streams/config.py +79 -0
  94. provide/foundation/streams/console.py +7 -8
  95. provide/foundation/streams/core.py +6 -3
  96. provide/foundation/streams/file.py +12 -2
  97. provide/foundation/testing/__init__.py +84 -2
  98. provide/foundation/testing/archive/__init__.py +24 -0
  99. provide/foundation/testing/archive/fixtures.py +217 -0
  100. provide/foundation/testing/cli.py +30 -17
  101. provide/foundation/testing/common/__init__.py +32 -0
  102. provide/foundation/testing/common/fixtures.py +236 -0
  103. provide/foundation/testing/file/__init__.py +40 -0
  104. provide/foundation/testing/file/content_fixtures.py +316 -0
  105. provide/foundation/testing/file/directory_fixtures.py +107 -0
  106. provide/foundation/testing/file/fixtures.py +52 -0
  107. provide/foundation/testing/file/special_fixtures.py +153 -0
  108. provide/foundation/testing/logger.py +117 -11
  109. provide/foundation/testing/mocking/__init__.py +46 -0
  110. provide/foundation/testing/mocking/fixtures.py +331 -0
  111. provide/foundation/testing/process/__init__.py +48 -0
  112. provide/foundation/testing/process/async_fixtures.py +405 -0
  113. provide/foundation/testing/process/fixtures.py +56 -0
  114. provide/foundation/testing/process/subprocess_fixtures.py +209 -0
  115. provide/foundation/testing/threading/__init__.py +38 -0
  116. provide/foundation/testing/threading/basic_fixtures.py +101 -0
  117. provide/foundation/testing/threading/data_fixtures.py +99 -0
  118. provide/foundation/testing/threading/execution_fixtures.py +263 -0
  119. provide/foundation/testing/threading/fixtures.py +54 -0
  120. provide/foundation/testing/threading/sync_fixtures.py +97 -0
  121. provide/foundation/testing/time/__init__.py +32 -0
  122. provide/foundation/testing/time/fixtures.py +409 -0
  123. provide/foundation/testing/transport/__init__.py +30 -0
  124. provide/foundation/testing/transport/fixtures.py +280 -0
  125. provide/foundation/tools/__init__.py +58 -0
  126. provide/foundation/tools/base.py +348 -0
  127. provide/foundation/tools/cache.py +268 -0
  128. provide/foundation/tools/downloader.py +224 -0
  129. provide/foundation/tools/installer.py +254 -0
  130. provide/foundation/tools/registry.py +223 -0
  131. provide/foundation/tools/resolver.py +321 -0
  132. provide/foundation/tools/verifier.py +186 -0
  133. provide/foundation/tracer/otel.py +7 -11
  134. provide/foundation/tracer/spans.py +2 -2
  135. provide/foundation/transport/__init__.py +155 -0
  136. provide/foundation/transport/base.py +171 -0
  137. provide/foundation/transport/client.py +266 -0
  138. provide/foundation/transport/config.py +140 -0
  139. provide/foundation/transport/errors.py +79 -0
  140. provide/foundation/transport/http.py +232 -0
  141. provide/foundation/transport/middleware.py +360 -0
  142. provide/foundation/transport/registry.py +167 -0
  143. provide/foundation/transport/types.py +45 -0
  144. provide/foundation/utils/deps.py +14 -12
  145. provide/foundation/utils/parsing.py +49 -4
  146. {provide_foundation-0.0.0.dev0.dist-info → provide_foundation-0.0.0.dev2.dist-info}/METADATA +5 -28
  147. provide_foundation-0.0.0.dev2.dist-info/RECORD +225 -0
  148. provide/foundation/cli/commands/logs/generate_old.py +0 -569
  149. provide/foundation/crypto/certificates.py +0 -896
  150. provide/foundation/logger/emoji/__init__.py +0 -44
  151. provide/foundation/logger/emoji/matrix.py +0 -209
  152. provide/foundation/logger/emoji/sets.py +0 -458
  153. provide/foundation/logger/emoji/types.py +0 -56
  154. provide/foundation/logger/setup/emoji_resolver.py +0 -64
  155. provide_foundation-0.0.0.dev0.dist-info/RECORD +0 -149
  156. /provide/foundation/{observability → integrations}/openobserve/exceptions.py +0 -0
  157. /provide/foundation/{observability → integrations}/openobserve/models.py +0 -0
  158. {provide_foundation-0.0.0.dev0.dist-info → provide_foundation-0.0.0.dev2.dist-info}/WHEEL +0 -0
  159. {provide_foundation-0.0.0.dev0.dist-info → provide_foundation-0.0.0.dev2.dist-info}/entry_points.txt +0 -0
  160. {provide_foundation-0.0.0.dev0.dist-info → provide_foundation-0.0.0.dev2.dist-info}/licenses/LICENSE +0 -0
  161. {provide_foundation-0.0.0.dev0.dist-info → provide_foundation-0.0.0.dev2.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,316 @@
1
+ """
2
+ Content-based file test fixtures.
3
+
4
+ Fixtures for creating files with specific content types like text, binary,
5
+ CSV, JSON, and other structured data.
6
+ """
7
+
8
+ import csv
9
+ import json
10
+ import random
11
+ import tempfile
12
+ from pathlib import Path
13
+
14
+ import pytest
15
+
16
+ from provide.foundation.file.safe import safe_delete
17
+
18
+
19
+ @pytest.fixture
20
+ def temp_file():
21
+ """
22
+ Create a temporary file factory with optional content.
23
+
24
+ Returns:
25
+ A function that creates temporary files with specified content and suffix.
26
+ """
27
+ created_files = []
28
+
29
+ def _make_temp_file(content: str = "test content", suffix: str = ".txt") -> Path:
30
+ """
31
+ Create a temporary file.
32
+
33
+ Args:
34
+ content: Content to write to the file
35
+ suffix: File suffix/extension
36
+
37
+ Returns:
38
+ Path to the created temporary file
39
+ """
40
+ with tempfile.NamedTemporaryFile(mode='w', suffix=suffix, delete=False) as f:
41
+ f.write(content)
42
+ path = Path(f.name)
43
+ created_files.append(path)
44
+ return path
45
+
46
+ yield _make_temp_file
47
+
48
+ # Cleanup all created files
49
+ for path in created_files:
50
+ safe_delete(path, missing_ok=True)
51
+
52
+
53
+ @pytest.fixture
54
+ def temp_named_file():
55
+ """
56
+ Create a named temporary file factory.
57
+
58
+ Returns:
59
+ Function that creates named temporary files.
60
+ """
61
+ created_files = []
62
+
63
+ def _make_named_file(
64
+ content: bytes | str = None,
65
+ suffix: str = "",
66
+ prefix: str = "tmp",
67
+ dir: Path | str = None,
68
+ mode: str = 'w+b',
69
+ delete: bool = False
70
+ ) -> Path:
71
+ """
72
+ Create a named temporary file.
73
+
74
+ Args:
75
+ content: Optional content to write
76
+ suffix: File suffix
77
+ prefix: File prefix
78
+ dir: Directory for the file
79
+ mode: File mode
80
+ delete: Whether to delete on close
81
+
82
+ Returns:
83
+ Path to the created file
84
+ """
85
+ if isinstance(dir, Path):
86
+ dir = str(dir)
87
+
88
+ f = tempfile.NamedTemporaryFile(
89
+ mode=mode,
90
+ suffix=suffix,
91
+ prefix=prefix,
92
+ dir=dir,
93
+ delete=delete
94
+ )
95
+
96
+ if content is not None:
97
+ if isinstance(content, str):
98
+ if 'b' in mode:
99
+ f.write(content.encode())
100
+ else:
101
+ f.write(content)
102
+ else:
103
+ f.write(content)
104
+ f.flush()
105
+
106
+ path = Path(f.name)
107
+ f.close()
108
+
109
+ if not delete:
110
+ created_files.append(path)
111
+
112
+ return path
113
+
114
+ yield _make_named_file
115
+
116
+ # Cleanup
117
+ for path in created_files:
118
+ safe_delete(path, missing_ok=True)
119
+
120
+
121
+ @pytest.fixture
122
+ def temp_file_with_content():
123
+ """
124
+ Create temporary files with specific content.
125
+
126
+ Returns:
127
+ Function that creates files with content.
128
+ """
129
+ created_files = []
130
+
131
+ def _make_file(
132
+ content: str | bytes,
133
+ suffix: str = ".txt",
134
+ encoding: str = "utf-8"
135
+ ) -> Path:
136
+ """
137
+ Create a temporary file with content.
138
+
139
+ Args:
140
+ content: Content to write
141
+ suffix: File suffix
142
+ encoding: Text encoding (for str content)
143
+
144
+ Returns:
145
+ Path to created file
146
+ """
147
+ with tempfile.NamedTemporaryFile(
148
+ mode='wb' if isinstance(content, bytes) else 'w',
149
+ suffix=suffix,
150
+ delete=False,
151
+ encoding=None if isinstance(content, bytes) else encoding
152
+ ) as f:
153
+ f.write(content)
154
+ path = Path(f.name)
155
+
156
+ created_files.append(path)
157
+ return path
158
+
159
+ yield _make_file
160
+
161
+ # Cleanup
162
+ for path in created_files:
163
+ safe_delete(path, missing_ok=True)
164
+
165
+
166
+ @pytest.fixture
167
+ def temp_binary_file():
168
+ """
169
+ Create temporary binary files.
170
+
171
+ Returns:
172
+ Function that creates binary files.
173
+ """
174
+ created_files = []
175
+
176
+ def _make_binary(
177
+ size: int = 1024,
178
+ pattern: bytes = None,
179
+ suffix: str = ".bin"
180
+ ) -> Path:
181
+ """
182
+ Create a temporary binary file.
183
+
184
+ Args:
185
+ size: File size in bytes
186
+ pattern: Optional byte pattern to repeat
187
+ suffix: File suffix
188
+
189
+ Returns:
190
+ Path to created binary file
191
+ """
192
+ if pattern is None:
193
+ # Create pseudo-random binary data
194
+ content = bytes(random.randint(0, 255) for _ in range(size))
195
+ else:
196
+ # Repeat pattern to reach size
197
+ repetitions = size // len(pattern) + 1
198
+ content = (pattern * repetitions)[:size]
199
+
200
+ with tempfile.NamedTemporaryFile(
201
+ mode='wb',
202
+ suffix=suffix,
203
+ delete=False
204
+ ) as f:
205
+ f.write(content)
206
+ path = Path(f.name)
207
+
208
+ created_files.append(path)
209
+ return path
210
+
211
+ yield _make_binary
212
+
213
+ # Cleanup
214
+ for path in created_files:
215
+ safe_delete(path, missing_ok=True)
216
+
217
+
218
+ @pytest.fixture
219
+ def temp_csv_file():
220
+ """
221
+ Create temporary CSV files for testing.
222
+
223
+ Returns:
224
+ Function that creates CSV files.
225
+ """
226
+ created_files = []
227
+
228
+ def _make_csv(
229
+ headers: list[str],
230
+ rows: list[list],
231
+ suffix: str = ".csv"
232
+ ) -> Path:
233
+ """
234
+ Create a temporary CSV file.
235
+
236
+ Args:
237
+ headers: Column headers
238
+ rows: Data rows
239
+ suffix: File suffix
240
+
241
+ Returns:
242
+ Path to created CSV file
243
+ """
244
+ with tempfile.NamedTemporaryFile(
245
+ mode='w',
246
+ suffix=suffix,
247
+ delete=False,
248
+ newline=''
249
+ ) as f:
250
+ writer = csv.writer(f)
251
+ writer.writerow(headers)
252
+ writer.writerows(rows)
253
+ path = Path(f.name)
254
+
255
+ created_files.append(path)
256
+ return path
257
+
258
+ yield _make_csv
259
+
260
+ # Cleanup
261
+ for path in created_files:
262
+ safe_delete(path, missing_ok=True)
263
+
264
+
265
+ @pytest.fixture
266
+ def temp_json_file():
267
+ """
268
+ Create temporary JSON files for testing.
269
+
270
+ Returns:
271
+ Function that creates JSON files.
272
+ """
273
+ created_files = []
274
+
275
+ def _make_json(
276
+ data: dict | list,
277
+ suffix: str = ".json",
278
+ indent: int = 2
279
+ ) -> Path:
280
+ """
281
+ Create a temporary JSON file.
282
+
283
+ Args:
284
+ data: JSON data to write
285
+ suffix: File suffix
286
+ indent: JSON indentation
287
+
288
+ Returns:
289
+ Path to created JSON file
290
+ """
291
+ with tempfile.NamedTemporaryFile(
292
+ mode='w',
293
+ suffix=suffix,
294
+ delete=False
295
+ ) as f:
296
+ json.dump(data, f, indent=indent)
297
+ path = Path(f.name)
298
+
299
+ created_files.append(path)
300
+ return path
301
+
302
+ yield _make_json
303
+
304
+ # Cleanup
305
+ for path in created_files:
306
+ safe_delete(path, missing_ok=True)
307
+
308
+
309
+ __all__ = [
310
+ "temp_file",
311
+ "temp_named_file",
312
+ "temp_file_with_content",
313
+ "temp_binary_file",
314
+ "temp_csv_file",
315
+ "temp_json_file",
316
+ ]
@@ -0,0 +1,107 @@
1
+ """
2
+ Directory-specific test fixtures.
3
+
4
+ Fixtures for creating temporary directories, nested structures,
5
+ and standard test directory layouts.
6
+ """
7
+
8
+ import tempfile
9
+ from pathlib import Path
10
+ from collections.abc import Generator
11
+
12
+ import pytest
13
+
14
+
15
+ @pytest.fixture
16
+ def temp_directory() -> Generator[Path, None, None]:
17
+ """
18
+ Create a temporary directory that's cleaned up after test.
19
+
20
+ Yields:
21
+ Path to the temporary directory.
22
+ """
23
+ with tempfile.TemporaryDirectory() as temp_dir:
24
+ yield Path(temp_dir)
25
+
26
+
27
+ @pytest.fixture
28
+ def test_files_structure() -> Generator[tuple[Path, Path], None, None]:
29
+ """
30
+ Create standard test file structure with files and subdirectories.
31
+
32
+ Creates:
33
+ - source/
34
+ - file1.txt (contains "Content 1")
35
+ - file2.txt (contains "Content 2")
36
+ - subdir/
37
+ - file3.txt (contains "Content 3")
38
+
39
+ Yields:
40
+ Tuple of (temp_path, source_path)
41
+ """
42
+ with tempfile.TemporaryDirectory() as temp_dir:
43
+ path = Path(temp_dir)
44
+ source = path / "source"
45
+ source.mkdir()
46
+
47
+ # Create test files
48
+ (source / "file1.txt").write_text("Content 1")
49
+ (source / "file2.txt").write_text("Content 2")
50
+
51
+ # Create subdirectory with files
52
+ subdir = source / "subdir"
53
+ subdir.mkdir()
54
+ (subdir / "file3.txt").write_text("Content 3")
55
+
56
+ yield path, source
57
+
58
+
59
+ @pytest.fixture
60
+ def nested_directory_structure() -> Generator[Path, None, None]:
61
+ """
62
+ Create a deeply nested directory structure for testing.
63
+
64
+ Creates:
65
+ - level1/
66
+ - level2/
67
+ - level3/
68
+ - deep_file.txt
69
+ - file_l2.txt
70
+ - file_l1.txt
71
+
72
+ Yields:
73
+ Path to the root of the structure.
74
+ """
75
+ with tempfile.TemporaryDirectory() as temp_dir:
76
+ root = Path(temp_dir)
77
+
78
+ # Create nested structure
79
+ deep_dir = root / "level1" / "level2" / "level3"
80
+ deep_dir.mkdir(parents=True)
81
+
82
+ # Add files at different levels
83
+ (root / "file_l1.txt").write_text("Level 1 file")
84
+ (root / "level1" / "file_l2.txt").write_text("Level 2 file")
85
+ (deep_dir / "deep_file.txt").write_text("Deep file")
86
+
87
+ yield root
88
+
89
+
90
+ @pytest.fixture
91
+ def empty_directory() -> Generator[Path, None, None]:
92
+ """
93
+ Create an empty temporary directory.
94
+
95
+ Yields:
96
+ Path to an empty directory.
97
+ """
98
+ with tempfile.TemporaryDirectory() as temp_dir:
99
+ yield Path(temp_dir)
100
+
101
+
102
+ __all__ = [
103
+ "temp_directory",
104
+ "test_files_structure",
105
+ "nested_directory_structure",
106
+ "empty_directory",
107
+ ]
@@ -0,0 +1,52 @@
1
+ """
2
+ File and Directory Test Fixtures.
3
+
4
+ Core file testing fixtures with re-exports from specialized modules.
5
+ Common fixtures for testing file operations, creating temporary directories,
6
+ and standard test file structures used across the provide-io ecosystem.
7
+ """
8
+
9
+ # Re-export all fixtures from specialized modules
10
+ from provide.foundation.testing.file.directory_fixtures import (
11
+ temp_directory,
12
+ test_files_structure,
13
+ nested_directory_structure,
14
+ empty_directory,
15
+ )
16
+
17
+ from provide.foundation.testing.file.special_fixtures import (
18
+ binary_file,
19
+ readonly_file,
20
+ temp_symlink,
21
+ temp_executable_file,
22
+ )
23
+
24
+ from provide.foundation.testing.file.content_fixtures import (
25
+ temp_file,
26
+ temp_named_file,
27
+ temp_file_with_content,
28
+ temp_binary_file,
29
+ temp_csv_file,
30
+ temp_json_file,
31
+ )
32
+
33
+
34
+ __all__ = [
35
+ # Directory fixtures
36
+ "temp_directory",
37
+ "test_files_structure",
38
+ "nested_directory_structure",
39
+ "empty_directory",
40
+ # Special file fixtures
41
+ "binary_file",
42
+ "readonly_file",
43
+ "temp_symlink",
44
+ "temp_executable_file",
45
+ # Content-based fixtures
46
+ "temp_file",
47
+ "temp_named_file",
48
+ "temp_file_with_content",
49
+ "temp_binary_file",
50
+ "temp_csv_file",
51
+ "temp_json_file",
52
+ ]
@@ -0,0 +1,153 @@
1
+ """
2
+ Special file test fixtures.
3
+
4
+ Fixtures for creating specialized files like binary files, read-only files,
5
+ symbolic links, and executable files.
6
+ """
7
+
8
+ import stat
9
+ import tempfile
10
+ from pathlib import Path
11
+ from collections.abc import Generator
12
+
13
+ import pytest
14
+
15
+ from provide.foundation.file.safe import safe_delete
16
+
17
+
18
+ @pytest.fixture
19
+ def binary_file() -> Generator[Path, None, None]:
20
+ """
21
+ Create a temporary binary file for testing.
22
+
23
+ Yields:
24
+ Path to a binary file containing sample binary data.
25
+ """
26
+ with tempfile.NamedTemporaryFile(mode='wb', suffix='.bin', delete=False) as f:
27
+ # Write some binary data
28
+ f.write(b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09')
29
+ f.write(b'\xFF\xFE\xFD\xFC\xFB\xFA\xF9\xF8\xF7\xF6')
30
+ path = Path(f.name)
31
+
32
+ yield path
33
+ safe_delete(path, missing_ok=True)
34
+
35
+
36
+ @pytest.fixture
37
+ def readonly_file() -> Generator[Path, None, None]:
38
+ """
39
+ Create a read-only file for permission testing.
40
+
41
+ Yields:
42
+ Path to a read-only file.
43
+ """
44
+ with tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False) as f:
45
+ f.write("Read-only content")
46
+ path = Path(f.name)
47
+
48
+ # Make file read-only
49
+ path.chmod(0o444)
50
+
51
+ yield path
52
+
53
+ # Restore write permission for cleanup
54
+ path.chmod(0o644)
55
+ safe_delete(path, missing_ok=True)
56
+
57
+
58
+ @pytest.fixture
59
+ def temp_symlink():
60
+ """
61
+ Create temporary symbolic links for testing.
62
+
63
+ Returns:
64
+ Function that creates symbolic links.
65
+ """
66
+ created_links = []
67
+
68
+ def _make_symlink(
69
+ target: Path | str,
70
+ link_name: Path | str = None
71
+ ) -> Path:
72
+ """
73
+ Create a temporary symbolic link.
74
+
75
+ Args:
76
+ target: Target path for the symlink
77
+ link_name: Optional link name (auto-generated if None)
78
+
79
+ Returns:
80
+ Path to created symlink
81
+ """
82
+ target = Path(target)
83
+
84
+ if link_name is None:
85
+ with tempfile.NamedTemporaryFile(delete=True) as f:
86
+ link_name = Path(f.name + "_link")
87
+ else:
88
+ link_name = Path(link_name)
89
+
90
+ link_name.symlink_to(target)
91
+ created_links.append(link_name)
92
+
93
+ return link_name
94
+
95
+ yield _make_symlink
96
+
97
+ # Cleanup
98
+ for link in created_links:
99
+ safe_delete(link, missing_ok=True)
100
+
101
+
102
+ @pytest.fixture
103
+ def temp_executable_file():
104
+ """
105
+ Create temporary executable files for testing.
106
+
107
+ Returns:
108
+ Function that creates executable files.
109
+ """
110
+ created_files = []
111
+
112
+ def _make_executable(
113
+ content: str = "#!/bin/sh\necho 'test'\n",
114
+ suffix: str = ".sh"
115
+ ) -> Path:
116
+ """
117
+ Create a temporary executable file.
118
+
119
+ Args:
120
+ content: Script content
121
+ suffix: File suffix
122
+
123
+ Returns:
124
+ Path to created executable file
125
+ """
126
+ with tempfile.NamedTemporaryFile(
127
+ mode='w',
128
+ suffix=suffix,
129
+ delete=False
130
+ ) as f:
131
+ f.write(content)
132
+ path = Path(f.name)
133
+
134
+ # Make executable
135
+ current = path.stat().st_mode
136
+ path.chmod(current | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH)
137
+
138
+ created_files.append(path)
139
+ return path
140
+
141
+ yield _make_executable
142
+
143
+ # Cleanup
144
+ for path in created_files:
145
+ safe_delete(path, missing_ok=True)
146
+
147
+
148
+ __all__ = [
149
+ "binary_file",
150
+ "readonly_file",
151
+ "temp_symlink",
152
+ "temp_executable_file",
153
+ ]