From a69b11d94553bb0b6baf8e6b675d25fa40e0f001 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Wed, 22 Aug 2012 08:22:46 -0400 Subject: fixed conditional patching of pylibacl/selinux methods for py2.6 --- testsuite/common.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'testsuite/common.py') diff --git a/testsuite/common.py b/testsuite/common.py index b49b75477..5788ad05d 100644 --- a/testsuite/common.py +++ b/testsuite/common.py @@ -1,6 +1,7 @@ import os import sys import unittest +from mock import patch from functools import wraps datastore = "/" @@ -253,3 +254,17 @@ def syncdb(modeltest): inst = modeltest(methodName='test_syncdb') inst.test_syncdb() inst.test_cleandb() + + +def patchIf(condition, entity, **kwargs): + """ perform conditional patching. this is necessary because some + libraries might not be installed (e.g., selinux, pylibacl), and + patching will barf on that. Other workarounds are not available + to us; e.g., context managers aren't in python 2.4, and using + inner functions doesn't work because python 2.6 applies all + decorators at compile-time, not at run-time, so decorating inner + functions does not prevent the decorators from being run. """ + if condition: + return patch(entity, **kwargs) + else: + return lambda f: f -- cgit v1.2.3-1-g7c22