From 421dcc062ab3f545e040707576fd3adbfdfd071f Mon Sep 17 00:00:00 2001 From: Tim Sweet Date: Thu, 26 Jun 2025 14:47:15 -0500 Subject: [PATCH] add test case files to repo --- .gitignore | 1 - test/TryExcept.py | 298 ++++++++++++++++++++++++++++++++++++++++++++++ test/with.py | 152 +++++++++++++++++++++++ 3 files changed, 450 insertions(+), 1 deletion(-) create mode 100644 test/TryExcept.py create mode 100644 test/with.py diff --git a/.gitignore b/.gitignore index 27f3d6c..86660cd 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,6 @@ venv/ .idea/ .python-version poetry.toml -test/ .DS_Store results/ .vscode/ diff --git a/test/TryExcept.py b/test/TryExcept.py new file mode 100644 index 0000000..ac8efff --- /dev/null +++ b/test/TryExcept.py @@ -0,0 +1,298 @@ +def TryExcept(): + try: + print(1) + except: + print(2) + print(3) + +def TryExceptMulti(): + try: + print(1) + except a: + print(2) + except b: + print(3) + except c: + print(4) + print(5) + +def TryExceptMultiFallback(): + try: + print(1) + except a: + print(2) + except b: + print(3) + except: + print(4) + print(5) + +def TryExceptMultiNamed(): + try: + print(1) + except A as a: + print(2) + except B as b: + print(3) + except C as c: + print(4) + print(5) + +def TryExceptMultiNamedFallback(): + try: + print(1) + except A as a: + print(2) + except B as b: + print(3) + except: + print(4) + print(5) + +def TryExceptMultiNamedAndUnnamed(): + try: + print(1) + except A as a: + print(2) + except b: + print(3) + except: + print(4) + print(5) + +def TryExceptElseBare(): + try: + print(1) + except: + print(2) + else: + print(3) + print(4) + +def TryExceptElseMulti(): + try: + print(1) + except a: + print(2) + except b: + print(3) + else: + print(4) + print(5) + +def TryExceptElseMultiFallback(): + try: + print(1) + except a: + print(2) + except b: + print(3) + except: + print(4) + else: + print(5) + print(6) + +def TryExceptElseNamed(): + try: + print(1) + except A as a: + print(2) + except B as b: + print(3) + else: + print(4) + print(5) + +def TryExceptElseMultiNamedAndUnnamed(): + try: + print(1) + except A as a: + print(2) + except b: + print(3) + except: + print(4) + else: + print(5) + print(6) + +def TryFinallyBare(): + try: + print(1) + finally: + print(2) + print(3) + +def TryExceptFinallyBare(): + try: + print(1) + except: + print(2) + finally: + print(3) + print(4) +##### NOT YET IMPLEMENTED ##### +##### crashes cflow.py ##### +##def TryExceptFinallyBareSpecific(): +## try: +## print(1) +## except a: +## print(2) +## finally: +## print(3) +## print(4) +## +##def TryExceptMultiFinally(): +## try: +## print(1) +## except a: +## print(2) +## except b: +## print(3) +## finally: +## print(4) +## print(5) +## +## Broken +##def TryExceptMultiFallbackFinally(): +## try: +## print(1) +## except a: +## print(2) +## except: +## print(3) +## finally: +## print(4) +## print(5) + +def TryExceptMultiNamedFinally(): + try: + print(1) + except A as a: + print(2) + except B as b: + print(3) + finally: + print(4) + print(5) + +def TryExceptMultiNamedFallbackFinally(): + try: + print(1) + except A as a: + print(2) + except: + print(3) + finally: + print(4) + print(5) + +def TryExceptMultiNamedAndUnnamedFinally(): + try: + print(1) + except A as a: + print(2) + except b: + print(3) + except: + print(4) + finally: + print(5) + print(6) + +def TryExceptElseFinallyBare(): + try: + print(1) + except: + print(2) + else: + print(3) + finally: + print(4) + print(5) + +def TryExceptBareNested(): + try: + print(1) + except: + print(2) + try: + print(3) + except: + print(4) + +def TryExceptReturn(): + try: + print(1) + return 2 + except: + print(2) + +# Not currently working, see https://github.com/syssec-utd/pylingual/issues/24#issuecomment-3005215427 +def TryExceptRaise(): + try: + print(1) + except: + print(2) + raise Exc + +def TryExceptRaiseNamed(): + try: + print(1) + except A as a: + print(2) + raise Exc + +### Expected to fail on 3.10- has the same issue as TryExceptFinally +def TryExceptBareNestedNamed(): + try: + print(1) + except A as a: + print(2) + try: + print(3) + except: + print(4) + +def TryExceptReturnNamed(): + try: + print(1) + return 2 + except A as a: + print(2) + +def TryExceptBareNestedMulti(): + try: + print(1) + except a: + print(2) + try: + print(3) + except: + print(4) + except b: + print(5) + try: + print(6) + except: + print(7) + +def TryExceptReturnMulti(): + try: + print(1) + return 2 + except a: + print(2) + except b: + print(3) + +def TryExceptRaiseMulti(): + try: + print(1) + except a: + print(2) + raise Exc + except b: + print(3) + raise Exc diff --git a/test/with.py b/test/with.py new file mode 100644 index 0000000..d51ccd7 --- /dev/null +++ b/test/with.py @@ -0,0 +1,152 @@ +def bare_with(): + with a: + print(1) + +def bare_with_fallthrough(): + with a: + print(1) + print(2) + +## Known to fail on 3.10 +def multi_with(): + with a, b: + print(1) + +def multi_with_fallthrough(): + with a, b: + print(1) + print(2) + +def with_as(): + with a as c: + print(1) + +def with_as_fallthrough(): + with a as c: + print(1) + print(2) + +def multi_with_as(): + with a, b as c: + print(1) + +def multi_with_as_fallthrough(): + with a, b as c: + print(1) + print(2) + +def with_multi_as(): + with a as b, c: + print(1) + +def with_multi_as_fallthrough(): + with a as b, c: + print(1) + print(2) + +def multi_with_multi_as(): + with a as b, c as d: + print(1) + +# Known to fail on 3.10 +def multi_with_multi_as_fallthrough(): + with a as b, c as d: + print(1) + print(2) + +def multi_with_multi_as_alt(): + with a, b as c, d: + print(1) + +# Known to fail on 3.10 +def multi_with_multi_as_fallthrough_alt(): + with a, b as c, d: + print(1) + print(2) + +async def bare_async_with(): + async with a: + print(1) + +async def bare_async_with_fallthrough(): + async with a: + print(1) + print(2) + +## Known to fail on 3.10 +async def multi_async_with(): + async with a, b: + print(1) + +async def multi_async_with_fallthrough(): + async with a, b: + print(1) + print(2) + +async def with_as(): + async with a as c: + print(1) + +async def with_as_fallthrough(): + async with a as c: + print(1) + print(2) + +async def multi_async_with_as(): + async with a, b as c: + print(1) + +async def multi_async_with_as_fallthrough(): + async with a, b as c: + print(1) + print(2) + +async def with_multi_as(): + async with a as b, c: + print(1) + +async def with_multi_as_fallthrough(): + async with a as b, c: + print(1) + print(2) + +async def multi_async_with_multi_as(): + async with a as b, c as d: + print(1) + +# Known to fail on 3.10 +async def multi_async_with_multi_as_fallthrough(): + async with a as b, c as d: + print(1) + print(2) + +async def multi_async_with_multi_as_alt(): + async with a, b as c, d: + print(1) + +# Known to fail on 3.10 +async def multi_async_with_multi_as_fallthrough_alt(): + async with a, b as c, d: + print(1) + print(2) + +def try_with_except(): + # With statement with outer exception handler + try: + with a: + print(1) + except: + print(2) + print(3) + +def with_return(): + # With statement with return + with a: + return 1 + print(1) + +def with_raise(): + # With statement with raise + with a: + raise Exc + print(1)