diff options
author | Jason Madden <jamadden@gmail.com> | 2017-09-11 07:36:00 -0500 |
---|---|---|
committer | Jason Madden <jamadden@gmail.com> | 2017-09-11 07:36:00 -0500 |
commit | aac82c40249095ec98afca4e88332e1db1790470 (patch) | |
tree | c1e3247cb68507bdce169a17766091bd59c535f4 /src/zope | |
parent | 0a852da59af04f98c50e0cbd8fbd68f2ab5fefbe (diff) | |
download | zope-security-aac82c40249095ec98afca4e88332e1db1790470.tar.gz |
Always test watching checkers. Quiet their output to stderr.issue8
Diffstat (limited to 'src/zope')
-rw-r--r-- | src/zope/security/tests/__init__.py | 18 | ||||
-rw-r--r-- | src/zope/security/tests/test_checker.py | 48 | ||||
-rw-r--r-- | src/zope/security/tests/test_decorator.py | 11 | ||||
-rw-r--r-- | src/zope/security/tests/test_location.py | 20 |
4 files changed, 65 insertions, 32 deletions
diff --git a/src/zope/security/tests/__init__.py b/src/zope/security/tests/__init__.py index b711d36..cab4c90 100644 --- a/src/zope/security/tests/__init__.py +++ b/src/zope/security/tests/__init__.py @@ -1,2 +1,16 @@ -# -# This file is necessary to make this directory a package. +import io + + +class QuietWatchingChecker(object): + # zope.testrunner does not support setUp/tearDownModule, + # so we use a mixin class to make sure we don't flood stderr + # with pointless printing when testing watching checkers + + def setUp(self): + from zope.security import checker + self.__old_file = checker.CheckerLoggingMixin._file + checker.CheckerLoggingMixin._file = io.StringIO() if bytes is not str else io.BytesIO() + + def tearDown(self): + from zope.security import checker + checker.CheckerLoggingMixin._file = self.__old_file diff --git a/src/zope/security/tests/test_checker.py b/src/zope/security/tests/test_checker.py index 9aaee38..d5cdc7f 100644 --- a/src/zope/security/tests/test_checker.py +++ b/src/zope/security/tests/test_checker.py @@ -13,8 +13,11 @@ ############################################################################## """Tests for zope.security.checker """ + import unittest + from zope.security import checker +from zope.security.tests import QuietWatchingChecker def _skip_if_not_Py2(testfunc): import sys @@ -28,6 +31,7 @@ def _skip_if_no_btrees(testfunc): else: return testfunc + class Test_ProxyFactory(unittest.TestCase): def _callFUT(self, object, checker=None): @@ -199,7 +203,7 @@ class Test_canAccess(unittest.TestCase): _marker = [] -class CheckerTestsBase(object): +class CheckerTestsBase(QuietWatchingChecker): def _getTargetClass(self): raise NotImplementedError("Subclasses must define") @@ -586,16 +590,20 @@ class CheckerTestsBase(object): class TestCheckerPy(CheckerTestsBase, unittest.TestCase): def _getTargetClass(self): - from zope.security.checker import CheckerPy - return CheckerPy + return checker.CheckerPy class TestChecker(CheckerTestsBase, unittest.TestCase): def _getTargetClass(self): - from zope.security.checker import Checker - return Checker + return checker.Checker +@unittest.skipIf(checker.Checker is checker.WatchingChecker, + "WatchingChecker is the default") +class TestWatchingChecker(TestChecker): + + def _getTargetClass(self): + return checker.WatchingChecker class TestTracebackSupplement(unittest.TestCase): @@ -1116,7 +1124,8 @@ class Test_undefineChecker(unittest.TestCase): self.assertFalse(Foo in _checkers) -class TestCombinedChecker(unittest.TestCase): +class TestCombinedChecker(QuietWatchingChecker, + unittest.TestCase): def _getTargetClass(self): from zope.security.checker import CombinedChecker @@ -1339,6 +1348,12 @@ class TestCombinedChecker(unittest.TestCase): finally: del thread_local.interaction +@unittest.skipIf(checker.WatchingCombinedChecker is checker.CombinedChecker, + "WatchingCombinedChecker is the default") +class TestWatchingCombinedChecker(TestCombinedChecker): + + def _getTargetClass(self): + return checker.WatchingCombinedChecker class TestCheckerLoggingMixin(unittest.TestCase): @@ -1605,23 +1620,26 @@ class TestBasicTypes(unittest.TestCase): # Pre-geddon tests start here -class TestSecurityPolicy(unittest.TestCase): +class TestSecurityPolicy(QuietWatchingChecker, + unittest.TestCase): def setUp(self): + super(TestSecurityPolicy, self).setUp() + from zope.security.management import newInteraction from zope.security.management import setSecurityPolicy - from zope.security.checker import _clear - _clear() + checker._clear() self.__oldpolicy = setSecurityPolicy(self._makeSecurityPolicy()) newInteraction() def tearDown(self): + super(TestSecurityPolicy, self).tearDown() + from zope.security.management import endInteraction from zope.security.management import setSecurityPolicy - from zope.security.checker import _clear endInteraction() setSecurityPolicy(self.__oldpolicy) - _clear() + checker._clear() def _makeSecurityPolicy(self): from zope.interface import implementer @@ -2193,15 +2211,17 @@ class TestMixinDecoratedChecker(unittest.TestCase): from zope.security.checker import Checker return Checker(self.decorationGetMap, self.decorationSetMap) -class TestCombinedCheckerMixin(TestMixinDecoratedChecker, unittest.TestCase): +class TestCombinedCheckerMixin(QuietWatchingChecker, + TestMixinDecoratedChecker, + unittest.TestCase): def setUp(self): - unittest.TestCase.setUp(self) + super(TestCombinedCheckerMixin, self).setUp() self.decoratedSetUp() def tearDown(self): self.decoratedTearDown() - unittest.TestCase.tearDown(self) + super(TestCombinedCheckerMixin, self).tearDown() def test_checking(self): from zope.security.interfaces import Unauthorized diff --git a/src/zope/security/tests/test_decorator.py b/src/zope/security/tests/test_decorator.py index 9319e6b..650380d 100644 --- a/src/zope/security/tests/test_decorator.py +++ b/src/zope/security/tests/test_decorator.py @@ -14,14 +14,19 @@ """Test zope.security.decorator """ import unittest +from zope.security.tests import QuietWatchingChecker -class DecoratedSecurityCheckerDescriptorTests(unittest.TestCase): + +class DecoratedSecurityCheckerDescriptorTests(QuietWatchingChecker, + unittest.TestCase): def setUp(self): + super(DecoratedSecurityCheckerDescriptorTests, self).setUp() from zope.security.checker import _clear _clear() def tearDown(self): + super(DecoratedSecurityCheckerDescriptorTests, self).tearDown() from zope.security.checker import _clear _clear() @@ -168,6 +173,4 @@ class DecoratedSecurityCheckerDescriptorTests(unittest.TestCase): def test_suite(): - return unittest.TestSuite(( - unittest.makeSuite(DecoratedSecurityCheckerDescriptorTests), - )) + return unittest.defaultTestLoader.loadTestsFromName(__name__) diff --git a/src/zope/security/tests/test_location.py b/src/zope/security/tests/test_location.py index 8905fca..5625f4e 100644 --- a/src/zope/security/tests/test_location.py +++ b/src/zope/security/tests/test_location.py @@ -15,21 +15,19 @@ """ import unittest +from zope.security.tests import QuietWatchingChecker def _skip_wo_zope_location(testfunc): try: - import zope.location + import zope.location as zl except ImportError: - from functools import update_wrapper - def dummy(self): - pass - update_wrapper(dummy, testfunc) - return dummy - else: - return testfunc + zl = None + return unittest.skipIf(zl is None, "Need zope.location")(testfunc) -class LocationSecurityProxyTests(unittest.TestCase): + +class LocationSecurityProxyTests(QuietWatchingChecker, + unittest.TestCase): @_skip_wo_zope_location def test_locationproxy_security(self): @@ -53,6 +51,4 @@ class LocationSecurityProxyTests(unittest.TestCase): def test_suite(): - return unittest.TestSuite(( - unittest.makeSuite(LocationSecurityProxyTests), - )) + return unittest.defaultTestLoader.loadTestsFromName(__name__) |