Skip to content

Commit

Permalink
Adding test cases for unrolling an iterable pytest-dev#5062
Browse files Browse the repository at this point in the history
  • Loading branch information
danielx123 committed Apr 22, 2019
1 parent 3fa329c commit 7156752
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions testing/test_assertrewrite.py
Expand Up @@ -671,6 +671,53 @@ def __repr__(self):
assert "UnicodeDecodeError" not in msg
assert "UnicodeEncodeError" not in msg

def test_generator(self, testdir):
testdir.makepyfile(
"""
def check_even(num):
if num % 2 == 0:
return True
return False
def test_generator():
odd_list = list(range(1,9,2))
assert all(check_even(num) for num in odd_list)"""
)
result = testdir.runpytest()
result.stdout.fnmatch_lines(["*assert False*", "*where False = check_even(1)*"])

def test_list_comprehension(self, testdir):
testdir.makepyfile(
"""
def check_even(num):
if num % 2 == 0:
return True
return False
def test_list_comprehension():
odd_list = list(range(1,9,2))
assert all([check_even(num) for num in odd_list])"""
)
result = testdir.runpytest()
result.stdout.fnmatch_lines(["*assert False*", "*where False = check_even(1)*"])

def test_for_loop(self, testdir):
testdir.makepyfile(
"""
def check_even(num):
if num % 2 == 0:
return True
return False
def test_for_loop():
odd_list = list(range(1,9,2))
for num in odd_list:
assert check_even(num)
"""
)
result = testdir.runpytest()
result.stdout.fnmatch_lines(["*assert False*", "*where False = check_even(1)*"])


class TestRewriteOnImport(object):
def test_pycache_is_a_file(self, testdir):
Expand Down

0 comments on commit 7156752

Please sign in to comment.