Skip to content

Commit

Permalink
flake8 ZPublisher/Testing
Browse files Browse the repository at this point in the history
  • Loading branch information
hannosch committed Aug 6, 2016
1 parent 2e9d01e commit efe6118
Show file tree
Hide file tree
Showing 43 changed files with 1,240 additions and 2,009 deletions.
35 changes: 0 additions & 35 deletions src/Testing/README.txt

This file was deleted.

2 changes: 2 additions & 0 deletions src/Testing/ZODButil.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import ZODB
from ZODB.FileStorage import FileStorage


def makeDB():
s = FileStorage('fs_tmp__%s' % os.getpid())
return ZODB.DB(s)


def cleanDB():
for fn in glob('fs_tmp__*'):
os.remove(fn)
14 changes: 7 additions & 7 deletions src/Testing/ZopeTestCase/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
After Marius Gedminas' functional.py module for Zope3.
"""

import sys, re, base64
import base64
import re
import sys
import transaction
import sandbox
import interfaces
Expand Down Expand Up @@ -58,8 +60,8 @@ def publish(self, path, basic=None, env=None, extra=None,
'''Publishes the object at 'path' returning a response object.'''

from StringIO import StringIO
from ZPublisher.Request import Request
from ZPublisher.Response import Response
from ZPublisher.HTTPRequest import HTTPRequest as Request
from ZPublisher.HTTPResponse import HTTPResponse as Response
from ZPublisher.Publish import publish_module

# Commit the sandbox for good measure
Expand All @@ -82,7 +84,7 @@ def publish(self, path, basic=None, env=None, extra=None,
elif len(p) == 2:
[env['PATH_INFO'], env['QUERY_STRING']] = p
else:
raise TypeError, ''
raise TypeError('')

if basic:
env['HTTP_AUTHORIZATION'] = "Basic %s" % base64.encodestring(basic)
Expand All @@ -99,8 +101,7 @@ def publish(self, path, basic=None, env=None, extra=None,
publish_module('Zope2',
debug=not handle_errors,
request=request,
response=response,
)
response=response)

return ResponseWrapper(response, outstream, path)

Expand Down Expand Up @@ -140,4 +141,3 @@ def getHeader(self, name):
def getCookie(self, name):
'''Returns a response cookie.'''
return self.cookies.get(name)

41 changes: 25 additions & 16 deletions src/Testing/ZopeTestCase/zopedoctest/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,14 @@ def __str__(self):
return "%s\n" % (self.header_output)


basicre = re.compile('Basic (.+)?:(.+)?$')
headerre = re.compile('(\S+): (.+)$')


def split_header(header):
return headerre.match(header).group(1, 2)

basicre = re.compile('Basic (.+)?:(.+)?$')

def auth_header(header):
match = basicre.match(header)
if match:
Expand All @@ -111,6 +114,7 @@ def auth_header(header):
def getRootFolder():
return AppZapper().app()


def sync():
getRootFolder()._p_jar.sync()

Expand All @@ -124,7 +128,7 @@ def http(request_string, handle_errors=True):
import urllib
import rfc822
from cStringIO import StringIO
from ZPublisher.Response import Response
from ZPublisher.HTTPResponse import HTTPResponse as Response
from ZPublisher.Publish import publish_module

# Commit work done by previous python code.
Expand All @@ -136,7 +140,7 @@ def http(request_string, handle_errors=True):
# Split off and parse the command line
l = request_string.find('\n')
command_line = request_string[:l].rstrip()
request_string = request_string[l+1:]
request_string = request_string[l + 1:]
method, path, protocol = command_line.split()
path = urllib.unquote(path)

Expand All @@ -154,7 +158,7 @@ def http(request_string, handle_errors=True):
elif len(p) == 2:
[env['PATH_INFO'], env['QUERY_STRING']] = p
else:
raise TypeError, ''
raise TypeError('')

header_output = HTTPHeaderOutput(
protocol, ('x-content-type-warning', 'x-powered-by',
Expand All @@ -173,7 +177,7 @@ def http(request_string, handle_errors=True):
name = 'HTTP_' + name
env[name] = value.rstrip()

if env.has_key('HTTP_AUTHORIZATION'):
if 'HTTP_AUTHORIZATION' in env:
env['HTTP_AUTHORIZATION'] = auth_header(env['HTTP_AUTHORIZATION'])

outstream = StringIO()
Expand All @@ -183,8 +187,8 @@ def http(request_string, handle_errors=True):
response=response,
stdin=instream,
environ=env,
debug=not handle_errors,
)
debug=not handle_errors)

header_output.setResponseStatus(response.getStatus(), response.errmsg)
header_output.setResponseHeaders(response.headers)
header_output.headersl.extend(response._cookie_list())
Expand Down Expand Up @@ -246,6 +250,7 @@ def setup_test_class(self):
test_instance = test_class()

kwsetUp = self._kw.get('setUp')

def setUp(test):
test_instance.setUp()
test.globs['test'] = test
Expand All @@ -264,6 +269,7 @@ def setUp(test):
self._kw['setUp'] = setUp

kwtearDown = self._kw.get('tearDown')

def tearDown(test):
if kwtearDown is not None:
kwtearDown(test_instance)
Expand All @@ -273,8 +279,8 @@ def tearDown(test):

def setup_optionflags(self):
if 'optionflags' not in self._kw:
self._kw['optionflags'] = (doctest.ELLIPSIS
| doctest.NORMALIZE_WHITESPACE)
self._kw['optionflags'] = (
doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE)


class FunctionalSuiteFactory(ZopeSuiteFactory):
Expand All @@ -285,7 +291,8 @@ def setup_globs(self):
globs['http'] = http
globs['getRootFolder'] = getRootFolder
globs['sync'] = sync
globs['user_auth'] = base64.encodestring('%s:%s' % (user_name, user_password))
globs['user_auth'] = base64.encodestring(
'%s:%s' % (user_name, user_password))

def setup_test_class(self):
test_class = self._kw.get('test_class', FunctionalTestCase)
Expand All @@ -297,7 +304,7 @@ def setup_test_class(self):
warnings.warn(("The test_class you are using doesn't "
"subclass from ZopeTestCase.Functional. "
"Please fix that."), UserWarning, 4)
if not 'Functional' in name:
if 'Functional' not in name:
name = 'Functional%s' % name
test_class = type(name, (Functional, test_class), {})

Expand All @@ -306,24 +313,27 @@ def setup_test_class(self):

def setup_optionflags(self):
if 'optionflags' not in self._kw:
self._kw['optionflags'] = (doctest.ELLIPSIS
| doctest.REPORT_NDIFF
| doctest.NORMALIZE_WHITESPACE)
self._kw['optionflags'] = (
doctest.ELLIPSIS | doctest.REPORT_NDIFF |
doctest.NORMALIZE_WHITESPACE)


def ZopeDocTestSuite(module=None, **kw):
module = doctest._normalize_module(module)
return ZopeSuiteFactory(module, **kw).doctestsuite()


def ZopeDocFileSuite(*paths, **kw):
if kw.get('module_relative', True):
kw['package'] = doctest._normalize_module(kw.get('package'))
return ZopeSuiteFactory(*paths, **kw).docfilesuite()


def FunctionalDocTestSuite(module=None, **kw):
module = doctest._normalize_module(module)
return FunctionalSuiteFactory(module, **kw).doctestsuite()


def FunctionalDocFileSuite(*paths, **kw):
if kw.get('module_relative', True):
kw['package'] = doctest._normalize_module(kw.get('package'))
Expand All @@ -335,5 +345,4 @@ def FunctionalDocFileSuite(*paths, **kw):
'ZopeDocFileSuite',
'FunctionalDocTestSuite',
'FunctionalDocFileSuite',
]

]
35 changes: 0 additions & 35 deletions src/Testing/common.py

This file was deleted.

9 changes: 4 additions & 5 deletions src/Testing/custom_zodb.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@

import os
import logging
import ZODB

LOG = logging.getLogger('Testing')


def getStorage():
""" Return a storage instance for running ZopeTestCase based
""" Return a storage instance for running ZopeTestCase based
tests. By default a DemoStorage is used. Setting
$TEST_ZEO_HOST/TEST_ZEO_PORT environment variables allows you
to use a ZEO server instead. A file storage can be configured
Expand All @@ -15,14 +14,14 @@ def getStorage():

get = os.environ.get

if os.environ.has_key('TEST_ZEO_HOST') and os.environ.has_key('TEST_ZEO_PORT'):
if 'TEST_ZEO_HOST' in os.environ and 'TEST_ZEO_PORT' in os.environ:
from ZEO.ClientStorage import ClientStorage
zeo_host = get('TEST_ZEO_HOST')
zeo_port = int(get('TEST_ZEO_PORT'))
LOG.info('Using ZEO server (%s:%d)' % (zeo_host, zeo_port))
return ClientStorage((zeo_host, zeo_port))

elif os.environ.has_key('TEST_FILESTORAGE'):
elif 'TEST_FILESTORAGE' in os.environ:
import ZODB.FileStorage
datafs = get('TEST_FILESTORAGE')
LOG.info('Using Filestorage at (%s)' % datafs)
Expand Down
Loading

0 comments on commit efe6118

Please sign in to comment.