From c4eea2e694d3aac499b9cddadd774fe0a8112ed6 Mon Sep 17 00:00:00 2001
From: John Chilton <jmchilton@gmail.com>
Date: Tue, 24 Sep 2013 15:57:42 -0500
Subject: [PATCH] Remove .travis.yml installation of condor - it doesn't work
 on Ubuntu LTS. Make condor and DRMAA based tests skipable if external
 environment not configured properly.

---
 .travis.yml              |  5 +----
 test/integration_test.py |  5 ++++-
 test/test_utils.py       | 39 +++++++++++++++++++++++++++++++++++----
 3 files changed, 40 insertions(+), 9 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 83d6b6da..3945a5c3 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,6 +1,3 @@
-## Add to .hg/hgrc to enable bitbucket pushes to push to github as well.
-# [hooks]  
-# outgoing = hg push git+ssh://git@github.com/jmchilton/lwr.git || true
 language: python
 python:
   - 2.6
@@ -22,7 +19,7 @@ install:
   - sudo python scripts/configure_test_slurm.py
   - echo "export DRMAA_LIBRARY_PATH=/usr/lib/libdrmaa.so" >> local_env.sh
   - pip install drmaa
-  - sudo apt-get install condor
+#  - sudo apt-get install condor
 script: . local_env.sh; nosetests
 matrix:
   include:
diff --git a/test/integration_test.py b/test/integration_test.py
index 6e90b877..b2f26187 100644
--- a/test/integration_test.py
+++ b/test/integration_test.py
@@ -1,5 +1,5 @@
 from os.path import join
-from .test_utils import TempDirectoryTestCase
+from .test_utils import TempDirectoryTestCase, skipUnlessExecutable, skipUnlessEnvironVariable
 
 from lwr.util import Bunch
 from .check import run
@@ -11,6 +11,7 @@ except ImportError:
 
 class IntegrationTest(TempDirectoryTestCase):
 
+    @skipUnlessEnvironVariable("DRMAA_LIBRARY_PATH")
     def test_integration_as_user(self):
         self.__run(job_conf_props={'type': 'queued_external_drmaa', "production": "false"}, private_token=None, default_file_action="copy", user='u1')
 
@@ -35,9 +36,11 @@ class IntegrationTest(TempDirectoryTestCase):
     def test_integration_errors(self):
         self.__run(app_conf={"private_key": "testtoken"}, private_token="testtoken", transport="curl", test_errors=True)
 
+    @skipUnlessEnvironVariable("DRMAA_LIBRARY_PATH")
     def test_integration_drmaa(self):
         self.__run(app_conf={}, job_conf_props={'type': 'queued_drmaa'}, private_token=None)
 
+    @skipUnlessExecutable("condor_submit")
     def test_integration_condor(self):
         self.__run(app_conf={}, job_conf_props={'type': 'queued_condor'}, private_token=None)
 
diff --git a/test/test_utils.py b/test/test_utils.py
index d7509da2..9130d6ba 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -1,15 +1,15 @@
 from contextlib import contextmanager
 from stat import S_IXOTH
-from os import pardir, stat, chmod
-from os.path import join, dirname
+from os import pardir, stat, chmod, access, X_OK, pathsep, environ
+from os.path import join, dirname, isfile, split
 from tempfile import mkdtemp
 from shutil import rmtree
 
 from sys import version_info
 if version_info < (2, 7):
-    from unittest2 import TestCase
+    from unittest2 import TestCase, skip
 else:
-    from unittest import TestCase
+    from unittest import TestCase, skip
 
 from webtest import TestApp
 from webtest.http import StopableWSGIServer
@@ -131,6 +131,37 @@ def test_app(global_conf={}, app_conf={}, test_conf={}):
                 pass
 
 
+def skipUnlessExecutable(executable):
+    if __which(executable):
+        return lambda func: func
+    return skip("PATH doesn't contain executable {!r}".format(executable))
+
+
+def skipUnlessEnvironVariable(variable):
+    if variable in environ:
+        return lambda func: func
+    return skip("Environment variable %s is not defined." % variable)
+
+
+def __which(program):
+
+    def is_exe(fpath):
+        return isfile(fpath) and access(fpath, X_OK)
+
+    fpath, fname = split(program)
+    if fpath:
+        if is_exe(program):
+            return program
+    else:
+        for path in environ["PATH"].split(pathsep):
+            path = path.strip('"')
+            exe_file = join(path, program)
+            if is_exe(exe_file):
+                return exe_file
+
+    return None
+
+
 class TestAuthorizer(object):
 
     def __init__(self):
-- 
GitLab