Skip to content

Commit 7156752

Browse files
committed
Adding test cases for unrolling an iterable pytest-dev#5062
1 parent 3fa329c commit 7156752

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

testing/test_assertrewrite.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,53 @@ def __repr__(self):
671671
assert "UnicodeDecodeError" not in msg
672672
assert "UnicodeEncodeError" not in msg
673673

674+
def test_generator(self, testdir):
675+
testdir.makepyfile(
676+
"""
677+
def check_even(num):
678+
if num % 2 == 0:
679+
return True
680+
return False
681+
682+
def test_generator():
683+
odd_list = list(range(1,9,2))
684+
assert all(check_even(num) for num in odd_list)"""
685+
)
686+
result = testdir.runpytest()
687+
result.stdout.fnmatch_lines(["*assert False*", "*where False = check_even(1)*"])
688+
689+
def test_list_comprehension(self, testdir):
690+
testdir.makepyfile(
691+
"""
692+
def check_even(num):
693+
if num % 2 == 0:
694+
return True
695+
return False
696+
697+
def test_list_comprehension():
698+
odd_list = list(range(1,9,2))
699+
assert all([check_even(num) for num in odd_list])"""
700+
)
701+
result = testdir.runpytest()
702+
result.stdout.fnmatch_lines(["*assert False*", "*where False = check_even(1)*"])
703+
704+
def test_for_loop(self, testdir):
705+
testdir.makepyfile(
706+
"""
707+
def check_even(num):
708+
if num % 2 == 0:
709+
return True
710+
return False
711+
712+
def test_for_loop():
713+
odd_list = list(range(1,9,2))
714+
for num in odd_list:
715+
assert check_even(num)
716+
"""
717+
)
718+
result = testdir.runpytest()
719+
result.stdout.fnmatch_lines(["*assert False*", "*where False = check_even(1)*"])
720+
674721

675722
class TestRewriteOnImport(object):
676723
def test_pycache_is_a_file(self, testdir):

0 commit comments

Comments
 (0)