Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Commit

Permalink
Update test setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
thefunny42 committed Jan 13, 2016
1 parent 94cd731 commit 80c6db3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
16 changes: 11 additions & 5 deletions src/grokcore/json/ftests/test_functional.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import doctest
import re
import unittest, doctest
import grokcore.json

import unittest
from pkg_resources import resource_listdir

from zope.testing import renormalizing
from zope.app.wsgi.testlayer import BrowserLayer, http
import grokcore.json


FunctionalLayer = BrowserLayer(grokcore.json)


checker = renormalizing.RENormalizing([
# Accommodate to exception wrapping in newer versions of mechanize
(re.compile(r'httperror_seek_wrapper:', re.M), 'HTTPError:'),
])


def http_call(method, path, data=None, **kw):
"""Function to help make RESTful calls.
Expand All @@ -32,6 +36,7 @@ def http_call(method, path, data=None, **kw):
request_string += data
return http(request_string, handle_errors=False)


def suiteFromPackage(name):
files = resource_listdir(__name__, name)
suite = unittest.TestSuite()
Expand All @@ -48,14 +53,15 @@ def suiteFromPackage(name):
extraglobs=dict(http_call=http_call,
http=http,
getRootFolder=FunctionalLayer.getRootFolder),
optionflags=(doctest.ELLIPSIS+
doctest.NORMALIZE_WHITESPACE+
optionflags=(doctest.ELLIPSIS +
doctest.NORMALIZE_WHITESPACE +
doctest.REPORT_NDIFF))
test.layer = FunctionalLayer

suite.addTest(test)
return suite


def test_suite():
suite = unittest.TestSuite()
for name in ['json']:
Expand Down
21 changes: 12 additions & 9 deletions src/grokcore/json/tests/test_package.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import doctest
import re
import unittest
from pkg_resources import resource_listdir
from zope.testing import doctest, cleanup, renormalizing

from zope.testing import cleanup, renormalizing


def cleanUpZope(test):
Expand All @@ -12,9 +14,9 @@ def cleanUpZope(test):
# str(Exception) has changed from Python 2.4 to 2.5 (due to
# Exception now being a new-style class). This changes the way
# exceptions appear in traceback printouts.
(re.compile(r"ConfigurationExecutionError: <class '([\w.]+)'>:"),
r'ConfigurationExecutionError: \1:'),
])
(re.compile(
r"ConfigurationExecutionError: <class '([\w.]+)'>:"),
r'ConfigurationExecutionError: \1:')])


def suiteFromPackage(name):
Expand All @@ -29,15 +31,16 @@ def suiteFromPackage(name):
continue

dottedname = 'grokcore.json.tests.%s.%s' % (name, filename[:-3])
test = doctest.DocTestSuite(dottedname,
tearDown=cleanUpZope,
checker=checker,
optionflags=doctest.ELLIPSIS+
doctest.NORMALIZE_WHITESPACE)
test = doctest.DocTestSuite(
dottedname,
tearDown=cleanUpZope,
checker=checker,
optionflags=doctest.ELLIPSIS + doctest.NORMALIZE_WHITESPACE)

suite.addTest(test)
return suite


def test_suite():
suite = unittest.TestSuite()
for name in ['json']:
Expand Down

0 comments on commit 80c6db3

Please sign in to comment.