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

Commit

Permalink
Merge pull request #6 from gyst/master
Browse files Browse the repository at this point in the history
 Reorganize tests,
  • Loading branch information
janwijbrand committed Jan 12, 2018
2 parents a27fd5e + 1d08102 commit 1f77427
Show file tree
Hide file tree
Showing 22 changed files with 98 additions and 36 deletions.
10 changes: 7 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
__pycache__
.coverage
*.pyc
.coverage*
.installed.cfg
.tox
*.pyc
__pycache__
bin
develop-eggs
htmlcov/
lib/
parts
pip-selfcheck.json
pyvenv.cfg
src/*.egg-info
4 changes: 2 additions & 2 deletions buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ grokcore.json =
[interpreter]
recipe = zc.recipe.egg
eggs = grokcore.layout
interpreter = python
interpreter = py

[test]
recipe = zc.recipe.testrunner
eggs =
grokcore.json
grokcore.json[test]
defaults = ['--tests-pattern', '^f?tests$', '-v']
defaults = ['-vc']
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# NOTE: setuptools and zc.buildout versions must be in sync with:
# ztk-versions.cfg
setuptools==38.2.4
zc.buildout==2.10.0
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ def read(*rnames):
)

tests_require = [
'grokcore.view[test]',
'grokcore.view[security_publication]',
'zope.testing',
'zope.app.wsgi',
'grokcore.view[test]',
'zope.app.appsetup',
'zope.app.wsgi[test]',
'zope.testbrowser',
'zope.testing',
]

setup(
Expand Down
2 changes: 1 addition & 1 deletion src/grokcore/json/ftesting.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
<include package="grokcore.view" file="ftesting.zcml" />
<include package="grokcore.json" />
<include package="grokcore.view" file="publication_security.zcml" />
<grok:grok package=".ftests" />
<grok:grok package=".tests.functional" />

</configure>
26 changes: 25 additions & 1 deletion src/grokcore/json/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
# make this directory a package
##############################################################################
#
# Copyright (c) 2006-2007 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################

from grokcore.component import *
from grokcore.security import *
from grokcore.view import *


from grokcore.json.components import JSON

from grokcore.json.interfaces import IGrokcoreJSONAPI
from zope.interface import moduleProvides
moduleProvides(IGrokcoreJSONAPI)
__all__ = list(IGrokcoreJSONAPI)
1 change: 1 addition & 0 deletions src/grokcore/json/tests/base/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# make this directory a package
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
Traceback (most recent call last):
...
zope.interface.interfaces.ComponentLookupError: \
((<grokcore.json.tests.json.json_layers.Mammoth object at ...>, \
((<grokcore.json.tests.base.json.json_layers.Mammoth object at ...>, \
<zope.publisher.browser.TestRequest instance URL=http://127.0.0.1>), \
<InterfaceClass zope.interface.Interface>, 'public')
Expand All @@ -44,7 +44,7 @@
Traceback (most recent call last):
...
zope.interface.interfaces.ComponentLookupError: \
((<grokcore.json.tests.json.json_layers.Mammoth object at ...>, \
((<grokcore.json.tests.base.json.json_layers.Mammoth object at ...>, \
<zope.publisher.browser.TestRequest instance URL=http://127.0.0.1>), \
<InterfaceClass zope.interface.Interface>, 'another')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
...
zope.configuration.config.ConfigurationExecutionError: \
martian.error.GrokError: Undefined permission 'doesnt.exist' in \
<class 'grokcore.json.tests.json.missing_permission.MissingPermission'>. \
<class 'grokcore.json.tests.base.json.missing_permission.MissingPermission'>. \
Use grok.Permission first...
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
...
zope.configuration.config.ConfigurationExecutionError: \
martian.error.GrokError: Undefined permission 'doesnt.exist' in \
<class 'grokcore.json.tests.json.missing_permission2.MissingPermission'>. \
<class 'grokcore.json.tests.base.json.missing_permission2.MissingPermission'>. \
Use grok.Permission first...
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Traceback (most recent call last):
...
martian.error.GrokError: grok.require was called multiple times in \
<class 'grokcore.json.tests.json.multiple_require.MultipleJSON'>. It may \
<class 'grokcore.json.tests.base.json.multiple_require.MultipleJSON'>. It may \
only be set once for a class.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Traceback (most recent call last):
...
martian.error.GrokError: No module-level context for \
<class 'grokcore.json.tests.json.nocontext.TestJSON'>, please use the \
<class 'grokcore.json.tests.base.json.nocontext.TestJSON'>, please use the \
'context' directive.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Traceback (most recent call last):
...
martian.error.GrokError: \
<class 'grokcore.json.tests.json.nomethods.RemoteCaveman'> does not \
<class 'grokcore.json.tests.base.json.nomethods.RemoteCaveman'> does not \
define any public methods. Please add methods to this class to enable \
its registration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
Traceback (most recent call last):
...
zope.interface.interfaces.ComponentLookupError: \
((<grokcore.json.tests.json.view_lookup.Mammoth object at ...>, \
((<grokcore.json.tests.base.json.view_lookup.Mammoth object at ...>, \
<zope.publisher.browser.TestRequest instance URL=http://127.0.0.1>), \
<InterfaceClass zope.interface.Interface>, '_private')
Expand All @@ -41,7 +41,7 @@
Traceback (most recent call last):
...
zope.interface.interfaces.ComponentLookupError: \
((<grokcore.json.tests.json.view_lookup.Mammoth object at ...>, \
((<grokcore.json.tests.base.json.view_lookup.Mammoth object at ...>, \
<zope.publisher.browser.TestRequest instance URL=http://127.0.0.1>), \
<InterfaceClass zope.interface.Interface>, '__call__')
Expand All @@ -52,15 +52,15 @@
Traceback (most recent call last):
...
zope.interface.interfaces.ComponentLookupError: \
((<grokcore.json.tests.json.view_lookup.Mammoth object at ...>, \
((<grokcore.json.tests.base.json.view_lookup.Mammoth object at ...>, \
<zope.publisher.browser.TestRequest instance URL=http://127.0.0.1>), \
<InterfaceClass zope.interface.Interface>, 'browserDefault')
>>> view = getMultiAdapter((mammoth, request), name='publishTraverse')
Traceback (most recent call last):
...
zope.interface.interfaces.ComponentLookupError: \
((<grokcore.json.tests.json.view_lookup.Mammoth object at ...>, \
((<grokcore.json.tests.base.json.view_lookup.Mammoth object at ...>, \
<zope.publisher.browser.TestRequest instance URL=http://127.0.0.1>), \
<InterfaceClass zope.interface.Interface>, 'publishTraverse')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def cleanUpZope(test):


def suiteFromPackage(name):
files = resource_listdir(__name__, name)
layer_dir = 'base'
files = resource_listdir(__name__, '{}/{}'.format(layer_dir, name))
suite = unittest.TestSuite()
for filename in files:
if not filename.endswith('.py'):
Expand All @@ -30,7 +31,8 @@ def suiteFromPackage(name):
if filename == '__init__.py':
continue

dottedname = 'grokcore.json.tests.%s.%s' % (name, filename[:-3])
dottedname = 'grokcore.json.tests.%s.%s.%s' % (
layer_dir, name, filename[:-3])
test = doctest.DocTestSuite(
dottedname,
tearDown=cleanUpZope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,31 @@ def http_call(app, method, path, data=None, handle_errors=False, **kw):


def suiteFromPackage(name):
files = resource_listdir(__name__, name)
layer_dir = 'functional'
files = resource_listdir(__name__, '{}/{}'.format(layer_dir, name))
suite = unittest.TestSuite()
globs = dict(
getRootFolder=layer.getRootFolder,
http_call=http_call,
wsgi_app=layer.make_wsgi_app)
optionflags = (
doctest.ELLIPSIS +
doctest.NORMALIZE_WHITESPACE +
doctest.REPORT_NDIFF +
renormalizing.IGNORE_EXCEPTION_MODULE_IN_PYTHON2)
for filename in files:
if not filename.endswith('.py'):
continue
if filename == '__init__.py':
continue

dottedname = 'grokcore.json.ftests.%s.%s' % (name, filename[:-3])
dottedname = 'grokcore.json.tests.%s.%s.%s' % (
layer_dir, name, filename[:-3])
test = doctest.DocTestSuite(
dottedname,
checker=checker,
extraglobs=dict(
getRootFolder=layer.getRootFolder,
http_call=http_call,
wsgi_app=layer.make_wsgi_app),
optionflags=(
doctest.ELLIPSIS +
doctest.NORMALIZE_WHITESPACE +
doctest.REPORT_NDIFF +
renormalizing.IGNORE_EXCEPTION_MODULE_IN_PYTHON2))
extraglobs=globs,
optionflags=optionflags)
test.layer = layer

suite.addTest(test)
Expand Down
26 changes: 24 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
[tox]
envlist =
coverage-clean,
py27,
py34,
py35,
py36,
pypy,
pypy3
pypy3,
coverage-report

[testenv]
commands =
coverage run -m zope.testrunner --test-path=src {posargs: -vc}
coverage run --source=grokcore.json -m zope.testrunner --test-path=src {posargs:-vc}
setenv =
COVERAGE_FILE=.coverage.{envname}
deps =
.[test]
zope.testrunner
coverage

[testenv:coverage-clean]
deps = coverage
setenv =
COVERAGE_FILE=.coverage
skip_install = true
commands = coverage erase

[testenv:coverage-report]
deps = coverage
setenv =
COVERAGE_FILE=.coverage
skip_install = true
commands =
coverage combine
coverage report
coverage html
coverage

0 comments on commit 1f77427

Please sign in to comment.