diff options
author | Florent Xicluna <florent.xicluna@gmail.com> | 2014-03-29 14:46:24 +0100 |
---|---|---|
committer | Florent Xicluna <florent.xicluna@gmail.com> | 2014-03-29 14:46:24 +0100 |
commit | 96cad81ab9e10ed676feb168f2c7a7dbf0100d7e (patch) | |
tree | 95717b56c9029d123a0e49415d8b85b696428b75 | |
parent | 12b4d425e304f80115f3de91a372ef0ad232ba90 (diff) | |
download | pyflakes-96cad81ab9e10ed676feb168f2c7a7dbf0100d7e.tar.gz |
Rewrite test_doctests to avoid running tests twice
-rw-r--r-- | pyflakes/test/test_doctests.py | 91 |
1 files changed, 51 insertions, 40 deletions
diff --git a/pyflakes/test/test_doctests.py b/pyflakes/test/test_doctests.py index 8c76815..1a03a3f 100644 --- a/pyflakes/test/test_doctests.py +++ b/pyflakes/test/test_doctests.py @@ -4,10 +4,10 @@ from pyflakes import messages as m from pyflakes.test.test_other import Test as TestOther from pyflakes.test.test_imports import Test as TestImports from pyflakes.test.test_undefined_names import Test as TestUndefinedNames -from pyflakes.test.harness import skip +from pyflakes.test.harness import TestCase, skip -class Test(TestOther, TestImports, TestUndefinedNames): +class _DoctestMixin(object): withDoctest = True @@ -35,37 +35,16 @@ class Test(TestOther, TestImports, TestUndefinedNames): return doctestificator % "\n ".join(lines) def flakes(self, input, *args, **kw): - return super(Test, self).flakes(self.doctestify(input), - *args, **kw) + return super(_DoctestMixin, self).flakes(self.doctestify(input), *args, **kw) + # return TestCase.flakes(self, self.doctestify(input), *args, **kw) - def test_doubleNestingReportsClosestName(self): - """ - Lines in doctest are a bit different so we can't use the test - from TestUndefinedNames - """ - exc = super(Test, self).flakes(''' - def doctest_stuff(): - """ - >>> def a(): - ... x = 1 - ... def b(): - ... x = 2 # line 7 in the file - ... def c(): - ... x - ... x = 3 - ... return x - ... return x - ... return x - """ - ''', m.UndefinedLocal).messages[0] - self.assertEqual(exc.message_args, ('x', 7)) +class Test(TestCase): - def test_futureImport(self): - """XXX This test can't work in a doctest""" + withDoctest = True def test_importBeforeDoctest(self): - super(Test, self).flakes(""" + self.flakes(""" import foo def doctest_stuff(): @@ -76,7 +55,7 @@ class Test(TestOther, TestImports, TestUndefinedNames): @skip("todo") def test_importBeforeAndInDoctest(self): - super(Test, self).flakes(''' + self.flakes(''' import foo def doctest_stuff(): @@ -89,7 +68,7 @@ class Test(TestOther, TestImports, TestUndefinedNames): ''', m.Redefined) def test_importInDoctestAndAfter(self): - super(Test, self).flakes(''' + self.flakes(''' def doctest_stuff(): """ >>> import foo @@ -101,7 +80,7 @@ class Test(TestOther, TestImports, TestUndefinedNames): ''') def test_offsetInDoctests(self): - exc = super(Test, self).flakes(''' + exc = self.flakes(''' def doctest_stuff(): """ @@ -113,7 +92,7 @@ class Test(TestOther, TestImports, TestUndefinedNames): self.assertEqual(exc.col, 12) def test_offsetInLambdasInDoctests(self): - exc = super(Test, self).flakes(''' + exc = self.flakes(''' def doctest_stuff(): """ @@ -125,7 +104,7 @@ class Test(TestOther, TestImports, TestUndefinedNames): self.assertEqual(exc.col, 20) def test_offsetAfterDoctests(self): - exc = super(Test, self).flakes(''' + exc = self.flakes(''' def doctest_stuff(): """ @@ -139,7 +118,7 @@ class Test(TestOther, TestImports, TestUndefinedNames): self.assertEqual(exc.col, 0) def test_syntaxErrorInDoctest(self): - exceptions = super(Test, self).flakes( + exceptions = self.flakes( ''' def doctest_stuff(): """ @@ -162,7 +141,7 @@ class Test(TestOther, TestImports, TestUndefinedNames): self.assertEqual(exc.col, 18) def test_indentationErrorInDoctest(self): - exc = super(Test, self).flakes(''' + exc = self.flakes(''' def doctest_stuff(): """ >>> if True: @@ -173,7 +152,7 @@ class Test(TestOther, TestImports, TestUndefinedNames): self.assertEqual(exc.col, 16) def test_offsetWithMultiLineArgs(self): - (exc1, exc2) = super(Test, self).flakes( + (exc1, exc2) = self.flakes( ''' def doctest_stuff(arg1, arg2, @@ -191,7 +170,7 @@ class Test(TestOther, TestImports, TestUndefinedNames): self.assertEqual(exc2.col, 12) def test_doctestCanReferToFunction(self): - super(Test, self).flakes(""" + self.flakes(""" def foo(): ''' >>> foo @@ -199,7 +178,7 @@ class Test(TestOther, TestImports, TestUndefinedNames): """) def test_doctestCanReferToClass(self): - super(Test, self).flakes(""" + self.flakes(""" class Foo(): ''' >>> Foo @@ -211,7 +190,7 @@ class Test(TestOther, TestImports, TestUndefinedNames): """) def test_noOffsetSyntaxErrorInDoctest(self): - exceptions = super(Test, self).flakes( + exceptions = self.flakes( ''' def buildurl(base, *args, **kwargs): """ @@ -230,7 +209,7 @@ class Test(TestOther, TestImports, TestUndefinedNames): self.assertEqual(exc.lineno, 6) def test_singleUnderscoreInDoctest(self): - super(Test, self).flakes(''' + self.flakes(''' def func(): """A docstring @@ -241,3 +220,35 @@ class Test(TestOther, TestImports, TestUndefinedNames): """ return 1 ''') + + +class TestOther(_DoctestMixin, TestOther): + pass + + +class TestImports(_DoctestMixin, TestImports): + + def test_futureImport(self): + """XXX This test can't work in a doctest""" + + +class TestUndefinedNames(_DoctestMixin, TestUndefinedNames): + + def test_doubleNestingReportsClosestName(self): + """ + Lines in doctest are a bit different so we can't use the test + from TestUndefinedNames + """ + exc = self.flakes(''' + def a(): + x = 1 + def b(): + x = 2 # line 7 in the file + def c(): + x + x = 3 + return x + return x + return x + ''', m.UndefinedLocal).messages[0] + self.assertEqual(exc.message_args, ('x', 7)) |