From de069f1a06a844f7c414fd0a30866306c2f89766 Mon Sep 17 00:00:00 2001 From: "Guido A.J. Stevens" Date: Fri, 12 Jan 2018 07:52:02 +0000 Subject: [PATCH 1/2] Add coverage, bypass bootstrap. --- requirements.txt | 4 ++++ tox.ini | 26 ++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e98d3e3 --- /dev/null +++ b/requirements.txt @@ -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 diff --git a/tox.ini b/tox.ini index 7efd092..4f9f3ee 100644 --- a/tox.ini +++ b/tox.ini @@ -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 From 1d0810242d6bdc40b198918b457b58fd7b673f09 Mon Sep 17 00:00:00 2001 From: "Guido A.J. Stevens" Date: Fri, 12 Jan 2018 09:53:26 +0000 Subject: [PATCH 2/2] Reorganize tests, declare missing test dependencies --- .gitignore | 10 ++++--- buildout.cfg | 4 +-- setup.py | 7 ++--- src/grokcore/json/ftesting.zcml | 2 +- src/grokcore/json/tests/__init__.py | 26 ++++++++++++++++++- src/grokcore/json/tests/base/__init__.py | 1 + .../{ftests => tests/base/json}/__init__.py | 0 .../json/tests/{ => base}/json/json_layers.py | 4 +-- .../{ => base}/json/missing_permission.py | 2 +- .../{ => base}/json/missing_permission2.py | 2 +- .../{ => base}/json/missing_permission3.py | 0 .../tests/{ => base}/json/multiple_require.py | 2 +- .../json/tests/{ => base}/json/nocontext.py | 2 +- .../json/tests/{ => base}/json/nomethods.py | 2 +- .../json/tests/{ => base}/json/view_lookup.py | 8 +++--- .../tests/{json => functional}/__init__.py | 0 .../functional}/json/__init__.py | 0 .../{ftests => tests/functional}/json/json.py | 0 .../tests/{test_package.py => test_base.py} | 6 +++-- .../json/{ftests => tests}/test_functional.py | 26 +++++++++++-------- 20 files changed, 70 insertions(+), 34 deletions(-) create mode 100644 src/grokcore/json/tests/base/__init__.py rename src/grokcore/json/{ftests => tests/base/json}/__init__.py (100%) rename src/grokcore/json/tests/{ => base}/json/json_layers.py (95%) rename src/grokcore/json/tests/{ => base}/json/missing_permission.py (88%) rename src/grokcore/json/tests/{ => base}/json/missing_permission2.py (87%) rename src/grokcore/json/tests/{ => base}/json/missing_permission3.py (100%) rename src/grokcore/json/tests/{ => base}/json/multiple_require.py (88%) rename src/grokcore/json/tests/{ => base}/json/nocontext.py (83%) rename src/grokcore/json/tests/{ => base}/json/nomethods.py (82%) rename src/grokcore/json/tests/{ => base}/json/view_lookup.py (90%) rename src/grokcore/json/tests/{json => functional}/__init__.py (100%) rename src/grokcore/json/{ftests => tests/functional}/json/__init__.py (100%) rename src/grokcore/json/{ftests => tests/functional}/json/json.py (100%) rename src/grokcore/json/tests/{test_package.py => test_base.py} (87%) rename src/grokcore/json/{ftests => tests}/test_functional.py (77%) diff --git a/.gitignore b/.gitignore index 7d9d772..38b45ca 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/buildout.cfg b/buildout.cfg index a3dd251..15a02cd 100644 --- a/buildout.cfg +++ b/buildout.cfg @@ -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'] diff --git a/setup.py b/setup.py index ad6c87c..05a204d 100644 --- a/setup.py +++ b/setup.py @@ -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( diff --git a/src/grokcore/json/ftesting.zcml b/src/grokcore/json/ftesting.zcml index 2d8f87b..b95304f 100644 --- a/src/grokcore/json/ftesting.zcml +++ b/src/grokcore/json/ftesting.zcml @@ -8,6 +8,6 @@ - + diff --git a/src/grokcore/json/tests/__init__.py b/src/grokcore/json/tests/__init__.py index 027150d..41c30c0 100644 --- a/src/grokcore/json/tests/__init__.py +++ b/src/grokcore/json/tests/__init__.py @@ -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) diff --git a/src/grokcore/json/tests/base/__init__.py b/src/grokcore/json/tests/base/__init__.py new file mode 100644 index 0000000..027150d --- /dev/null +++ b/src/grokcore/json/tests/base/__init__.py @@ -0,0 +1 @@ +# make this directory a package diff --git a/src/grokcore/json/ftests/__init__.py b/src/grokcore/json/tests/base/json/__init__.py similarity index 100% rename from src/grokcore/json/ftests/__init__.py rename to src/grokcore/json/tests/base/json/__init__.py diff --git a/src/grokcore/json/tests/json/json_layers.py b/src/grokcore/json/tests/base/json/json_layers.py similarity index 95% rename from src/grokcore/json/tests/json/json_layers.py rename to src/grokcore/json/tests/base/json/json_layers.py index db822d3..eb61c68 100644 --- a/src/grokcore/json/tests/json/json_layers.py +++ b/src/grokcore/json/tests/base/json/json_layers.py @@ -33,7 +33,7 @@ Traceback (most recent call last): ... zope.interface.interfaces.ComponentLookupError: \ - ((, \ + ((, \ ), \ , 'public') @@ -44,7 +44,7 @@ Traceback (most recent call last): ... zope.interface.interfaces.ComponentLookupError: \ - ((, \ + ((, \ ), \ , 'another') diff --git a/src/grokcore/json/tests/json/missing_permission.py b/src/grokcore/json/tests/base/json/missing_permission.py similarity index 88% rename from src/grokcore/json/tests/json/missing_permission.py rename to src/grokcore/json/tests/base/json/missing_permission.py index 7592487..b974cd0 100644 --- a/src/grokcore/json/tests/json/missing_permission.py +++ b/src/grokcore/json/tests/base/json/missing_permission.py @@ -8,7 +8,7 @@ ... zope.configuration.config.ConfigurationExecutionError: \ martian.error.GrokError: Undefined permission 'doesnt.exist' in \ - . \ + . \ Use grok.Permission first... """ diff --git a/src/grokcore/json/tests/json/missing_permission2.py b/src/grokcore/json/tests/base/json/missing_permission2.py similarity index 87% rename from src/grokcore/json/tests/json/missing_permission2.py rename to src/grokcore/json/tests/base/json/missing_permission2.py index 38f580b..1762149 100644 --- a/src/grokcore/json/tests/json/missing_permission2.py +++ b/src/grokcore/json/tests/base/json/missing_permission2.py @@ -9,7 +9,7 @@ ... zope.configuration.config.ConfigurationExecutionError: \ martian.error.GrokError: Undefined permission 'doesnt.exist' in \ - . \ + . \ Use grok.Permission first... """ diff --git a/src/grokcore/json/tests/json/missing_permission3.py b/src/grokcore/json/tests/base/json/missing_permission3.py similarity index 100% rename from src/grokcore/json/tests/json/missing_permission3.py rename to src/grokcore/json/tests/base/json/missing_permission3.py diff --git a/src/grokcore/json/tests/json/multiple_require.py b/src/grokcore/json/tests/base/json/multiple_require.py similarity index 88% rename from src/grokcore/json/tests/json/multiple_require.py rename to src/grokcore/json/tests/base/json/multiple_require.py index 3479186..4ff3fbb 100644 --- a/src/grokcore/json/tests/json/multiple_require.py +++ b/src/grokcore/json/tests/base/json/multiple_require.py @@ -6,7 +6,7 @@ Traceback (most recent call last): ... martian.error.GrokError: grok.require was called multiple times in \ - . It may \ + . It may \ only be set once for a class. """ diff --git a/src/grokcore/json/tests/json/nocontext.py b/src/grokcore/json/tests/base/json/nocontext.py similarity index 83% rename from src/grokcore/json/tests/json/nocontext.py rename to src/grokcore/json/tests/base/json/nocontext.py index 61f5b7f..b9d11ed 100644 --- a/src/grokcore/json/tests/json/nocontext.py +++ b/src/grokcore/json/tests/base/json/nocontext.py @@ -8,7 +8,7 @@ Traceback (most recent call last): ... martian.error.GrokError: No module-level context for \ - , please use the \ + , please use the \ 'context' directive. """ diff --git a/src/grokcore/json/tests/json/nomethods.py b/src/grokcore/json/tests/base/json/nomethods.py similarity index 82% rename from src/grokcore/json/tests/json/nomethods.py rename to src/grokcore/json/tests/base/json/nomethods.py index dbf089a..0338b4c 100644 --- a/src/grokcore/json/tests/json/nomethods.py +++ b/src/grokcore/json/tests/base/json/nomethods.py @@ -4,7 +4,7 @@ Traceback (most recent call last): ... martian.error.GrokError: \ - does not \ + does not \ define any public methods. Please add methods to this class to enable \ its registration. diff --git a/src/grokcore/json/tests/json/view_lookup.py b/src/grokcore/json/tests/base/json/view_lookup.py similarity index 90% rename from src/grokcore/json/tests/json/view_lookup.py rename to src/grokcore/json/tests/base/json/view_lookup.py index 3fad21c..c8309fe 100644 --- a/src/grokcore/json/tests/json/view_lookup.py +++ b/src/grokcore/json/tests/base/json/view_lookup.py @@ -29,7 +29,7 @@ Traceback (most recent call last): ... zope.interface.interfaces.ComponentLookupError: \ - ((, \ + ((, \ ), \ , '_private') @@ -41,7 +41,7 @@ Traceback (most recent call last): ... zope.interface.interfaces.ComponentLookupError: \ - ((, \ + ((, \ ), \ , '__call__') @@ -52,7 +52,7 @@ Traceback (most recent call last): ... zope.interface.interfaces.ComponentLookupError: \ - ((, \ + ((, \ ), \ , 'browserDefault') @@ -60,7 +60,7 @@ Traceback (most recent call last): ... zope.interface.interfaces.ComponentLookupError: \ - ((, \ + ((, \ ), \ , 'publishTraverse') diff --git a/src/grokcore/json/tests/json/__init__.py b/src/grokcore/json/tests/functional/__init__.py similarity index 100% rename from src/grokcore/json/tests/json/__init__.py rename to src/grokcore/json/tests/functional/__init__.py diff --git a/src/grokcore/json/ftests/json/__init__.py b/src/grokcore/json/tests/functional/json/__init__.py similarity index 100% rename from src/grokcore/json/ftests/json/__init__.py rename to src/grokcore/json/tests/functional/json/__init__.py diff --git a/src/grokcore/json/ftests/json/json.py b/src/grokcore/json/tests/functional/json/json.py similarity index 100% rename from src/grokcore/json/ftests/json/json.py rename to src/grokcore/json/tests/functional/json/json.py diff --git a/src/grokcore/json/tests/test_package.py b/src/grokcore/json/tests/test_base.py similarity index 87% rename from src/grokcore/json/tests/test_package.py rename to src/grokcore/json/tests/test_base.py index 32b0403..935988c 100644 --- a/src/grokcore/json/tests/test_package.py +++ b/src/grokcore/json/tests/test_base.py @@ -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'): @@ -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, diff --git a/src/grokcore/json/ftests/test_functional.py b/src/grokcore/json/tests/test_functional.py similarity index 77% rename from src/grokcore/json/ftests/test_functional.py rename to src/grokcore/json/tests/test_functional.py index aec3ed3..c448e54 100644 --- a/src/grokcore/json/ftests/test_functional.py +++ b/src/grokcore/json/tests/test_functional.py @@ -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)