Skip to content

Commit

Permalink
refine and add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
zmezei committed Jul 5, 2023
1 parent 163c772 commit f942268
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions tests/test_field_descr.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# pylint: disable=function-redefined
import unittest
from pydantic import Field


from uagents import Model, Protocol


Expand All @@ -23,11 +21,9 @@ class Message(Model):
Model.build_schema_digest(Message)

message_field_info = Message.__fields__["message"].field_info
self.assertTrue(message_field_info is not None)
self.assertTrue(
message_field_info.description is not None
and message_field_info.description == "message field description"
)
self.assertIsNotNone(message_field_info)
self.assertIsNotNone(message_field_info.description)
self.assertEqual(message_field_info.description, "message field description")

def test_model_digest(self):
class Message(Model):
Expand All @@ -42,14 +38,21 @@ class Message(Model):

self.assertEqual(model_digest_no_descr, model_digest_with_descr)

def test_proto_digest(self):
def test_protocol(self):
class Message(Model):
message: str

@self.protocol_no_descr.on_query(Message)
def _(_ctx, _sender, _msg):
pass

self.assertNotIn(
"description",
self.protocol_no_descr.manifest()["models"][0]["schema"]["properties"][
"message"
],
)

proto_digest_no_descr = self.protocol_no_descr.digest

class Message(Model):
Expand All @@ -59,6 +62,13 @@ class Message(Model):
def _(_ctx, _sender, _msg):
pass

self.assertEqual(
self.protocol_with_descr.manifest()["models"][0]["schema"]["properties"][
"message"
]["description"],
"message field description",
)

proto_digest_with_descr = self.protocol_with_descr.digest

self.assertEqual(len(self.protocol_no_descr.models), 1)
Expand Down

0 comments on commit f942268

Please sign in to comment.