Change the way to import common autotest libs to follow
the rest of autotest convention, regain the ability of
running the test programs:

 * server/self-test/autotest_test.py
 * server/self-test/common.py
 * server/self-test/utils_test.py

Signed-off-by: Lucas Meneghel Rodrigues <[email protected]>
---
 server/self-test/autotest_test.py |   11 ++++-------
 server/self-test/common.py        |    8 ++++++++
 server/self-test/utils_test.py    |    8 ++------
 3 files changed, 14 insertions(+), 13 deletions(-)
 create mode 100644 server/self-test/common.py

diff --git a/server/self-test/autotest_test.py 
b/server/self-test/autotest_test.py
index cf4e9a9..6e9df7b 100755
--- a/server/self-test/autotest_test.py
+++ b/server/self-test/autotest_test.py
@@ -11,14 +11,11 @@ import os
 import sys
 import unittest
 
-# Adjust the path so Python can find the autoserv modules
-src = os.path.abspath("%s/.." % (os.path.dirname(sys.argv[0]),))
-if src not in sys.path:
-    sys.path.insert(1, src)
-
-import utils
-import autotest
-import hosts
+import common
+
+from autotest_lib.server import utils
+from autotest_lib.server import autotest
+from autotest_lib.server import hosts
 
 
 class AutotestTestCase(unittest.TestCase):
diff --git a/server/self-test/common.py b/server/self-test/common.py
new file mode 100644
index 0000000..41607e1
--- /dev/null
+++ b/server/self-test/common.py
@@ -0,0 +1,8 @@
+import os, sys
+dirname = os.path.dirname(sys.modules[__name__].__file__)
+autotest_dir = os.path.abspath(os.path.join(dirname, "..", ".."))
+client_dir = os.path.join(autotest_dir, "client")
+sys.path.insert(0, client_dir)
+import setup_modules
+sys.path.pop(0)
+setup_modules.setup(base_path=autotest_dir, root_module_name="autotest_lib")
diff --git a/server/self-test/utils_test.py b/server/self-test/utils_test.py
index fffbf9a..e1b2de3 100755
--- a/server/self-test/utils_test.py
+++ b/server/self-test/utils_test.py
@@ -12,13 +12,9 @@ import sys
 import os.path
 import unittest
 
-# Adjust the path so Python can find the autoserv modules
-src = os.path.abspath("%s/.." % (os.path.dirname(sys.argv[0]),))
-if src not in sys.path:
-    sys.path.insert(1, src)
-
-import utils
+import common
 
+from autotest_lib.server import utils
 
 
 class UtilsTestCase(unittest.TestCase):
-- 
1.7.6

_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to