Skip to content

Commit f78b49b

Browse files
committed
Merge dev into main
2 parents ecddf8b + 5101ce8 commit f78b49b

File tree

8 files changed

+53
-7
lines changed

8 files changed

+53
-7
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.34.0-blue)
3+
![Current Release](https://img.shields.io/badge/release-v3.34.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/helpers/cache_on_self/Cache_Key_Generator.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
2-
from typing import Callable, Dict, List, Tuple, Any, Set, FrozenSet
2+
from enum import Enum
3+
from typing import Callable, Dict, List, Tuple, Any
34
from osbot_utils.utils.Misc import str_md5
45

56

@@ -91,6 +92,12 @@ def value_to_cache_str(self, value: Any) -> str: #
9192
elif isinstance(value, frozenset):
9293
return f"<frozenset>:{json.dumps(sorted(list(value)), separators=(',', ':'))}"
9394

95+
elif isinstance(value, Enum): # Handle Enum types - include both class name and member name for uniqueness
96+
enum_class = type(value).__name__
97+
enum_member = value.name
98+
return f"<enum:{enum_class}>:{enum_member}"
99+
100+
94101
else:
95102
# For other types, try to use repr if it's likely to be stable
96103
# This is a fallback - specific types should be handled above

osbot_utils/testing/Pytest.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from osbot_utils.utils.Env import get_env, load_dotenv, in_python_debugger
1+
from osbot_utils.utils.Env import get_env, load_dotenv, in_python_debugger, in_github_action
22

33
needs_load_dotenv = True
44

@@ -15,4 +15,8 @@ def skip_pytest__if_env_var_is_not_set(env_var_name):
1515

1616
def skip__if_in_python_debugger():
1717
if in_python_debugger():
18-
skip_pytest("Skipping tests because we are in a debugger")
18+
skip_pytest("Skipping tests because we are in a debugger")
19+
20+
def skip_if_in_github_action():
21+
if in_github_action():
22+
skip_pytest("Skipping test because we are in a github action")

osbot_utils/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v3.34.0
1+
v3.34.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.34.0"
3+
version = "v3.34.1"
44
description = "OWASP Security Bot - Utils"
55
authors = ["Dinis Cruz <[email protected]>"]
66
license = "MIT"

tests/unit/helpers/cache_on_self/test__regression__cache_on_self.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,39 @@
55

66
class test__regression__cache_on_self(TestCase):
77

8+
def test__regression__cache_on_self__enum_caching(self):
9+
10+
from enum import Enum
11+
12+
@cache_on_self
13+
def an_method(self, an_str:str):
14+
return an_str
15+
16+
assert an_method(self, an_str='A') == 'A'
17+
assert an_method(self, an_str='B') == 'B'
18+
assert an_method(self, an_str='C') == 'C'
19+
20+
class An_Enum(str, Enum):
21+
A = 'A'
22+
B = 'B'
23+
C = 'C'
24+
25+
@cache_on_self
26+
def an_method_with_enum(self, an_enum:An_Enum):
27+
return an_enum
28+
29+
assert an_method_with_enum(self, an_enum='A') == 'A'
30+
assert an_method_with_enum(self, an_enum='B') == 'B'
31+
assert an_method_with_enum(self, an_enum='C') == 'C'
32+
33+
assert an_method_with_enum(self, an_enum=An_Enum.A) == 'A'
34+
assert an_method_with_enum(self, an_enum=An_Enum.A) == An_Enum.A
35+
#assert an_method_with_enum(self, an_enum=An_Enum.B) != 'B' # BUG
36+
#assert an_method_with_enum(self, an_enum=An_Enum.B) == An_Enum.A # BUG
37+
#assert an_method_with_enum(self, an_enum=An_Enum.C) == An_Enum.A # BUG
38+
assert an_method_with_enum(self, an_enum=An_Enum.B) == An_Enum.B # FIXED
39+
assert an_method_with_enum(self, an_enum=An_Enum.B) == 'B' # FIXED
40+
assert an_method_with_enum(self, an_enum=An_Enum.C) == An_Enum.C # FIXED
841
def test__regression__cache_on_self__none_values_ignored(self):
942
"""Test that None values are completely ignored in cache key generation"""
1043
class None_Values_Class:

tests/unit/helpers/pubsub/test_Event__Queue.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from osbot_utils.base_classes.Kwargs_To_Self import Kwargs_To_Self
66
from osbot_utils.helpers.pubsub.Event__Queue import Event__Queue, TIMEOUT__QUEUE_GET
77
from osbot_utils.helpers.pubsub.schemas.Schema__Event import Schema__Event
8+
from osbot_utils.testing.Pytest import skip_if_in_github_action
89
from osbot_utils.utils.Objects import base_types
910

1011
class test_Event_Queue(TestCase):
@@ -79,6 +80,7 @@ def handle_event(self, event):
7980
assert _.running is False
8081

8182
def test_send_message(self):
83+
skip_if_in_github_action() # this failed sometimes in GH Actions (on 3.11.11)
8284
message_1 = 'Hello World!'
8385
message_2 = 'from here'
8486
data_1 = {'some': 'data', 'goes': 'here'}

tests/unit/type_safe/primitives/domains/identifiers/safe_int/test_Timestamp_Now.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def process_event(timestamp: Timestamp_Now = None):
357357
# Without providing timestamp
358358
ts1 = process_event()
359359
ts2 = process_event()
360-
assert abs(ts2 - ts1) < 1 # Both recent
360+
assert abs(ts2 - ts1) < 2 # Both recent
361361

362362
# With providing timestamp
363363
specific_ts = Timestamp_Now(1234567890)

0 commit comments

Comments
 (0)