Skip to content

Commit 8cc9849

Browse files
committed
fixed test
1 parent ddb323e commit 8cc9849

4 files changed

Lines changed: 27 additions & 19 deletions

File tree

osbot_fast_api/api/transformers/Type_Safe__To__Json.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ class Type_Safe__To__Json(Type_Safe): # Converts Type_Safe classes to JSON
1414
include_examples : bool = False
1515
strict_mode : bool = False # If True, includes all Type_Safe constraints
1616

17+
# todo: the @type_safe here breaks some of the cache behaviour below since the @type_safe will
18+
# convert the Dict to Type_Safe__Dict which means the returned objects are not the same (but from the cached value, so the performance implications might not be that big)
19+
# (see if this has any side effects or main performance implications)
1720
@type_safe
1821
def convert_class(self, type_safe_class : Type[Type_Safe] , # Type_Safe class to convert
1922
title : str = None , # Optional schema title

tests/unit/api/transformers/test_Type_Safe__To__BaseModel.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import re
22
import sys
33
import pytest
4-
from typing import List, Dict, Optional, Union
5-
from unittest import TestCase
6-
from osbot_utils.testing.__ import __
7-
from pydantic import BaseModel, ValidationError
8-
9-
from osbot_utils.testing.__helpers import obj
10-
from osbot_utils.type_safe.Type_Safe import Type_Safe
11-
from osbot_fast_api.api.transformers.Type_Safe__To__BaseModel import Type_Safe__To__BaseModel, type_safe__to__basemodel
12-
from osbot_utils.type_safe.primitives.core.Safe_Int import Safe_Int
13-
from osbot_utils.type_safe.primitives.core.Safe_Str import Safe_Str
4+
from typing import List, Dict, Optional, Union
5+
from unittest import TestCase
6+
from osbot_utils.testing.__ import __
7+
from pydantic import BaseModel, ValidationError
8+
from osbot_utils.testing.__helpers import obj
9+
from osbot_utils.type_safe.Type_Safe import Type_Safe
10+
from osbot_fast_api.api.transformers.Type_Safe__To__BaseModel import Type_Safe__To__BaseModel, type_safe__to__basemodel
11+
from osbot_utils.type_safe.primitives.core.Safe_Int import Safe_Int
12+
from osbot_utils.type_safe.primitives.core.Safe_Str import Safe_Str
1413

1514

1615
class test_Type_Safe__To__BaseModel(TestCase):

tests/unit/api/transformers/test_Type_Safe__To__Json.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from osbot_utils.type_safe.primitives.core.Safe_Int import Safe_Int
77
from osbot_utils.type_safe.primitives.core.Safe_Float import Safe_Float
88
from osbot_fast_api.api.transformers.Type_Safe__To__Json import Type_Safe__To__Json, type_safe__to__json
9+
from osbot_utils.type_safe.type_safe_core.collections.Type_Safe__Dict import Type_Safe__Dict
910

1011

1112
class test_Type_Safe__To__Json(TestCase):
@@ -199,8 +200,14 @@ class CachedClass(Type_Safe):
199200
schema1 = self.converter.convert_class(CachedClass) # First conversion
200201
schema2 = self.converter.convert_class(CachedClass) # Second should return cached
201202

202-
assert schema1 is schema2 # Should be same object
203-
assert (CachedClass, False) in self.converter.schema_cache # Verify cache contains class
203+
assert type(schema1) is Type_Safe__Dict
204+
assert type(schema2) is Type_Safe__Dict
205+
206+
assert schema1 is not schema2 # objects are not exactly the same because of the @type_safe conversion from Dict to Type_Safe__Dict
207+
assert schema1 == schema2 # values are the same
208+
assert (CachedClass, False) in self.converter.schema_cache # Verify cache contains class
209+
assert self.converter.schema_cache[(CachedClass, False)] == schema1 # confirm cache entries
210+
assert self.converter.schema_cache[(CachedClass, False)] == schema2
204211

205212
def test__with_title_and_description(self): # Test custom title and description
206213
class DocumentedClass(Type_Safe):

tests/unit/api/transformers/test__type_safe__Fast_API_Routes__support.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
from typing import Optional, List, Dict, Set, Any
2-
from unittest import TestCase
3-
4-
from osbot_fast_api.api.schemas.Schema__Fast_API__Config import Schema__Fast_API__Config
5-
from osbot_utils.testing.__helpers import obj
1+
from typing import Optional, List, Dict, Set, Any
2+
from unittest import TestCase
3+
from osbot_fast_api.api.schemas.Schema__Fast_API__Config import Schema__Fast_API__Config
4+
from osbot_utils.testing.__helpers import obj
65
from osbot_utils.type_safe.primitives.domains.files.safe_str.Safe_Str__File__Name import Safe_Str__File__Name
76
from osbot_utils.type_safe.primitives.domains.http.safe_str.Safe_Str__Http__Content_Type import Safe_Str__Http__Content_Type
8-
from osbot_utils.testing.__ import __, __SKIP__
7+
from osbot_utils.testing.__ import __
98
from osbot_utils.type_safe.Type_Safe import Type_Safe
109
from osbot_utils.type_safe.Type_Safe__Primitive import Type_Safe__Primitive
11-
from osbot_utils.type_safe.primitives.domains.identifiers.safe_int.Timestamp_Now import Timestamp_Now
10+
from osbot_utils.type_safe.primitives.domains.identifiers.safe_int.Timestamp_Now import Timestamp_Now
1211
from osbot_utils.type_safe.primitives.core.Safe_Str import Safe_Str
1312
from osbot_utils.type_safe.primitives.domains.files.safe_str.Safe_Str__File__Path import Safe_Str__File__Path
1413
from osbot_utils.type_safe.primitives.domains.identifiers.Safe_Id import Safe_Id

0 commit comments

Comments
 (0)