From 6aed506e6975e1e038a8fc804fdc01d5d16f8a20 Mon Sep 17 00:00:00 2001 From: Gui Chen Date: Sun, 6 Jan 2013 10:36:53 +0800 Subject: [PATCH] update dist files and tests to enable unittest Signed-off-by: Gui Chen --- Makefile | 7 +++---- debian/rules | 5 +---- packaging/mic.spec | 30 ++++-------------------------- tests/test_baseimager.py | 15 +++++++++------ tests/test_chroot.py | 4 +++- tests/test_configmgr.py | 13 +++++++------ tests/test_pluginmgr.py | 18 +++++------------- 7 files changed, 32 insertions(+), 60 deletions(-) diff --git a/Makefile b/Makefile index 5165fd2..5bbf2f6 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,6 @@ build: dist-common: man git archive --format=tar --prefix=$(PKGNAME)-$(TAGVER)/ $(TAG) | tar xpf - git show $(TAG) --oneline | head -1 > $(PKGNAME)-$(TAGVER)/commit-id - mkdir $(PKGNAME)-$(TAGVER)/doc; mv mic.1 $(PKGNAME)-$(TAGVER)/doc rm -rf $(PKGNAME)-$(TAGVER)/tests dist-bz2: dist-common @@ -30,8 +29,8 @@ dist-gz: dist-common tar zcpf $(PKGNAME)-$(TAGVER).tar.gz $(PKGNAME)-$(TAGVER) rm -rf $(PKGNAME)-$(TAGVER) -man: USAGE.rst - rst2man $< >mic.1 +man: + rst2man doc/man.rst > doc/mic.1 install: build $(PYTHON) setup.py install @@ -40,7 +39,7 @@ develop: build $(PYTHON) setup.py develop test: - cd tests/unittest/ && $(PYTHON) suite.py + cd tests/ && $(PYTHON) suite.py clean: rm -f *.tar.gz diff --git a/debian/rules b/debian/rules index 5346591..fc55966 100755 --- a/debian/rules +++ b/debian/rules @@ -25,10 +25,7 @@ install: build # Installing package mkdir -p $(CURDIR)/debian/mic $(CURDIR)/debian/mic/usr/bin $(CURDIR)/debian/mic/usr/share/man/man1 - install -m644 mic.1 $(CURDIR)/debian/mic/usr/share/man/man1 - #make DESTDIR=$(CURDIR)/debian/mic installman - #make DESTDIR=$(CURDIR)/debian/micng installconf - #make DESTDIR=$(CURDIR)/debian/micng installsymlinks + install -m644 doc/mic.1 $(CURDIR)/debian/mic/usr/share/man/man1 python setup.py install --root=$(CURDIR)/debian/mic binary-indep: build install diff --git a/packaging/mic.spec b/packaging/mic.spec index b3a299e..53dc83c 100644 --- a/packaging/mic.spec +++ b/packaging/mic.spec @@ -1,5 +1,5 @@ -%define is_tizen %(test -e /etc/tizen-release -o -e /etc/meego-release && echo 1 || echo 0) %{!?python_sitelib: %define python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")} + Name: mic Summary: Image Creator for Linux Distributions Version: 0.15 @@ -27,26 +27,14 @@ Requires: bzip2 Requires: squashfs-tools >= 4.0 Requires: qemu-arm-static Requires: python-urlgrabber -%if 0%{is_tizen} == 0 Requires: yum >= 3.2.24 -%endif %if 0%{?suse_version} Requires: btrfsprogs %else Requires: btrfs-progs %endif -%if 0%{?fedora_version} || 0%{is_tizen} == 1 -Requires: m2crypto -%else -%if 0%{?suse_version} == 1210 -Requires: python-M2Crypto -%else -Requires: python-m2crypto -%endif -%endif - -%if 0%{?fedora_version} > 13 || 0%{is_tizen} == 1 +%if 0%{?fedora_version} > 13 Requires: syslinux-extlinux %endif @@ -83,26 +71,16 @@ rm -rf $RPM_BUILD_ROOT %{__python} setup.py install --root=$RPM_BUILD_ROOT -O1 %endif -# remove yum backend for tizen -%if 0%{is_tizen} == 1 -rm -rf %{buildroot}/%{_prefix}/lib/%{name}/plugins/backend/yumpkgmgr.py -rm -rf %{buildroot}/%{_sysconfdir}/%{name}/bootstrap.conf -%endif - # install man page mkdir -p %{buildroot}/%{_prefix}/share/man/man1 -install -m644 mic.1 %{buildroot}/%{_prefix}/share/man/man1 +install -m644 doc/mic.1 %{buildroot}/%{_prefix}/share/man/man1 %files %defattr(-,root,root,-) -%doc README.rst -%doc doc/RELEASE_NOTES +%doc doc/* %{_mandir}/man1/* %dir %{_sysconfdir}/%{name} %config(noreplace) %{_sysconfdir}/%{name}/%{name}.conf -%if 0%{is_tizen} == 0 -%config %{_sysconfdir}/%{name}/bootstrap.conf -%endif %{python_sitelib}/* %dir %{_prefix}/lib/%{name} %{_prefix}/lib/%{name}/* 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 = {} -- 2.7.4