bear-utils 0.8.19__tar.gz → 0.8.21__tar.gz
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.
- {bear_utils-0.8.19 → bear_utils-0.8.21}/.bumpversion.cfg +1 -1
- {bear_utils-0.8.19 → bear_utils-0.8.21}/PKG-INFO +4 -2
- {bear_utils-0.8.19 → bear_utils-0.8.21}/README.md +1 -1
- {bear_utils-0.8.19 → bear_utils-0.8.21}/pyproject.toml +8 -1
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/events/events_module.py +1 -1
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/extras/_async_helpers.py +11 -6
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/extras/responses/function_response.py +17 -52
- {bear_utils-0.8.19 → bear_utils-0.8.21}/tests/test_function_response.py +71 -3
- {bear_utils-0.8.19 → bear_utils-0.8.21}/uv.lock +15 -1
- {bear_utils-0.8.19 → bear_utils-0.8.21}/.gitignore +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/.python-version +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/AGENTS.md +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/config/coverage.ini +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/config/default.toml +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/config/git-changelog.toml +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/config/pytest.ini +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/config/ruff.toml +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/config/vscode/launch.json +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/config/vscode/settings.json +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/config/vscode/tasks.json +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/directory_structure.txt +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/directory_structure.xml +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/maskfile.md +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/noxfile.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/__init__.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/__main__.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/_internal/__init__.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/_internal/cli.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/_internal/debug.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/ai/__init__.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/ai/ai_helpers/__init__.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/ai/ai_helpers/_common.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/ai/ai_helpers/_config.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/ai/ai_helpers/_parsers.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/ai/ai_helpers/_types.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/cache/__init__.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/cli/__init__.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/cli/commands.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/cli/prompt_helpers.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/cli/shell/__init__.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/cli/shell/_base_command.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/cli/shell/_base_shell.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/cli/shell/_common.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/config/__init__.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/config/config_manager.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/config/dir_manager.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/config/settings_manager.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/constants/__init__.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/constants/_exceptions.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/constants/_lazy_typing.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/constants/date_related.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/constants/server.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/constants/time_related.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/database/__init__.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/database/_db_manager.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/events/__init__.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/events/events_class.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/extras/__init__.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/extras/_tools.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/extras/platform_utils.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/extras/responses/__init__.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/extras/wrappers/__init__.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/extras/wrappers/add_methods.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/files/__init__.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/files/file_handlers/__init__.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/files/file_handlers/_base_file_handler.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/files/file_handlers/file_handler_factory.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/files/file_handlers/json_file_handler.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/files/file_handlers/log_file_handler.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/files/file_handlers/toml_file_handler.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/files/file_handlers/txt_file_handler.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/files/file_handlers/yaml_file_handler.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/files/ignore_parser.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/graphics/__init__.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/graphics/bear_gradient.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/graphics/image_helpers.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/gui/__init__.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/gui/gui_tools/__init__.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/gui/gui_tools/_settings.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/gui/gui_tools/_types.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/gui/gui_tools/qt_app.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/gui/gui_tools/qt_color_picker.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/gui/gui_tools/qt_file_handler.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/gui/gui_tools/qt_input_dialog.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/logger_manager/__init__.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/logger_manager/_common.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/logger_manager/_console_junk.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/logger_manager/_log_level.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/logger_manager/_styles.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/logger_manager/logger_protocol.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/logger_manager/loggers/__init__.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/logger_manager/loggers/_level_sin.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/logger_manager/loggers/base_logger.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/logger_manager/loggers/base_logger.pyi +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/logger_manager/loggers/basic_logger/__init__.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/logger_manager/loggers/basic_logger/logger.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/logger_manager/loggers/basic_logger/logger.pyi +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/logger_manager/loggers/buffer_logger.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/logger_manager/loggers/console_logger.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/logger_manager/loggers/console_logger.pyi +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/logger_manager/loggers/fastapi_logger.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/logger_manager/loggers/file_logger.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/logger_manager/loggers/simple_logger.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/logger_manager/loggers/sub_logger.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/logger_manager/loggers/sub_logger.pyi +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/monitoring/__init__.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/monitoring/_common.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/monitoring/host_monitor.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/time/__init__.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/tests/__init__.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/tests/test_add_ord_suffix.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/tests/test_clipboard.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/tests/test_database_manager.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/tests/test_default_shell.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/tests/test_gradient.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/tests/test_logger.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/tests/test_platform_utils.py +0 -0
- {bear_utils-0.8.19 → bear_utils-0.8.21}/tests/test_prompt_helpers.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: bear-utils
|
3
|
-
Version: 0.8.
|
3
|
+
Version: 0.8.21
|
4
4
|
Summary: Various utilities for Bear programmers, including a rich logging utility, a disk cache, and a SQLite database wrapper amongst other things.
|
5
5
|
Author-email: chaz <bright.lid5647@fastmail.com>
|
6
6
|
Requires-Python: >=3.12
|
@@ -20,9 +20,11 @@ Requires-Dist: sqlalchemy<3.0.0,>=2.0.40
|
|
20
20
|
Requires-Dist: tinydb>=4.8.2
|
21
21
|
Requires-Dist: toml>=0.10.2
|
22
22
|
Requires-Dist: uvicorn>=0.35.0
|
23
|
+
Provides-Extra: gui
|
24
|
+
Requires-Dist: pyqt6>=6.9.0; extra == 'gui'
|
23
25
|
Description-Content-Type: text/markdown
|
24
26
|
|
25
|
-
# Bear Utils v# Bear Utils v0.8.
|
27
|
+
# Bear Utils v# Bear Utils v0.8.21
|
26
28
|
|
27
29
|
Personal set of tools and utilities for Python projects, focusing on modularity and ease of use. This library includes components for caching, database management, logging, time handling, file operations, CLI prompts, image processing, clipboard interaction, gradient utilities, event systems, and async helpers.
|
28
30
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Bear Utils v# Bear Utils v0.8.
|
1
|
+
# Bear Utils v# Bear Utils v0.8.21
|
2
2
|
|
3
3
|
Personal set of tools and utilities for Python projects, focusing on modularity and ease of use. This library includes components for caching, database management, logging, time handling, file operations, CLI prompts, image processing, clipboard interaction, gradient utilities, event systems, and async helpers.
|
4
4
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
[project]
|
2
2
|
name = "bear-utils"
|
3
|
-
version = "0.8.
|
3
|
+
version = "0.8.21"
|
4
4
|
description = "Various utilities for Bear programmers, including a rich logging utility, a disk cache, and a SQLite database wrapper amongst other things."
|
5
5
|
authors = [{ name = "chaz", email = "bright.lid5647@fastmail.com" }]
|
6
6
|
readme = "README.md"
|
@@ -24,6 +24,11 @@ dependencies = [
|
|
24
24
|
"bear-epoch-time>=1.1.1",
|
25
25
|
]
|
26
26
|
|
27
|
+
[project.optional-dependencies]
|
28
|
+
gui = [
|
29
|
+
"pyqt6>=6.9.0",
|
30
|
+
]
|
31
|
+
|
27
32
|
[build-system]
|
28
33
|
requires = ["hatchling"]
|
29
34
|
build-backend = "hatchling.build"
|
@@ -33,6 +38,7 @@ maintain = [
|
|
33
38
|
"git-changelog>=2.5",
|
34
39
|
"yore>=0.3.3",
|
35
40
|
"griffe>=1.7.3",
|
41
|
+
"pytest-asyncio>=1.0.0",
|
36
42
|
]
|
37
43
|
ci = [
|
38
44
|
"ruff>=0.4",
|
@@ -58,6 +64,7 @@ default-groups = ["maintain", "ci"]
|
|
58
64
|
testpaths = ["tests"]
|
59
65
|
pythonpath = ["src"]
|
60
66
|
addopts = "-v"
|
67
|
+
asyncio_mode = "auto"
|
61
68
|
markers = [
|
62
69
|
"visual: marks tests as visual verification tests (deselect with '-m \"not visual\"')"
|
63
70
|
]
|
@@ -50,7 +50,7 @@ def dispatch_event(name: str, *args, **kwargs) -> Any | None:
|
|
50
50
|
results: list[Any] = []
|
51
51
|
for func in _event_registry.get(name, []):
|
52
52
|
if is_async_function(func):
|
53
|
-
result: Any = asyncio.run(func(*args, **kwargs))
|
53
|
+
result: Any = asyncio.run(func(*args, **kwargs)) # FIXME: This will crash if called from an async context
|
54
54
|
else:
|
55
55
|
result: Any = func(*args, **kwargs)
|
56
56
|
results.append(result)
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import asyncio
|
2
|
-
from asyncio import AbstractEventLoop
|
2
|
+
from asyncio import AbstractEventLoop
|
3
3
|
from collections.abc import Callable
|
4
|
+
from contextlib import suppress
|
4
5
|
import inspect
|
5
6
|
|
6
7
|
|
@@ -17,11 +18,15 @@ def is_async_function(func: Callable) -> bool:
|
|
17
18
|
|
18
19
|
|
19
20
|
def in_async_loop() -> bool:
|
20
|
-
"""Check if the current context is already in an async loop.
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
"""Check if the current context is already in an async loop.
|
22
|
+
|
23
|
+
Returns:
|
24
|
+
bool: True if an async loop is running, False otherwise.
|
25
|
+
"""
|
26
|
+
loop: AbstractEventLoop | None = None
|
27
|
+
with suppress(RuntimeError):
|
28
|
+
loop = asyncio.get_running_loop()
|
29
|
+
return loop.is_running() if loop else False
|
25
30
|
|
26
31
|
|
27
32
|
def gimmie_async_loop() -> AbstractEventLoop:
|
{bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/extras/responses/function_response.py
RENAMED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
from __future__ import annotations
|
4
4
|
|
5
|
-
import asyncio
|
6
5
|
from collections.abc import Callable
|
7
6
|
import json
|
8
7
|
from subprocess import CompletedProcess
|
@@ -251,19 +250,19 @@ class FunctionResponse(BaseModel):
|
|
251
250
|
) -> Self:
|
252
251
|
"""Append additional content to the existing content."""
|
253
252
|
try:
|
254
|
-
if
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
if returncode
|
253
|
+
if content is not None:
|
254
|
+
if isinstance(content, FunctionResponse):
|
255
|
+
self._handle_function_response(func_response=content)
|
256
|
+
self.number_of_tasks += 1
|
257
|
+
elif isinstance(content, CompletedProcess):
|
258
|
+
self._handle_completed_process(result=content)
|
259
|
+
self.number_of_tasks += 1
|
260
|
+
elif isinstance(content, (str | list)) and content:
|
261
|
+
self._add_content(content=content)
|
262
|
+
self.number_of_tasks += 1
|
263
|
+
if error is not None and isinstance(error, (str | list)):
|
264
|
+
self._add_error(error=error)
|
265
|
+
if isinstance(returncode, int):
|
267
266
|
self.returncode = returncode
|
268
267
|
if isinstance(extra, dict):
|
269
268
|
self.extra.update(extra)
|
@@ -283,10 +282,12 @@ class FunctionResponse(BaseModel):
|
|
283
282
|
|
284
283
|
async def loop_logging(messages: list[str], func: Callable) -> None:
|
285
284
|
for msg in messages:
|
285
|
+
if msg == "":
|
286
|
+
continue
|
286
287
|
if is_async_function(func):
|
287
|
-
await func(f"{
|
288
|
+
await func(f"{msg}")
|
288
289
|
else:
|
289
|
-
func(f"{
|
290
|
+
func(f"{msg}")
|
290
291
|
|
291
292
|
async def _log_messages(
|
292
293
|
content: str | list[str], error: str | list[str], info_func: Callable, error_func: Callable
|
@@ -375,39 +376,3 @@ def fail(
|
|
375
376
|
) -> FunctionResponse:
|
376
377
|
"""Create a failed FunctionResponse."""
|
377
378
|
return FunctionResponse().fail(content=content, error=error, returncode=returncode, **kwargs)
|
378
|
-
|
379
|
-
|
380
|
-
async def testing_already_in_loop() -> None:
|
381
|
-
"""Test function to check if already in an event loop."""
|
382
|
-
# from rich import inspect
|
383
|
-
|
384
|
-
response = FunctionResponse(name="example_function", logger=SimpleLogger())
|
385
|
-
try:
|
386
|
-
response.add(content=["Test content", "test 1234"], error="Test error", log_output=True)
|
387
|
-
response.done(to_dict=True)
|
388
|
-
except RuntimeError as e:
|
389
|
-
print(f"Already in an event loop: {e}")
|
390
|
-
else:
|
391
|
-
print("Successfully added content and error without issues.")
|
392
|
-
# inspect(response)
|
393
|
-
|
394
|
-
|
395
|
-
def testing_not_in_loop() -> None:
|
396
|
-
"""Test function to check if not in an event loop."""
|
397
|
-
response = FunctionResponse(name="example_function", logger=SimpleLogger())
|
398
|
-
try:
|
399
|
-
response.add(content=["Test content", "test 1234"], error="Test error", log_output=True)
|
400
|
-
response.done(to_dict=True)
|
401
|
-
except RuntimeError as e:
|
402
|
-
print(f"Not in an event loop: {e}")
|
403
|
-
else:
|
404
|
-
print("Successfully added content and error without issues.")
|
405
|
-
|
406
|
-
|
407
|
-
if __name__ == "__main__":
|
408
|
-
# Example usage
|
409
|
-
|
410
|
-
from bear_utils.logger_manager import SimpleLogger
|
411
|
-
|
412
|
-
asyncio.run(testing_already_in_loop())
|
413
|
-
testing_not_in_loop()
|
@@ -13,6 +13,42 @@ from bear_utils.extras.responses.function_response import (
|
|
13
13
|
fail,
|
14
14
|
success,
|
15
15
|
)
|
16
|
+
from bear_utils.logger_manager import SimpleLogger as AsyncLogger
|
17
|
+
|
18
|
+
|
19
|
+
class MockLogger:
|
20
|
+
def __init__(self):
|
21
|
+
"""Initialize mock logger."""
|
22
|
+
self.messages = []
|
23
|
+
|
24
|
+
def log(self, level: str, msg: object, *args, **kwargs) -> None:
|
25
|
+
"""Mock logging method."""
|
26
|
+
msg = f"{level.upper()}: {msg}"
|
27
|
+
if args:
|
28
|
+
msg = f"{msg} {' '.join(map(str, args))}"
|
29
|
+
if kwargs:
|
30
|
+
msg = f"{msg} {kwargs}"
|
31
|
+
self.messages.append(msg)
|
32
|
+
|
33
|
+
def info(self, msg: object, *args, **kwargs) -> None:
|
34
|
+
"""Mock info logging method."""
|
35
|
+
self.log("info", msg, *args, **kwargs)
|
36
|
+
|
37
|
+
def error(self, msg: object, *args, **kwargs) -> None:
|
38
|
+
"""Mock error logging method."""
|
39
|
+
self.log("error", msg, *args, **kwargs)
|
40
|
+
|
41
|
+
def debug(self, msg: object, *args, **kwargs) -> None:
|
42
|
+
"""Mock debug logging method."""
|
43
|
+
self.log("debug", msg, *args, **kwargs)
|
44
|
+
|
45
|
+
def warning(self, msg: object, *args, **kwargs) -> None:
|
46
|
+
"""Mock warning logging method."""
|
47
|
+
self.log("warning", msg, *args, **kwargs)
|
48
|
+
|
49
|
+
def get_messages(self) -> list[str]:
|
50
|
+
"""Retrieve all logged messages."""
|
51
|
+
return self.messages
|
16
52
|
|
17
53
|
|
18
54
|
class TestFunctionResponseCreation:
|
@@ -166,8 +202,22 @@ class TestFluentAPI:
|
|
166
202
|
|
167
203
|
def test_successful_method(self):
|
168
204
|
"""Test successful() method."""
|
169
|
-
|
170
|
-
|
205
|
+
mock_logger = MockLogger()
|
206
|
+
response = FunctionResponse(name="test", logger=mock_logger)
|
207
|
+
result = response.successful("operation completed", log_output=True)
|
208
|
+
|
209
|
+
assert result is response # Returns self for chaining
|
210
|
+
assert response.content == ["operation completed"]
|
211
|
+
assert response.returncode == 0
|
212
|
+
assert response.success is True
|
213
|
+
messages = mock_logger.get_messages()
|
214
|
+
assert len(messages) == 1
|
215
|
+
assert "INFO: operation completed" in messages
|
216
|
+
|
217
|
+
async def test_async_successful_method(self):
|
218
|
+
"""Test successful() method."""
|
219
|
+
response = FunctionResponse(name="test", logger=AsyncLogger())
|
220
|
+
result = response.successful("operation completed", log_output=True)
|
171
221
|
|
172
222
|
assert result is response # Returns self for chaining
|
173
223
|
assert response.content == ["operation completed"]
|
@@ -192,7 +242,7 @@ class TestFluentAPI:
|
|
192
242
|
.add(content="second operation")
|
193
243
|
.add(error="minor warning")
|
194
244
|
)
|
195
|
-
|
245
|
+
print(response)
|
196
246
|
assert response.content == ["first operation", "second operation"]
|
197
247
|
assert response.error == ["minor warning"]
|
198
248
|
assert response.returncode == 0
|
@@ -296,6 +346,24 @@ class TestSubTaskMethod:
|
|
296
346
|
# Should still add content, just without name prefix
|
297
347
|
assert "content without name" in main_response.content
|
298
348
|
|
349
|
+
def test_async_sub_task(self):
|
350
|
+
"""Test sub_task with async logger."""
|
351
|
+
main_response = FunctionResponse(name="main_task", logger=AsyncLogger())
|
352
|
+
main_response.sub_task(name="async_subtask", content="async content")
|
353
|
+
|
354
|
+
assert main_response.number_of_tasks == 1
|
355
|
+
assert main_response.content == ["async_subtask: async content"]
|
356
|
+
assert isinstance(main_response.logger, AsyncLogger)
|
357
|
+
|
358
|
+
async def test_async_sub_task_with_async_logger(self):
|
359
|
+
"""Test sub_task with async logger with an async context."""
|
360
|
+
main_response = FunctionResponse(name="main_task", logger=AsyncLogger())
|
361
|
+
main_response.sub_task(name="async_subtask", content="async content")
|
362
|
+
|
363
|
+
assert main_response.number_of_tasks == 1
|
364
|
+
assert main_response.content == ["async_subtask: async content"]
|
365
|
+
assert isinstance(main_response.logger, AsyncLogger)
|
366
|
+
|
299
367
|
|
300
368
|
class TestAddMethod:
|
301
369
|
"""Test the complex add() method."""
|
@@ -73,7 +73,7 @@ wheels = [
|
|
73
73
|
|
74
74
|
[[package]]
|
75
75
|
name = "bear-utils"
|
76
|
-
version = "0.8.
|
76
|
+
version = "0.8.19"
|
77
77
|
source = { editable = "." }
|
78
78
|
dependencies = [
|
79
79
|
{ name = "bear-epoch-time" },
|
@@ -114,6 +114,7 @@ gui = [
|
|
114
114
|
maintain = [
|
115
115
|
{ name = "git-changelog" },
|
116
116
|
{ name = "griffe" },
|
117
|
+
{ name = "pytest-asyncio" },
|
117
118
|
{ name = "yore" },
|
118
119
|
]
|
119
120
|
|
@@ -155,6 +156,7 @@ gui = [{ name = "pyqt6", specifier = ">=6.9.0" }]
|
|
155
156
|
maintain = [
|
156
157
|
{ name = "git-changelog", specifier = ">=2.5" },
|
157
158
|
{ name = "griffe", specifier = ">=1.7.3" },
|
159
|
+
{ name = "pytest-asyncio", specifier = ">=1.0.0" },
|
158
160
|
{ name = "yore", specifier = ">=0.3.3" },
|
159
161
|
]
|
160
162
|
|
@@ -1033,6 +1035,18 @@ wheels = [
|
|
1033
1035
|
{ url = "https://files.pythonhosted.org/packages/2f/de/afa024cbe022b1b318a3d224125aa24939e99b4ff6f22e0ba639a2eaee47/pytest-8.4.0-py3-none-any.whl", hash = "sha256:f40f825768ad76c0977cbacdf1fd37c6f7a468e460ea6a0636078f8972d4517e", size = 363797, upload_time = "2025-06-02T17:36:27.859Z" },
|
1034
1036
|
]
|
1035
1037
|
|
1038
|
+
[[package]]
|
1039
|
+
name = "pytest-asyncio"
|
1040
|
+
version = "1.0.0"
|
1041
|
+
source = { registry = "https://pypi.org/simple/" }
|
1042
|
+
dependencies = [
|
1043
|
+
{ name = "pytest" },
|
1044
|
+
]
|
1045
|
+
sdist = { url = "https://files.pythonhosted.org/packages/d0/d4/14f53324cb1a6381bef29d698987625d80052bb33932d8e7cbf9b337b17c/pytest_asyncio-1.0.0.tar.gz", hash = "sha256:d15463d13f4456e1ead2594520216b225a16f781e144f8fdf6c5bb4667c48b3f", size = 46960, upload_time = "2025-05-26T04:54:40.484Z" }
|
1046
|
+
wheels = [
|
1047
|
+
{ url = "https://files.pythonhosted.org/packages/30/05/ce271016e351fddc8399e546f6e23761967ee09c8c568bbfbecb0c150171/pytest_asyncio-1.0.0-py3-none-any.whl", hash = "sha256:4f024da9f1ef945e680dc68610b52550e36590a67fd31bb3b4943979a1f90ef3", size = 15976, upload_time = "2025-05-26T04:54:39.035Z" },
|
1048
|
+
]
|
1049
|
+
|
1036
1050
|
[[package]]
|
1037
1051
|
name = "pytest-cov"
|
1038
1052
|
version = "6.2.1"
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/files/file_handlers/_base_file_handler.py
RENAMED
File without changes
|
{bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/files/file_handlers/file_handler_factory.py
RENAMED
File without changes
|
{bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/files/file_handlers/json_file_handler.py
RENAMED
File without changes
|
{bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/files/file_handlers/log_file_handler.py
RENAMED
File without changes
|
{bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/files/file_handlers/toml_file_handler.py
RENAMED
File without changes
|
{bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/files/file_handlers/txt_file_handler.py
RENAMED
File without changes
|
{bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/files/file_handlers/yaml_file_handler.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/logger_manager/loggers/base_logger.py
RENAMED
File without changes
|
{bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/logger_manager/loggers/base_logger.pyi
RENAMED
File without changes
|
File without changes
|
{bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/logger_manager/loggers/basic_logger/logger.py
RENAMED
File without changes
|
File without changes
|
{bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/logger_manager/loggers/buffer_logger.py
RENAMED
File without changes
|
{bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/logger_manager/loggers/console_logger.py
RENAMED
File without changes
|
{bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/logger_manager/loggers/console_logger.pyi
RENAMED
File without changes
|
{bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/logger_manager/loggers/fastapi_logger.py
RENAMED
File without changes
|
{bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/logger_manager/loggers/file_logger.py
RENAMED
File without changes
|
{bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/logger_manager/loggers/simple_logger.py
RENAMED
File without changes
|
File without changes
|
{bear_utils-0.8.19 → bear_utils-0.8.21}/src/bear_utils/logger_manager/loggers/sub_logger.pyi
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|