diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-08-22 08:22:46 -0400 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-08-22 08:31:06 -0400 |
commit | a69b11d94553bb0b6baf8e6b675d25fa40e0f001 (patch) | |
tree | 45dfadb4f70b1280da88cd06ba74785acc94e699 /testsuite/common.py | |
parent | ce9b7aedbe9cfe8de4e576dbe125c5a7161f5f5d (diff) | |
download | bcfg2-a69b11d94553bb0b6baf8e6b675d25fa40e0f001.tar.gz bcfg2-a69b11d94553bb0b6baf8e6b675d25fa40e0f001.tar.bz2 bcfg2-a69b11d94553bb0b6baf8e6b675d25fa40e0f001.zip |
fixed conditional patching of pylibacl/selinux methods for py2.6
Diffstat (limited to 'testsuite/common.py')
-rw-r--r-- | testsuite/common.py | 15 |
1 files changed, 15 insertions, 0 deletions
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 |