Skip to content
This repository has been archived by the owner on May 15, 2020. It is now read-only.

Commit

Permalink
Add helper to determine zope.app.testing usability.
Browse files Browse the repository at this point in the history
While z3c.testsetup can work also without zope.app.testing
installed, it runs into trouble when z.a.testing is installed but
not in a usable state. This is the case with Python 3.x at the
moment: you can install it, but it will be broken.

Therefore we need a way to determine clearly (in tests and code)
whether we can import *and use* zope.app.testing. The new function
is meant for that purpose.
  • Loading branch information
ulif committed May 7, 2015
1 parent df53477 commit 2f645a0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/z3c/testsetup/tests/test_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
""" Tests for `z3c.testsetup.util`.
Most of `z3c.testsetup.util` helper functions are tested in doctest
files called ``util.txt`` (yes, there are two of them). As this kind of
doctesting is a hell to debug and (in times of Sphinx) even not very
useful for documentation, we write down new tests in Python.
"""
import unittest
from z3c.testsetup.util import got_working_zope_app_testing


class TestUtil(unittest.TestCase):

def test_got_working_zope_app_testing(self):
# we can generally determine whether zope.app.testing is useable
result = got_working_zope_app_testing()
assert (result is True) or (result is False)
18 changes: 18 additions & 0 deletions src/z3c/testsetup/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,21 @@ def get_attribute(name):
name, attr = name.rsplit('.', 1)
obj = import_name(name)
return getattr(obj, attr)


def got_working_zope_app_testing():
"""Determine whether we have a working `zope.app.testing` installed.
Please do not make any assumptions about how the "workingness" of
`zope.app.testing` in an environment is determined.
"""
try:
from zope.app.testing.functional import (
HTTPCaller, getRootFolder, sync, ZCMLLayer,
FunctionalDocFileSuite, FunctionalTestSetup)
return True
except:
# any problem here (not only ImportError) is an indicator for
# serious trouble with zope.app.testing.
pass
return False

0 comments on commit 2f645a0

Please sign in to comment.