From 5d2b7563cb63b080c99f6df24661dd9dcec188e1 Mon Sep 17 00:00:00 2001 From: saper Date: Sun, 6 Jan 2013 02:41:50 +0100 Subject: [PATCH] Issue #13: redefinition of unused module (tests) Unittests for issue #13 --- pyflakes/test/test_imports.py | 74 +++++++++++++++++++++++++++++++++++ pyflakes/test/test_other.py | 56 ++++++++++++++++++++++++++ 2 files changed, 130 insertions(+) diff --git a/pyflakes/test/test_imports.py b/pyflakes/test/test_imports.py index 08e4580..df8e43c 100644 --- a/pyflakes/test/test_imports.py +++ b/pyflakes/test/test_imports.py @@ -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 diff --git a/pyflakes/test/test_other.py b/pyflakes/test/test_other.py index 0751115..6388666 100644 --- a/pyflakes/test/test_other.py +++ b/pyflakes/test/test_other.py @@ -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