summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGui Chen <gui.chen@intel.com>2013-01-06 10:36:53 +0800
committerGui Chen <gui.chen@intel.com>2013-01-06 17:43:58 +0800
commit6aed506e6975e1e038a8fc804fdc01d5d16f8a20 (patch)
treec9967d5730e5bbd78e91a6e0e676ae4d0be21e59 /tests
parent946725e1d0666fe7f4d4eee9253e092f82a3f175 (diff)
downloadmic-6aed506e6975e1e038a8fc804fdc01d5d16f8a20.tar.gz
mic-6aed506e6975e1e038a8fc804fdc01d5d16f8a20.tar.bz2
mic-6aed506e6975e1e038a8fc804fdc01d5d16f8a20.zip
update dist files and tests to enable unittest
Signed-off-by: Gui Chen <gui.chen@intel.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/test_baseimager.py15
-rw-r--r--tests/test_chroot.py4
-rw-r--r--tests/test_configmgr.py13
-rw-r--r--tests/test_pluginmgr.py18
4 files changed, 24 insertions, 26 deletions
diff --git a/tests/test_baseimager.py b/tests/test_baseimager.py
index 6b91b0d..0348b36 100644
--- a/tests/test_baseimager.py
+++ b/tests/test_baseimager.py
@@ -13,11 +13,12 @@ from mic import conf as configmgr
from mic import msger
from mic.imager import fs
-TEST_BASEIMGR_LOC = os.path.join(os.getcwd(), 'baseimgr_fixtures')
-KSCONF = os.path.join(os.getcwd(), 'baseimgr_fixtures', 'test.ks')
-KSBAK = os.path.join(os.getcwd(), 'baseimgr_fixtures', 'test.ks.bak')
-REPOURI = os.path.join(os.getcwd(), 'baseimgr_fixtures')
-CACHEDIR = os.path.join(os.getcwd(), 'baseimgr_fixtures', 'cache')
+CWD = os.path.dirname(__file__) or '.'
+TEST_BASEIMGR_LOC = os.path.join(CWD, 'baseimgr_fixtures')
+KSCONF = os.path.join(CWD, 'baseimgr_fixtures', 'test.ks')
+KSBAK = os.path.join(CWD, 'baseimgr_fixtures', 'test.ks.bak')
+REPOURI = os.path.join(CWD, 'baseimgr_fixtures')
+CACHEDIR = os.path.join(CWD, 'baseimgr_fixtures', 'cache')
RPMLOCK_PATH = None
def suite():
@@ -56,7 +57,7 @@ class BaseImgrTest(unittest.TestCase):
for entry in p.communicate()[0].split('\n'):
if entry.find(pattern) > 0:
- real_mount_list.append(entry.split(' ')[0])
+ real_mount_list.append(entry.split(' ')[2])
real_mount_list.sort()
os.close(dev_null)
return real_mount_list
@@ -102,6 +103,7 @@ class BaseImgrTest(unittest.TestCase):
RPMLOCK_PATH = "%s/var/lib/rpm" % creator._instroot
exp_mount_list = ['/sys', '/proc', '/proc/sys/fs/binfmt_misc', '/dev/pts']
exp_mount_list.sort()
+ exp_mount_list = [os.path.join(creator._instroot, pth.lstrip('/')) for pth in exp_mount_list]
real_mount_list = self.getMountList(creator._instroot)
self.assertEqual(real_mount_list, exp_mount_list)
@@ -128,6 +130,7 @@ class BaseImgrTest(unittest.TestCase):
real_pkglist = f.read()
self.assertEqual(real_pkglist, '\n'.join(pkglist))
+if os.getuid == 0:
def testBaseImagerZypp(self):
self.BaseImager('zypp')
diff --git a/tests/test_chroot.py b/tests/test_chroot.py
index 546e3ae..3563f14 100644
--- a/tests/test_chroot.py
+++ b/tests/test_chroot.py
@@ -8,7 +8,8 @@ import StringIO
import unittest
from mic import chroot
-TEST_CHROOT_LOC = os.path.join(os.getcwd(), 'chroot_fixtures')
+CWD = os.path.dirname(__file__) or '.'
+TEST_CHROOT_LOC = os.path.join(CWD, 'chroot_fixtures')
TEST_CHROOT_TAR = os.path.join(TEST_CHROOT_LOC, 'minchroot.tar.gz')
TEST_CHROOT_DIR = os.path.join(TEST_CHROOT_LOC, 'minchroot')
@@ -31,6 +32,7 @@ class ChrootTest(unittest.TestCase):
sys.stderr = self.stderr
shutil.rmtree(TEST_CHROOT_DIR, ignore_errors=True)
+if os.getuid() == 0:
def testChroot(self):
try:
chroot.chroot(TEST_CHROOT_DIR, None, 'exit')
diff --git a/tests/test_configmgr.py b/tests/test_configmgr.py
index fcebc9f..c357426 100644
--- a/tests/test_configmgr.py
+++ b/tests/test_configmgr.py
@@ -4,16 +4,17 @@ import os
import sys
import shutil
import StringIO
+import unittest
from mic import conf, msger
from pykickstart.parser import KickstartParser
-import unittest2 as unittest
-SITECONF = os.path.join(os.getcwd(), 'configmgr_fixtures', 'mic.conf')
-KSCONF = os.path.join(os.getcwd(), 'configmgr_fixtures', 'test.ks')
-KSBAK = os.path.join(os.getcwd(), 'configmgr_fixtures', 'test.ks.bak')
-REPOURI = os.path.join(os.getcwd(), 'configmgr_fixtures', 'packages')
-CACHEDIR = os.path.join(os.getcwd(), 'configmgr_fixtures', 'cache')
+CWD = os.path.dirname(__file__) or '.'
+SITECONF = os.path.join(CWD, 'configmgr_fixtures', 'mic.conf')
+KSCONF = os.path.join(CWD, 'configmgr_fixtures', 'test.ks')
+KSBAK = os.path.join(CWD, 'configmgr_fixtures', 'test.ks.bak')
+REPOURI = os.path.join(CWD, 'configmgr_fixtures', 'packages')
+CACHEDIR = os.path.join(CWD, 'configmgr_fixtures', 'cache')
def suite():
return unittest.makeSuite(ConfigMgrTest)
diff --git a/tests/test_pluginmgr.py b/tests/test_pluginmgr.py
index 5c207b6..6263ee9 100644
--- a/tests/test_pluginmgr.py
+++ b/tests/test_pluginmgr.py
@@ -9,7 +9,8 @@ from mic import pluginbase
from mic import msger
import unittest
-TEST_PLUGINS_LOC = os.path.join(os.getcwd(), 'pluginmgr_fixtures')
+CWD = os.path.dirname(__file__) or '.'
+TEST_PLUGINS_LOC = os.path.join(CWD, 'pluginmgr_fixtures')
def suite():
return unittest.makeSuite(PluginMgrTest)
@@ -17,9 +18,9 @@ def suite():
class PluginMgrTest(unittest.TestCase):
def setUp(self):
- self.defploc = plugin.DEFAULT_PLUGIN_LOCATION
- plugin.DEFAULT_PLUGIN_LOCATION = TEST_PLUGINS_LOC
self.plugin = plugin.PluginMgr()
+ self.defploc = self.plugin.plugin_dir
+ self.plugin.plugin_dir = TEST_PLUGINS_LOC
self.stdout = sys.stdout
self.stderr = sys.stderr
sys.stdout = StringIO.StringIO()
@@ -28,16 +29,7 @@ class PluginMgrTest(unittest.TestCase):
def tearDown(self):
sys.stdout = self.stdout
sys.stderr = self.stderr
- #dirs = map(lambda pt: os.path.join(TEST_PLUGINS_LOC, pt), \
- # plugin.PLUGIN_TYPES)
- #pys = reduce(lambda p, q: p+q, map(lambda d: filter(
- # lambda x: x.endswith(".py"), os.listdir(d)), dirs))
- #for mod in pys:
- # if mod.strip('.py') in sys.modules:
- # del sys.modules[mod.strip('.py')]
- #self.plugin._intance = None
- #self.plugin.plugin_dirs = {}
- plugin.DEFAULT_PLUGIN_LOCATION = self.defploc
+ self.plugin.plugin_dir = self.defploc
def testPluginDir(self):
plugindir = {}