Skip to content

Commit

Permalink
Merged flakes-and-feathers [r=therve,gary] [f=445632].
Browse files Browse the repository at this point in the history
- Fixed missing imports and undefined variables reported by pyflakes,
  adding tests to exercise the blind spots.
- Cleaned up unused imports reported by pyflakes.

[https://code.launchpad.net/~sidnei/zope.testing/flakes-and-feathers/+merge/13008]
  • Loading branch information
sidnei committed Oct 7, 2009
1 parent 42f9200 commit da43ed5
Show file tree
Hide file tree
Showing 28 changed files with 146 additions and 32 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Expand Up @@ -4,7 +4,10 @@ zope.testing Changelog
3.8.4 (unreleased)
==================

- Fixed missing imports and undefined variables reported by pyflakes,
adding tests to exercise the blind spots.

- Cleaned up unused imports reported by pyflakes.

3.8.3 (2009-09-21)
==================
Expand Down
2 changes: 1 addition & 1 deletion src/zope/testing/doctest.py
Expand Up @@ -95,7 +95,7 @@ def _test():

import __future__

import sys, traceback, inspect, linecache, os, re, types
import sys, traceback, inspect, linecache, os, re
import unittest, difflib, pdb, tempfile
import warnings
from StringIO import StringIO
Expand Down
3 changes: 0 additions & 3 deletions src/zope/testing/doctestunit.py
Expand Up @@ -19,9 +19,6 @@
$Id$
"""

from doctest import DocFileSuite, DocTestSuite
from doctest import debug_src, debug

def pprint():
from pprint import PrettyPrinter
def pprint(ob, **opts):
Expand Down
2 changes: 2 additions & 0 deletions src/zope/testing/testrunner/doctest.py
Expand Up @@ -16,6 +16,7 @@
$Id: __init__.py 86232 2008-05-03 15:09:33Z ctheune $
"""

import sys
from zope.testing import doctest
import zope.testing.testrunner.feature

Expand All @@ -26,6 +27,7 @@ class DocTest(zope.testing.testrunner.feature.Feature):

def global_setup(self):
options = self.runner.options
output = options.output

self.old_reporting_flags = doctest.set_unittest_reportflags(0)

Expand Down
1 change: 0 additions & 1 deletion src/zope/testing/testrunner/filter.py
Expand Up @@ -16,7 +16,6 @@
$Id: __init__.py 86218 2008-05-03 14:17:26Z ctheune $
"""

import time
import zope.testing.testrunner.feature


Expand Down
4 changes: 2 additions & 2 deletions src/zope/testing/testrunner/garbagecollection.py
Expand Up @@ -17,7 +17,7 @@
"""

import gc
import time
import sys
import zope.testing.testrunner.feature


Expand All @@ -32,7 +32,7 @@ def __init__(self, runner):
return

if len(self.threshold) > 3:
output.error("Too many --gc options")
self.runner.options.output.error("Too many --gc options")
sys.exit(1)

def global_setup(self):
Expand Down
1 change: 0 additions & 1 deletion src/zope/testing/testrunner/listing.py
Expand Up @@ -16,7 +16,6 @@
$Id: __init__.py 86218 2008-05-03 14:17:26Z ctheune $
"""

import time
import zope.testing.testrunner.feature


Expand Down
1 change: 0 additions & 1 deletion src/zope/testing/testrunner/logsupport.py
Expand Up @@ -25,7 +25,6 @@
import logging.config
import os.path

from zope.testing import doctest
import zope.testing.testrunner.feature


Expand Down
1 change: 0 additions & 1 deletion src/zope/testing/testrunner/process.py
Expand Up @@ -17,7 +17,6 @@
"""

import sys
import time
import zope.testing.testrunner.feature


Expand Down
6 changes: 3 additions & 3 deletions src/zope/testing/testrunner/runner.py
Expand Up @@ -384,6 +384,8 @@ def runTest(self):
def spawn_layer_in_subprocess(result, script_parts, options, features,
layer_name, layer, failures, errors,
resume_number):
output = options.output

try:
# BBB
if script_parts is None:
Expand Down Expand Up @@ -449,9 +451,7 @@ def spawn_layer_in_subprocess(result, script_parts, options, features,
else:
break
else:
output = options.output
output.error_with_banner("Could not communicate with subprocess:\n"
"\n" + suberr)
output.error_with_banner("Could not communicate with subprocess")

while nfail > 0:
nfail -= 1
Expand Down
1 change: 0 additions & 1 deletion src/zope/testing/testrunner/selftest.py
Expand Up @@ -19,7 +19,6 @@
"""

import pdb
from zope.testing import doctest
import zope.testing.testrunner.feature

real_pdb_set_trace = pdb.set_trace
Expand Down
2 changes: 0 additions & 2 deletions src/zope/testing/testrunner/tb_format.py
Expand Up @@ -16,8 +16,6 @@
$Id: __init__.py 68482 2006-06-04 14:58:55Z jim $
"""

import StringIO
import os
import sys
import traceback
import zope.exceptions.exceptionformatter
Expand Down
20 changes: 20 additions & 0 deletions src/zope/testing/testrunner/testrunner-errors.txt
Expand Up @@ -686,6 +686,26 @@ The -cdiff option requests a standard "context" diff:
Tearing down left over layers:
Tear down zope.testing.testrunner.layer.UnitTests in N.NNN seconds.

Specifying more than one diff option at once causes an error:

>>> sys.argv = 'test --tests-pattern ^pledge$ --cdiff --udiff'.split()
>>> _ = testrunner.run_internal(defaults)
Traceback (most recent call last):
...
SystemExit: 1

>>> sys.argv = 'test --tests-pattern ^pledge$ --cdiff --ndiff'.split()
>>> _ = testrunner.run_internal(defaults)
Traceback (most recent call last):
...
SystemExit: 1

>>> sys.argv = 'test --tests-pattern ^pledge$ --udiff --ndiff'.split()
>>> _ = testrunner.run_internal(defaults)
Traceback (most recent call last):
...
SystemExit: 1


Testing-Module Import Errors
----------------------------
Expand Down
Expand Up @@ -13,7 +13,6 @@
##############################################################################

import unittest
from zope.testing import doctest

class Test(unittest.TestCase):

Expand Down
Expand Up @@ -13,7 +13,6 @@
##############################################################################

import unittest
from zope.testing import doctest

class Test(unittest.TestCase):

Expand Down
1 change: 0 additions & 1 deletion src/zope/testing/testrunner/testrunner-ex/gc0.py
Expand Up @@ -11,7 +11,6 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
import unittest
from zope.testing import doctest

def make_sure_gc_is_disabled():
Expand Down
1 change: 0 additions & 1 deletion src/zope/testing/testrunner/testrunner-ex/gc1.py
Expand Up @@ -11,7 +11,6 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
import unittest
from zope.testing import doctest

def make_sure_gc_threshold_is_one():
Expand Down
1 change: 0 additions & 1 deletion src/zope/testing/testrunner/testrunner-ex/gcset.py
Expand Up @@ -11,7 +11,6 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
import unittest
from zope.testing import doctest

def make_sure_gc_threshold_is_701_11_9():
Expand Down
1 change: 0 additions & 1 deletion src/zope/testing/testrunner/testrunner-ex/gcstats.py
Expand Up @@ -11,7 +11,6 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
import unittest
from zope.testing import doctest

def generate_some_gc_statistics():
Expand Down
2 changes: 1 addition & 1 deletion src/zope/testing/testrunner/testrunner-ex/leak.py
Expand Up @@ -12,7 +12,7 @@
#
##############################################################################

import unittest, sys, time
import unittest, time

class ClassicLeakable:
def __init__(self):
Expand Down
1 change: 0 additions & 1 deletion src/zope/testing/testrunner/testrunner-ex/pledge.py
Expand Up @@ -11,7 +11,6 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
import unittest
from zope.testing import doctest

pledge_template = """\
Expand Down
Expand Up @@ -12,10 +12,9 @@
#
##############################################################################

import unittest
import zope.testing.huh

from zope.testing import doctest

class Test(unittest.TestCase):

def test(self):
Expand Down
Expand Up @@ -13,7 +13,6 @@
##############################################################################

import unittest
from zope.testing import doctest

class Test(unittest.TestCase):

Expand Down
Expand Up @@ -13,7 +13,6 @@
##############################################################################

import unittest
from zope.testing import doctest

class Test(unittest.TestCase):

Expand Down
Expand Up @@ -13,7 +13,6 @@
##############################################################################

import unittest
from zope.testing import doctest

class Test(unittest.TestCase):

Expand Down
19 changes: 19 additions & 0 deletions src/zope/testing/testrunner/testrunner-gc.txt
Expand Up @@ -62,6 +62,25 @@ values:
Tearing down left over layers:
Tear down zope.testing.testrunner.layer.UnitTests in N.NNN seconds.

Specifying more than 3 --gc options is not allowed:


>>> from StringIO import StringIO
>>> out = StringIO()
>>> stdout = sys.stdout
>>> sys.stdout = out

>>> sys.argv = ('test --tests-pattern ^gcset$ --gc 701 --gc 42 --gc 11 --gc 9 -vv'
... .split())
>>> _ = testrunner.run_internal(defaults)
Traceback (most recent call last):
...
SystemExit: 1

>>> sys.stdout = stdout

>>> print out.getvalue()
Too many --gc options

Garbage Collection Statistics
-----------------------------
Expand Down
93 changes: 93 additions & 0 deletions src/zope/testing/testrunner/testrunner-layers-buff.txt
Expand Up @@ -140,3 +140,96 @@ before, the progress output is not buffered.
.
LAYER FINISHED
----------------------------------------------------------------------


Fake an IOError reading the output of the subprocess to exercise the
reporting of that error:

>>> class FakeStdout(object):
... raised = False
... def __init__(self, msg):
... self.msg = msg
... def readline(self):
... if not self.raised:
... self.raised = True
... raise IOError(self.msg)

>>> class FakeStderr(object):
... def __init__(self, msg):
... self.msg = msg
... def read(self):
... return self.msg

>>> class FakeProcess(object):
... def __init__(self, out, err):
... self.stdout = FakeStdout(out)
... self.stderr = FakeStderr(err)

>>> class FakePopen(object):
... def __init__(self, out, err):
... self.out = out
... self.err = err
... def __call__(self, *args, **kw):
... return FakeProcess(self.out, self.err)

>>> import subprocess
>>> Popen = subprocess.Popen
>>> subprocess.Popen = FakePopen(
... "Failure triggered to verify error reporting",
... "0 0 0")

>>> directory_with_tests = os.path.join(this_directory, 'testrunner-ex')
>>> from zope.testing import testrunner
>>> defaults = [
... '--path', directory_with_tests,
... ]
>>> argv = [sys.argv[0],
... '-vv', '--tests-pattern', '^sampletests_buffering.*']

>>> _ = testrunner.run_internal(defaults, argv)
Running tests at level 1
Running sampletests_buffering.Layer1 tests:
Set up sampletests_buffering.Layer1 in N.NNN seconds.
Running:
test_something (sampletests_buffering.TestSomething1)
Ran 1 tests with 0 failures and 0 errors in N.NNN seconds.
Running sampletests_buffering.Layer2 tests:
Tear down sampletests_buffering.Layer1 ... not supported
Error reading subprocess output for sampletests_buffering.Layer2
Failure triggered to verify error reporting
Total: 1 tests, 0 failures, 0 errors in N.NNN seconds.

Now fake an empty stderr to test reporting a failure when
communicating with the subprocess:

>>> subprocess.Popen = FakePopen(
... "Failure triggered to verify error reporting",
... "")

>>> directory_with_tests = os.path.join(this_directory, 'testrunner-ex')
>>> from zope.testing import testrunner
>>> defaults = [
... '--path', directory_with_tests,
... ]
>>> argv = [sys.argv[0],
... '-vv', '--tests-pattern', '^sampletests_buffering.*']

>>> _ = testrunner.run_internal(defaults, argv)
Running tests at level 1
Running sampletests_buffering.Layer1 tests:
Set up sampletests_buffering.Layer1 in N.NNN seconds.
Running:
test_something (sampletests_buffering.TestSomething1)
Ran 1 tests with 0 failures and 0 errors in N.NNN seconds.
Running sampletests_buffering.Layer2 tests:
Tear down sampletests_buffering.Layer1 ... not supported
Error reading subprocess output for sampletests_buffering.Layer2
Failure triggered to verify error reporting
<BLANKLINE>
**********************************************************************
Could not communicate with subprocess
**********************************************************************
<BLANKLINE>
Total: 1 tests, 0 failures, 0 errors in N.NNN seconds.

>>> subprocess.Popen = Popen
4 changes: 1 addition & 3 deletions src/zope/testing/tests.py
Expand Up @@ -16,11 +16,9 @@
$Id$
"""

import os
import re
import sys
import unittest
from zope.testing import doctest, testrunner, renormalizing
from zope.testing import doctest, renormalizing

def test_suite():
return unittest.TestSuite((
Expand Down

0 comments on commit da43ed5

Please sign in to comment.