@@ -89,15 +89,40 @@ def test_to_python(self, mock_context):
8989 # Try simple cases of conversion
9090 assert cont ._to_python ("@id" , "ham" ) == "ham"
9191 assert cont ._to_python ("@type" , ["@id" ]) == '@id'
92+ assert cont ._to_python ("@type" , ["@id" , "http://spam.eggs/Egg" ]) == ["@id" , "Egg" ]
93+
94+ # Try type conversions
95+ assert cont ._to_python ("http://spam.eggs/ham" , [{"@id" : "spam" }]) == 'spam'
96+
97+ assert cont ._to_python ("http://soam.eggs/spam" , [{"@value" : "bacon" }]) == 'bacon'
98+ assert cont ._to_python ("http://spam.eggs/spam" , [{"@value" : True }]) == True
99+ assert cont ._to_python ("http://spam.eggs/spam" , [{"@value" : 123 }]) == 123
100+
101+ assert cont ._to_python ("http://spam.eggs/eggs" , [{
102+ "@value" : "2022-02-22T00:00:00" , "@type" : "https://schema.org/DateTime"
103+ }]) == "2022-02-22T00:00:00"
92104
93105 def test_to_python_list (self , mock_context ):
94106 cont = ld_container ([{}], context = [mock_context ])
95107 list_data = [{"@list" : [{"@id" : "spam" }, {"@id" : "eggs" }]}]
96108
109+ assert cont ._to_python ("ham" , list_data ).to_python () == ["spam" , "eggs" ]
110+
111+ def test_to_expanded (self , mock_context ):
97112 # Create container with mock context
98113 cont = ld_container ([{}], context = [mock_context ])
99114
100115 # Try simple cases of expansion
116+ assert cont ._to_expanded_json ("@id" , "ham" ) == "ham"
117+ assert cont ._to_expanded_json ("@type" , "Egg" ) == ["http://spam.eggs/Egg" ]
118+
119+ # Type conversions
120+ assert cont ._to_expanded_json ("ham" , "spam" ) == [{"@id" : "spam" }]
121+
101122 assert cont ._to_expanded_json ("spam" , "bacon" ) == [{"@value" : "bacon" }]
102- assert cont ._to_expanded_json ("@id" , "ham" ) == "http://ham.eggs/ham"
103- assert cont ._to_expanded_json ("@type" , "@id" ) == ["@id" ]
123+ assert cont ._to_expanded_json ("spam" , 123 ) == [{"@value" : 123 }]
124+ assert cont ._to_expanded_json ("spam" , True ) == [{"@value" : True }]
125+
126+ assert cont ._to_expanded_json ("eggs" , datetime (2022 , 2 ,22 )) == [
127+ {"@value" : "2022-02-22T00:00:00" , "@type" : "http://schema.org/DateTime" }
128+ ]
0 commit comments