Skip to content

Commit

Permalink
Add integration test for walrus-if
Browse files Browse the repository at this point in the history
  • Loading branch information
drdavella committed Sep 21, 2023
1 parent 0ab5033 commit a91e24d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
32 changes: 32 additions & 0 deletions integration_tests/test_use_walrus_if.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from codemodder.codemods.use_walrus_if import UseWalrusIf
from integration_tests.base_test import (
BaseIntegrationTest,
original_and_expected_from_code_path,
)


class TestUseWalrusIf(BaseIntegrationTest):
codemod = UseWalrusIf
code_path = "tests/samples/use_walrus_if.py"
original_code, _ = original_and_expected_from_code_path(code_path, [])
expected_new_code = """
if (x := foo()) is not None:
print(x)
if y := bar():
print(y)
z = baz()
print(z)
def whatever():
if (b := biz()) == 10:
print(b)
""".lstrip()

expected_diff = "--- \n+++ \n@@ -1,9 +1,7 @@\n-x = foo()\n-if x is not None:\n+if (x := foo()) is not None:\n print(x)\n \n-y = bar()\n-if y:\n+if y := bar():\n print(y)\n \n z = baz()\n@@ -11,6 +9,5 @@\n \n \n def whatever():\n- b = biz()\n- if b == 10:\n+ if (b := biz()) == 10:\n print(b)\n"

num_changes = 3
expected_line_change = 1
change_description = UseWalrusIf.CHANGE_DESCRIPTION
2 changes: 1 addition & 1 deletion tests/samples/unnecessary_f_str.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
bad = "hello"
bad = f"hello"
good = f"{2+3}"
16 changes: 16 additions & 0 deletions tests/samples/use_walrus_if.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
x = foo()
if x is not None:
print(x)

y = bar()
if y:
print(y)

z = baz()
print(z)


def whatever():
b = biz()
if b == 10:
print(b)

0 comments on commit a91e24d

Please sign in to comment.