Skip to content

Commit

Permalink
added test to Type_Safe
Browse files Browse the repository at this point in the history
  • Loading branch information
DinisCruz committed Jan 11, 2025
1 parent 1d095ec commit 4dd24eb
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/unit/type_safe/test_Type_Safe.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,38 @@ class An_Class_1(Type_Safe):

assert An_Class_1().json() == {'an_guid': 'osbot_utils.helpers.Guid.Guid', 'an_time_stamp': 'osbot_utils.helpers.Timestamp_Now.Timestamp_Now'}

def test_type_checks_on__forward_ref__works_on_multiple_levels(self):
class An_Class(Type_Safe):
node_type: Type['An_Class']

class Child_Type_1(An_Class):
pass

class Child_Type_2(Child_Type_1):
pass

class Child_Type_3(Child_Type_2):
pass

class Child_Type_4(Child_Type_3):
pass

class Should_Fail(Type_Safe):
pass

An_Class(node_type=An_Class ) # works
An_Class(node_type=Child_Type_1) # works
An_Class(node_type=Child_Type_2)
An_Class(node_type=Child_Type_3)
An_Class(node_type=Child_Type_4)
with pytest.raises(ValueError,match=re.escape("Invalid type for attribute 'node_type'. Expected 'typing.Type[ForwardRef('An_Class')]' but got '<class 'type'>'")):
An_Class(node_type=Should_Fail)

assert issubclass(Child_Type_1, An_Class)
assert issubclass(Child_Type_2, An_Class)
assert issubclass(Child_Type_3, An_Class)
assert issubclass(Child_Type_4, An_Class)



class Custom_Class: # used in test_type_serialization
Expand Down

0 comments on commit 4dd24eb

Please sign in to comment.