commit 792557ccdb475cdd95be09b71a69d38f7770b3c7 Author: Damian Johnson atagar@torproject.org Date: Sat Jun 15 15:45:02 2013 -0700
Requiring mock version 0.7.0 or later
Our jenkins tests presently have mock version 0.6.0, but we're using mock's patch.dict which was introduced in 0.7.0. This causes the tests to fail with...
Traceback (most recent call last): File "./run_tests.py", line 394, in <module> main() File "./run_tests.py", line 173, in main for test_class in test.util.get_unit_tests(args.test_prefix): File "/srv/jenkins-workspace/workspace/stem-tor-ci/test/util.py", line 130, in _get_tests module = __import__(module_name) File "/srv/jenkins-workspace/workspace/stem-tor-ci/test/unit/version.py", line 20, in <module> class TestVersion(unittest.TestCase): File "/srv/jenkins-workspace/workspace/stem-tor-ci/test/unit/version.py", line 22, in TestVersion @patch.dict(stem.version.VERSION_CACHE)
Making run_tests.py balk if we're using a version of mock prior to 0.7.0. --- run_tests.py | 13 ++++++++++++- stem/prereq.py | 6 ++++++ 2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/run_tests.py b/run_tests.py index 7bcbe5e..207b0fe 100755 --- a/run_tests.py +++ b/run_tests.py @@ -81,6 +81,13 @@ To run stem's tests you'll need mock... https://pypi.python.org/pypi/mock/ """
+MOCK_OUT_OF_DATE_MSG = """\ +To run stem's tests you'll need mock. You have version %s, but you need +version 0.7.0 or later... + +https://pypi.python.org/pypi/mock/ +""" +
def main(): start_time = time.time() @@ -111,7 +118,11 @@ def main(): sys.exit()
if not stem.prereq.is_mock_available(): - println(MOCK_UNAVAILABLE_MSG) + try: + import mock + println(MOCK_OUT_OF_DATE_MSG % mock.__version__) + except ImportError: + println(MOCK_UNAVAILABLE_MSG)
if stem.util.system.is_available('pip'): println("You can get it by running 'sudo pip install mock'.") diff --git a/stem/prereq.py b/stem/prereq.py index 148b6f8..25573ab 100644 --- a/stem/prereq.py +++ b/stem/prereq.py @@ -100,6 +100,12 @@ def is_mock_available(): if IS_MOCK_AVAILABLE is None: try: import mock + + # we use mock's patch.dict() which was introduced in version 0.7.0 + + if not hasattr(mock.patch, 'dict'): + raise ImportError() + IS_MOCK_AVAILABLE = True except ImportError: IS_MOCK_AVAILABLE = False