Skip to content

Commit de813cb

Browse files
committed
refactored bug test to regression test
1 parent 1059b31 commit de813cb

File tree

2 files changed

+34
-37
lines changed

2 files changed

+34
-37
lines changed

tests/unit/type_safe/type_safe_core/_bugs/test_Type_Safe__bugs.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -100,39 +100,3 @@ class Extended_Config(Base_Config):
100100
Extended_Config() # BUG: should auto-assign Extended_Handler
101101

102102

103-
104-
def test__bug__set__json__serialisation_issue(self):
105-
import json
106-
from typing import Dict, Set
107-
from osbot_utils.testing.__ import __
108-
from osbot_utils.type_safe.primitives.domains.identifiers.Safe_Id import Safe_Id
109-
from osbot_utils.type_safe.primitives.domains.identifiers.Edge_Id import Edge_Id
110-
111-
class An_Class(Type_Safe):
112-
an_dict : Dict[Safe_Id , Set[Edge_Id ]]
113-
safe_id = Safe_Id('safe-id_jlqsh')
114-
edge_id = Edge_Id('6106b8e7')
115-
an_class = An_Class()
116-
an_class.an_dict[safe_id] = {edge_id}
117-
118-
#assert an_class.obj () == __(an_dict=__(safe_id_jlqsh={'6106b8e7'})) # BUG, this should be list, right? i.e. ['6106b8e7']
119-
#assert an_class.json() == {'an_dict': {'safe-id_jlqsh': {'6106b8e7'}}} # BUG, this should be list, right? i.e. ['6106b8e7']
120-
121-
assert an_class.obj () == __(an_dict=__(safe_id_jlqsh=['6106b8e7'])) # FIXED
122-
assert an_class.json() == {'an_dict': {'safe-id_jlqsh': ['6106b8e7']}} # FIXED
123-
124-
# error_message = "Object of type set is not JSON serializable"
125-
# with pytest.raises(TypeError, match=error_message): # BUG
126-
# json.dumps(an_class.json())
127-
assert json.dumps(an_class.json()) == '{"an_dict": {"safe-id_jlqsh": ["6106b8e7"]}}'
128-
129-
assert type(an_class.json().get('an_dict') ) is dict
130-
#assert type(an_class.json().get('an_dict').get('safe-id_jlqsh')) is set # BUG
131-
assert type(an_class.json().get('an_dict').get('safe-id_jlqsh')) is list # FIXED
132-
assert json.loads(json.dumps(an_class.json())) == an_class.json()
133-
error_message = "Type Set cannot be instantiated; use set() instead"
134-
# with pytest.raises(TypeError, match=re.escape(error_message)):
135-
# An_Class.from_json(an_class.json()) # BUG
136-
assert An_Class.from_json(an_class.json()).obj() == an_class.obj() # FIXED
137-
assert An_Class.from_json(an_class.json()).json() == an_class.json() # FIXED
138-

tests/unit/type_safe/type_safe_core/_regression/test_Type_Safe__regression.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import re
22
import sys
3+
import json
34
import pytest
45
from enum import Enum
56
from decimal import Decimal
67
from typing import Optional, Union, List, Dict, get_origin, Type, ForwardRef, Any, Set, Tuple
78
from unittest import TestCase
89
from unittest.mock import patch
10+
from osbot_utils.type_safe.primitives.domains.identifiers.Safe_Id import Safe_Id
11+
from osbot_utils.type_safe.primitives.domains.identifiers.Edge_Id import Edge_Id
912
from osbot_utils.type_safe.primitives.core.Safe_Float import Safe_Float
1013
from osbot_utils.type_safe.primitives.domains.identifiers.safe_str.Safe_Str__Id import Safe_Str__Id
1114
from osbot_utils.type_safe.primitives.domains.identifiers.Obj_Id import Obj_Id
@@ -2022,4 +2025,34 @@ class An_Class(Type_Safe):
20222025
# assert With_Base ().obj () == __(an_str=None) # BUG
20232026

20242027
assert With_Base ().json() == {'an_str': ''} # FIXED
2025-
assert With_Base ().obj () == __(an_str='') # FIXED
2028+
assert With_Base ().obj () == __(an_str='') # FIXED
2029+
2030+
def test__regression__set__json__serialisation_issue(self):
2031+
2032+
class An_Class(Type_Safe):
2033+
an_dict : Dict[Safe_Id , Set[Edge_Id ]]
2034+
safe_id = Safe_Id('safe-id_jlqsh')
2035+
edge_id = Edge_Id('6106b8e7')
2036+
an_class = An_Class()
2037+
an_class.an_dict[safe_id] = {edge_id}
2038+
2039+
#assert an_class.obj () == __(an_dict=__(safe_id_jlqsh={'6106b8e7'})) # BUG, this should be list, right? i.e. ['6106b8e7']
2040+
#assert an_class.json() == {'an_dict': {'safe-id_jlqsh': {'6106b8e7'}}} # BUG, this should be list, right? i.e. ['6106b8e7']
2041+
2042+
assert an_class.obj () == __(an_dict=__(safe_id_jlqsh=['6106b8e7'])) # FIXED
2043+
assert an_class.json() == {'an_dict': {'safe-id_jlqsh': ['6106b8e7']}} # FIXED
2044+
2045+
# error_message = "Object of type set is not JSON serializable"
2046+
# with pytest.raises(TypeError, match=error_message): # BUG
2047+
# json.dumps(an_class.json())
2048+
assert json.dumps(an_class.json()) == '{"an_dict": {"safe-id_jlqsh": ["6106b8e7"]}}'
2049+
2050+
assert type(an_class.json().get('an_dict') ) is dict
2051+
#assert type(an_class.json().get('an_dict').get('safe-id_jlqsh')) is set # BUG
2052+
assert type(an_class.json().get('an_dict').get('safe-id_jlqsh')) is list # FIXED
2053+
assert json.loads(json.dumps(an_class.json())) == an_class.json()
2054+
error_message = "Type Set cannot be instantiated; use set() instead"
2055+
# with pytest.raises(TypeError, match=re.escape(error_message)):
2056+
# An_Class.from_json(an_class.json()) # BUG
2057+
assert An_Class.from_json(an_class.json()).obj() == an_class.obj() # FIXED
2058+
assert An_Class.from_json(an_class.json()).json() == an_class.json() # FIXED

0 commit comments

Comments
 (0)