summaryrefslogtreecommitdiff
path: root/src/zope/component/tests/__init__.py
blob: bc508bb36d53e2af1e0872d43a1009231d17870f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import unittest

def skipIfNoSecurity(testfunc):
    try:
        import zope.security
    except ImportError: # pragma: no cover
        return unittest.skip("zope.security not installed")(testfunc)
    return testfunc

def fails_if_called(test, msg="This function must not be called.",
                    arguments=True):
    """
    Return a new function (accepting any arguments)
    that will call test.fail(msg) if it is called.

    :keyword bool arguments: If set to ``False``, then we will
        not accept any arguments. This can avoid
        masking when we would expect a TypeError to be raised by
        calling an instance method against a class.
    """
    if not arguments:
        return lambda: test.fail(msg)
    return lambda *_args, **__kwargs: test.fail(msg)