Skip to content

Commit

Permalink
Issue kevinw#13: redefinition of unused module (tests)
Browse files Browse the repository at this point in the history
Unittests for issue kevinw#13
  • Loading branch information
saper committed Jan 6, 2013
1 parent 06e149a commit 5d2b756
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 0 deletions.
74 changes: 74 additions & 0 deletions pyflakes/test/test_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,80 @@ def test_redefinedWhileUnused(self):
self.flakes('import fu; fu, bar = 3', m.RedefinedWhileUnused)
self.flakes('import fu; [fu, bar] = 3', m.RedefinedWhileUnused)

def test_redefinedIf(self):
"""
Test that importing a module twice within an if
block does raise a warning.
Issue #13: https://github.com/kevinw/pyflakes/issues/13
"""
self.flakes('''
i = 2
if i==1:
import os
import os
os.path''', m.RedefinedWhileUnused)

def test_redefinedIfElse(self):
"""
Test that importing a module twice in if
and else blocks does not raise a warning.
Issue #13: https://github.com/kevinw/pyflakes/issues/13
"""
self.flakes('''
i = 2
if i==1:
import os
else:
import os
os.path''')

def test_redefinedTry(self):
"""
Test that importing a module twice in an try block
does raise a warning.
Issue #13: https://github.com/kevinw/pyflakes/issues/13
"""
self.flakes('''
try:
import os
import os
except:
pass
os.path''', m.RedefinedWhileUnused)

def test_redefinedTryExcept(self):
"""
Test that importing a module twice in an try
and except block does not raise a warning.
Issue #13: https://github.com/kevinw/pyflakes/issues/13
"""
self.flakes('''
try:
import os
except:
import os
os.path''')

def test_redefinedTryNested(self):
"""
Test that importing a module twice using a nested
try/except and if blocks does not issue a warning.
Issue #13: https://github.com/kevinw/pyflakes/issues/13
"""
self.flakes('''
try:
if True:
if True:
import os
except:
import os
os.path''')

def test_redefinedByFunction(self):
self.flakes('''
import fu
Expand Down
56 changes: 56 additions & 0 deletions pyflakes/test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,62 @@ def a(): pass
def a(): pass
''', m.RedefinedFunction)

def test_redefinedIfElseFunction(self):
"""
Test that shadowing a function definition twice in an if
and else block does not raise a warning.
Issue #13: https://github.com/kevinw/pyflakes/issues/13
"""
self.flakes('''
if True:
def a(): pass
else:
def a(): pass
''')

def test_redefinedIfFunction(self):
"""
Test that shadowing a function definition within an if block
raises a warning.
Issue #13: https://github.com/kevinw/pyflakes/issues/13
"""
self.flakes('''
if True:
def a(): pass
def a(): pass
''', m.RedefinedFunction)

def test_redefinedTryExceptFunction(self):
"""
Test that shadowing a function definition twice in try
and except block does not raise a warning.
Issue #13: https://github.com/kevinw/pyflakes/issues/13
"""
self.flakes('''
try:
def a(): pass
except:
def a(): pass
''')

def test_redefinedTryFunction(self):
"""
Test that shadowing a function definition within a try block
raises a warning.
Issue #13: https://github.com/kevinw/pyflakes/issues/13
"""
self.flakes('''
try:
def a(): pass
def a(): pass
except:
pass
''', m.RedefinedFunction)

def test_functionDecorator(self):
"""
Test that shadowing a function definition with a decorated version of
Expand Down

0 comments on commit 5d2b756

Please sign in to comment.