Skip to content

Commit 06eea19

Browse files
committed
Merge dev into main
2 parents 2d4d5a8 + e73a19e commit 06eea19

File tree

7 files changed

+26
-27
lines changed

7 files changed

+26
-27
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# OSBot-Utils
22

3-
![Current Release](https://img.shields.io/badge/release-v3.48.0-blue)
3+
![Current Release](https://img.shields.io/badge/release-v3.48.1-blue)
44
![Python](https://img.shields.io/badge/python-3.8+-green)
55
![Type-Safe](https://img.shields.io/badge/Type--Safe-✓-brightgreen)
66
![Caching](https://img.shields.io/badge/Caching-Built--In-orange)

osbot_utils/utils/Objects.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -288,15 +288,13 @@ def serialize_to_dict(obj):
288288
elif isinstance(obj, (set, frozenset)):
289289
return [serialize_to_dict(item) for item in obj]
290290
elif isinstance(obj, dict):
291-
serialized_dict = {} # todo: refactor to separate method
291+
serialized_dict = {}
292292
for key, value in obj.items():
293-
if isinstance(key, type): # Handle type keys by converting to fully qualified string
294-
serialized_key = f"{key.__module__}.{key.__name__}"
295-
else:
296-
serialized_key = key
297-
serialized_dict[serialized_key] = serialize_to_dict(value) # Recursively serialize the value
293+
serialized_key = serialize_to_dict(key) # Recursively handle ALL key types
294+
serialized_value = serialize_to_dict(value)
295+
serialized_dict[serialized_key] = serialized_value
298296
return serialized_dict
299-
#return {key: serialize_to_dict(value) for key, value in obj.items()}
297+
300298
elif callable(obj) and not isinstance(obj, type): # For functions/lambdas, return a string representation
301299
if hasattr(obj, '__name__'):
302300
return obj.__name__

osbot_utils/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v3.48.0
1+
v3.48.1

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "osbot_utils"
3-
version = "v3.48.0"
3+
version = "v3.48.1"
44
description = "OWASP Security Bot - Utils"
55
authors = ["Dinis Cruz <[email protected]>"]
66
license = "MIT"

tests/unit/type_safe/primitives/domains/identifiers/test_Cache_Id.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
from typing import List
2-
from unittest import TestCase
31
import pytest
4-
from osbot_utils.testing.__ import __
5-
from osbot_utils.type_safe.Type_Safe import Type_Safe
6-
from osbot_utils.type_safe.Type_Safe__Primitive import Type_Safe__Primitive
7-
from osbot_utils.type_safe.primitives.domains.identifiers.Cache_Id import Cache_Id
2+
from typing import List
3+
from unittest import TestCase
4+
from osbot_utils.testing.__ import __
5+
from osbot_utils.type_safe.Type_Safe import Type_Safe
6+
from osbot_utils.type_safe.Type_Safe__Primitive import Type_Safe__Primitive
7+
from osbot_utils.type_safe.primitives.domains.identifiers.Cache_Id import Cache_Id
88
from osbot_utils.type_safe.primitives.domains.identifiers.Random_Guid import Random_Guid
99
from osbot_utils.type_safe.type_safe_core.collections.Type_Safe__List import Type_Safe__List
10-
from osbot_utils.utils.Json import json_to_str, json_round_trip
11-
from osbot_utils.utils.Misc import is_guid
12-
from osbot_utils.utils.Objects import base_classes
10+
from osbot_utils.utils.Json import json_to_str, json_round_trip
11+
from osbot_utils.utils.Misc import is_guid
12+
from osbot_utils.utils.Objects import base_classes
1313

1414

1515
class test_Cache_Id(TestCase):
@@ -80,7 +80,7 @@ def test__init__validates_like_random_guid(self):
8080
# ═══════════════════════════════════════════════════════════════════════════════
8181

8282
def test__is_string_subclass(self): # Test that Cache_Id is a string
83-
cache_id = Cache_Id()
83+
cache_id = Cache_Id(Random_Guid())
8484

8585
assert isinstance(cache_id, str)
8686
assert isinstance(cache_id, Random_Guid)

tests/unit/type_safe/primitives/domains/identifiers/test_Graph_Id.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ def test__init__with_bad(self):
6161
# ═══════════════════════════════════════════════════════════════════════════════
6262

6363
def test__is_string_subclass(self): # Test that Graph_Id is a string
64-
graph_id = Graph_Id()
64+
graph_id = Graph_Id(Obj_Id())
6565

6666
assert isinstance(graph_id, str )
6767
assert isinstance(graph_id, Graph_Id )
6868

6969
def test__can_be_used_as_string(self): # Test string operations work
70-
graph_id = Graph_Id()
70+
graph_id = Graph_Id(Obj_Id())
7171

7272
assert graph_id.upper() == graph_id.upper() # String methods work
7373
assert graph_id.lower() == graph_id.lower()
@@ -130,7 +130,7 @@ def test__multiple_empty_instances(self):
130130
assert type(empty) is Graph_Id
131131

132132
def test__use_in_dict_key(self): # Test Graph_Id can be used as dict key
133-
graph_id = Graph_Id()
133+
graph_id = Graph_Id(Obj_Id())
134134
data = {graph_id: 'test_value'}
135135

136136
assert data[graph_id] == 'test_value'

tests/unit/type_safe/type_safe_core/steps/test_perf__Type_Safe__Step__Set_Attr.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def setUpClass(cls): #
2727
cls.time_8_kns = 8_000
2828
cls.time_9_kns = 9_000
2929
cls.time_10_kns = 10_000
30+
cls.time_20_kns = 20_000
3031

3132
def test_simple_setattr(self): # Test simple attribute setting
3233
class SimpleClass:
@@ -59,8 +60,8 @@ def set_dict_attr(): # Tes
5960
type_safe_step_set_attr.setattr(obj, obj, "dict_val", {"key": "value"})
6061

6162
with Performance_Measure__Session() as session:
62-
session.measure(set_list_attr).assert_time__less_than(self.time_10_kns)
63-
session.measure(set_dict_attr).assert_time__less_than(self.time_10_kns)
63+
session.measure(set_list_attr).assert_time__less_than(self.time_20_kns) # was 10k but was failing in some python version in GH Actions
64+
session.measure(set_dict_attr).assert_time__less_than(self.time_20_kns)
6465

6566
def test_union_setattr(self): # Test union type attribute setting
6667
class UnionClass:
@@ -120,7 +121,7 @@ def set_dict_convert(): # Te
120121
with Performance_Measure__Session() as session:
121122
session.measure(set_str_from_int ).assert_time__less_than(self.time_10_kns)
122123
session.measure(set_int_from_str ).assert_time__less_than(self.time_10_kns)
123-
session.measure(set_dict_convert ).assert_time__less_than(self.time_10_kns)
124+
session.measure(set_dict_convert ).assert_time__less_than(self.time_20_kns)
124125

125126
def test_error_cases(self): # Test error handling performance
126127
class ErrorClass:
@@ -144,4 +145,4 @@ def set_none_value(): # Te
144145

145146
with Performance_Measure__Session() as session:
146147
session.measure(set_wrong_type ).assert_time__less_than(self.time_6_kns)
147-
session.measure(set_none_value ).assert_time__less_than(self.time_2_kns)
148+
session.measure(set_none_value ).assert_time__less_than(self.time_3_kns)

0 commit comments

Comments
 (0)