From 12bbe05af64daa398f113989f000dcb066b6b1e1 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone <exarkun@twistedmatrix.com> Date: Tue, 10 Mar 2020 08:53:50 -0400 Subject: [PATCH] Fix skipping to be testtools compatible --- src/_zkapauthorizer/tests/common.py | 41 +++++++++++++++++++ .../tests/test_storage_protocol.py | 7 ++-- 2 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 src/_zkapauthorizer/tests/common.py diff --git a/src/_zkapauthorizer/tests/common.py b/src/_zkapauthorizer/tests/common.py new file mode 100644 index 0000000..39aa911 --- /dev/null +++ b/src/_zkapauthorizer/tests/common.py @@ -0,0 +1,41 @@ +# Copyright 2019 PrivateStorage.io, LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Testing functionality that is specifically related to the test harness +itself. +""" + + +def skipIf(condition, reason): + """ + Create a decorate a function to be skipped if the given condition is true. + + :param bool condition: The condition under which to skip. + :param unicode reason: A reason for the skip. + + :return: A function decorator which will skip the test if the given + condition is true. + """ + if condition: + return _skipper(reason) + return lambda x: x + + +def _skipper(reason): + def wrapper(f): + def skipIt(self, *a, **kw): + self.skipTest(reason) + return skipIt + return wrapper diff --git a/src/_zkapauthorizer/tests/test_storage_protocol.py b/src/_zkapauthorizer/tests/test_storage_protocol.py index ee0dc5b..80c34b5 100644 --- a/src/_zkapauthorizer/tests/test_storage_protocol.py +++ b/src/_zkapauthorizer/tests/test_storage_protocol.py @@ -23,9 +23,6 @@ from __future__ import ( from fixtures import ( MonkeyPatch, ) -from unittest import ( - skipIf, -) from testtools import ( TestCase, ) @@ -73,6 +70,10 @@ from privacypass import ( random_signing_key, ) +from .common import ( + skipIf, +) + from .privacypass import ( make_passes, ) -- GitLab