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 20, 2023
1 parent 297449c commit 4db5bf8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
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
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 4db5bf8

Please sign in to comment.