File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -422,8 +422,13 @@ def has_equal_ast(incorrect_msg="FMT: Your code does not seem to match the solut
422422 """
423423 rep = Reporter .active_reporter
424424
425- parse_tree = lambda n : ast .dump (n .body [0 ] if isinstance (n , ast .Module ) and len (n .body ) == 1 else n )
425+ def parse_tree (n ):
426+ # get contents of module.body if only 1 element
427+ crnt = n .body [0 ] if isinstance (n , ast .Module ) and len (n .body ) == 1 else n
426428
429+ # remove Expr if it exists
430+ return ast .dump (crnt .value if isinstance (crnt , ast .Expr ) else crnt )
431+
427432 stu_rep = parse_tree (state .student_tree )
428433 sol_rep = parse_tree (state .solution_tree if not code else ast .parse (code ))
429434
Original file line number Diff line number Diff line change @@ -220,6 +220,15 @@ def test_exact_false_fail(self):
220220 self .data ["DC_SCT" ] = "Ex().has_equal_ast(exact=False)"
221221 self .failing_submission ()
222222
223+ def test_part_of_method_pass (self ):
224+ self .data ["DC_SCT" ] = """Ex().has_equal_ast(code = 'dict(a = "a")', exact=False)"""
225+ sct_payload = helper .run (self .data )
226+ self .assertTrue (sct_payload ['correct' ])
227+
228+ def test_part_of_method_fail (self ):
229+ self .data ["DC_SCT" ] = """Ex().has_equal_ast(code = 'dict(a = "a")', exact=False)"""
230+ self .failing_submission ()
231+
223232class TestOverride (unittest .TestCase ):
224233 """
225234 This class is used to test overriding w/ correct and incorrect code. Tests are
You can’t perform that action at this time.
0 commit comments