File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed
tests/test_loaders_dumpers Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -54,6 +54,16 @@ def test_json_dumper(self):
5454 "creator" not in data ["books" ][i ].keys ()
5555 self .assertEqual (data , remove_empty_items (self .bookseries .model_dump ()))
5656
57+ # test @type is added to the top level and is assigned correct type when inject_type is True
58+ bookseries_with_type = json .loads (json_dumper .dumps (self .bookseries , inject_type = True ))
59+ self .assertIn ("@type" , bookseries_with_type )
60+ self .assertEqual ("BookSeries" , bookseries_with_type .get ("@type" ))
61+
62+ # test @type is not added to the top level when inject_type is False
63+ bookseries_without_type = json .loads (json_dumper .dumps (self .bookseries , inject_type = False ))
64+ self .assertNotIn ("@type" , bookseries_without_type )
65+ self .assertEqual (None , bookseries_without_type .get ("@type" ))
66+
5767
5868class PydanticDumpersDateTestCase (LoaderDumperTestCase ):
5969 @classmethod
You can’t perform that action at this time.
0 commit comments