Skip to content

Commit 9020185

Browse files
committed
Add more test cases
1 parent 306ee96 commit 9020185

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

tests/expressions/test_interpreter_coverage1.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,49 @@ async def foo():
862862
foo()
863863

864864

865+
def test_visit_classdef():
866+
parser = ExpressionsParser()
867+
interpreter = ExpressionsInterpreter()
868+
869+
# Test class with super() in method
870+
code = """
871+
class Base:
872+
def greet(self):
873+
return "Hello"
874+
875+
class Derived(Base):
876+
def greet(self):
877+
return super().greet() + " World"
878+
879+
obj = Derived()
880+
result = obj.greet()
881+
"""
882+
tree = parser.parse(code)
883+
interpreter.execute(tree)
884+
assert interpreter.get_name_value("result") == "Hello World"
885+
886+
# Test class with multiple inheritance
887+
code = """
888+
class A:
889+
def foo(self):
890+
return "A"
891+
892+
class B:
893+
def foo(self):
894+
return "B"
895+
896+
class C(A, B):
897+
def foo(self):
898+
return super().foo()
899+
900+
obj = C()
901+
result = obj.foo()
902+
"""
903+
tree = parser.parse(code)
904+
interpreter.execute(tree)
905+
assert interpreter.get_name_value("result") == "A"
906+
907+
865908
def test_visit_try():
866909
parser = ExpressionsParser()
867910
interpreter = ExpressionsInterpreter()
@@ -1227,6 +1270,27 @@ def foo():
12271270
assert interpreter.get_name_value("result") == [3, 7, 11]
12281271

12291272

1273+
def test_visit_global():
1274+
parser = ExpressionsParser()
1275+
interpreter = ExpressionsInterpreter()
1276+
1277+
# Test global declaration with nonlocal conflict
1278+
code = """
1279+
def outer():
1280+
x = 1
1281+
def inner():
1282+
nonlocal x
1283+
global x
1284+
x = 2
1285+
inner()
1286+
1287+
outer()
1288+
"""
1289+
tree = parser.parse(code)
1290+
with pytest.raises(SyntaxError, match="name 'x' is nonlocal and global"):
1291+
interpreter.execute(tree)
1292+
1293+
12301294
def test_visit_nonlocal():
12311295
parser = ExpressionsParser()
12321296
interpreter = ExpressionsInterpreter()

0 commit comments

Comments
 (0)