@@ -172,6 +172,53 @@ def test_fail(self):
172172 sct_payload = helper .run (self .data )
173173 self .assertFalse (sct_payload ['correct' ])
174174
175+ class TestHasEqualAst (unittest .TestCase ):
176+ def setUp (self ):
177+ self .data = {
178+ "DC_SOLUTION" : """dict(a = "a").keys()""" ,
179+ "DC_CODE" : """dict(a = 'a') .keys()""" }
180+
181+ def failing_submission (self ):
182+ self .data ["DC_CODE" ] = "dict(A = 'a').keys(somearg = 2)" ""
183+ sct_payload = helper .run (self .data )
184+ self .assertFalse (sct_payload ['correct' ])
185+
186+ def test_simple_pass (self ):
187+ self .data ["DC_SCT" ] = "Ex().has_equal_ast()"
188+ sct_payload = helper .run (self .data )
189+ self .assertTrue (sct_payload ['correct' ])
190+
191+ def test_simple_fail (self ):
192+ self .data ["DC_SCT" ] = "Ex().has_equal_ast()"
193+ self .failing_submission ()
194+
195+ def test_function_pass (self ):
196+ self .data ["DC_SCT" ] = "Ex().check_function('dict', 0, signature=False).has_equal_ast()"
197+ sct_payload = helper .run (self .data )
198+ self .assertTrue (sct_payload ['correct' ])
199+
200+ def test_function_fail (self ):
201+ self .data ["DC_SCT" ] = "Ex().check_function('dict', 0, signature=False).has_equal_ast()"
202+ self .failing_submission ()
203+
204+ def test_function_code_pass (self ):
205+ self .data ["DC_SCT" ] = """Ex().has_equal_ast(code = 'dict(a = "a").keys()')"""
206+ sct_payload = helper .run (self .data )
207+ self .assertTrue (sct_payload ['correct' ])
208+
209+ def test_function_code_fail (self ):
210+ self .data ["DC_SCT" ] = """Ex().has_equal_ast(code = 'dict(a = "a").keys()')"""
211+ self .failing_submission ()
212+
213+ def test_exact_false_pass (self ):
214+ self .data ["DC_CODE" ] = """dict(a = 'a').keys()\n print('extra')"""
215+ self .data ["DC_SCT" ] = "Ex().has_equal_ast(exact=False)"
216+ sct_payload = helper .run (self .data )
217+ self .assertTrue (sct_payload ['correct' ])
218+
219+ def test_exact_false_fail (self ):
220+ self .data ["DC_SCT" ] = "Ex().has_equal_ast(exact=False)"
221+ self .failing_submission ()
175222
176223class TestOverride (unittest .TestCase ):
177224 """
0 commit comments