mock cross_connect test added to test/core/integration.py
[nepi.git] / test / lib / test_util.py
index bdedb9b..87e22c3 100644 (file)
@@ -1,8 +1,9 @@
 #!/usr/bin/env python
-# vim:ts=4:sw=4:et:ai:sts=4
 
-import sys
 import nepi.util.environ
+import ctypes
+import imp
+import sys
 
 # Unittest from Python 2.6 doesn't have these decorators
 def _bannerwrap(f, text):
@@ -19,6 +20,46 @@ def skipUnless(cond, text):
 def skipIf(cond, text):
     return (lambda f: _bannerwrap(f, text)) if cond else lambda f: f
 
+def ns3_bindings_path():
+    if "NEPI_NS3BINDINGS" in os.environ:
+        return os.environ["NEPI_NS3BINDINGS"]
+    return None
+
+def ns3_library_path():
+    if "NEPI_NS3LIBRARY" in os.environ:
+        return os.environ["NEPI_NS3LIBRARY"]
+    return None
+
+def ns3_usable():
+    if ns3_library_path():
+        try:
+            ctypes.CDLL(ns3_library_path(), ctypes.RTLD_GLOBAL)
+        except:
+            return False
+
+    if ns3_bindings_path():
+        sys.path.insert(0, ns3_bindings_path())
+
+    try:
+        found = imp.find_module('ns3')
+        module = imp.load_module('ns3', *found)
+    except ImportError:
+        return False
+    finally:
+        if ns3_bindings_path():
+            del sys.path[0]
+
+    return True
+
+def pl_auth():
+    user = os.environ.get('PL_USER')
+    pwd = os.environ.get('PL_PASS')
+     
+    if user and pwd:
+        return (user,pwd)
+    else:
+        return None
+
 def find_bin(name, extra_path = None):
     search = []
     if "PATH" in os.environ:
@@ -134,6 +175,12 @@ class test_environment(object):
         if 'PYTHONPATH' in os.environ:
             environ['PYTHONPATH'] = ":".join(map(os.path.realpath, 
                 os.environ['PYTHONPATH'].split(":")))
+        if 'NEPI_NS3BINDINGS' in os.environ:
+            environ['NEPI_NS3BINDINGS'] = \
+                    os.path.realpath(os.environ['NEPI_NS3BINDINGS'])
+        if 'NEPI_NS3LIBRARY' in os.environ:
+            environ['NEPI_NS3LIBRARY'] = \
+                    os.path.realpath(os.environ['NEPI_NS3LIBRARY'])
 
         self.dir = tempfile.mkdtemp()
         self.server_keypair = gen_ssh_keypair(