This patch adds test cases for paths generation code.
Signed-off-by: Mark Wu <wudxw(a)linux.vnet.ibm.com>
---
.gitignore | 1 +
Makefile.am | 1 +
tests/Makefile.am | 10 +++++--
tests/test_config.py.in | 79 +++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 89 insertions(+), 2 deletions(-)
create mode 100644 tests/test_config.py.in
diff --git a/.gitignore b/.gitignore
index 6dfa874..a3b7f6f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -29,6 +29,7 @@ src/kimchid
src/kimchi.conf
src/kimchi/config.py
tests/run_tests.sh
+tests/test_config.py
po/POTFILES
po/gen-pot
*.orig
diff --git a/Makefile.am b/Makefile.am
index fa7b6b6..278e7be 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -58,6 +58,7 @@ PEP8_WHITELIST = \
src/kimchi/root.py \
src/kimchi/server.py \
src/kimchi/utils.py \
+ tests/test_config.py.in \
tests/test_mockmodel.py \
tests/test_model.py \
tests/test_plugin.py \
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 59e344d..0487ffc 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -24,6 +24,7 @@ EXTRA_DIST = \
Makefile.am \
run_tests.sh.in \
iso_gen.py \
+ test_config.py.in \
test_exception.py \
test_mockmodel.py \
test_model.py \
@@ -42,16 +43,21 @@ noinst_SCRIPTS = run_tests.sh
do_substitution = \
sed -e 's,[@]HAVE_PYMOD_UNITTEST[@],$(HAVE_PYMOD_UNITTEST),g' \
- -e 's,[@]PYTHON_VERSION[@],$(PYTHON_VERSION),g'
+ -e 's,[@]PYTHON_VERSION[@],$(PYTHON_VERSION),g' \
+ -e 's,[@]kimchidir[@],$(pythondir)/kimchi,g' \
+ -e 's,[@]pkgdatadir[@],$(pkgdatadir),g'
run_tests.sh: run_tests.sh.in Makefile
$(do_substitution) < $(srcdir)/run_tests.sh.in > run_tests.sh
chmod +x run_tests.sh
+test_config.py: test_config.py.in Makefile
+ $(do_substitution) < $(srcdir)/test_config.py.in > test_config.py
check-local:
$(MKDIR_P) $(top_srcdir)/data/screenshots
./run_tests.sh
-CLEANFILES = run_tests.sh
+BUILT_SOURCES = test_config.py
+CLEANFILES = run_tests.sh test_config.py
diff --git a/tests/test_config.py.in b/tests/test_config.py.in
new file mode 100644
index 0000000..19a6cfe
--- /dev/null
+++ b/tests/test_config.py.in
@@ -0,0 +1,79 @@
+#
+# Project Kimchi
+#
+# Copyright IBM, Corp. 2013
+#
+# Authors:
+# Mark Wu <wudxw(a)linux.vnet.ibm.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+import unittest
+
+
+from kimchi.config import Paths, PluginPaths
+
+
+class ConfigTests(unittest.TestCase):
+ def assertInstalledPath(self, actual, expected):
+ if '@pkgdatadir@' != '/usr/share/kimchi':
+ usr_local = '/usr/local'
+ if not expected.startswith('/usr'):
+ expected = usr_local + expected
+ self.assertEquals(actual, expected)
+
+ def test_installed_paths(self):
+ Paths.get_prefix = lambda self: '@pkgdatadir@'
+ paths = Paths()
+ self.assertInstalledPath(paths.state_dir, '/var/lib/kimchi')
+ self.assertInstalledPath(paths.log_dir, '/var/log/kimchi')
+ self.assertInstalledPath(paths.conf_dir, '/etc/kimchi')
+ self.assertInstalledPath(paths.src_dir, '@kimchidir@')
+ self.assertInstalledPath(paths.plugins_dir, '@kimchidir@')
+ self.assertInstalledPath(paths.ui_dir, '@pkgdatadir@/ui')
+ self.assertInstalledPath(paths.mo_dir, '@pkgdatadir@/mo')
+
+ def test_uninstalled_paths(self):
+ Paths.get_prefix = lambda self: '/home/user/kimchi'
+ paths = Paths()
+ self.assertEquals(paths.state_dir, '/home/user/kimchi/data')
+ self.assertEquals(paths.log_dir, '/home/user/kimchi/log')
+ self.assertEquals(paths.conf_dir, '/home/user/kimchi/src')
+ self.assertEquals(paths.src_dir, '/home/user/kimchi/src/kimchi')
+ self.assertEquals(paths.plugins_dir, '/home/user/kimchi/plugins')
+ self.assertEquals(paths.ui_dir, '/home/user/kimchi/ui')
+ self.assertEquals(paths.mo_dir, '/home/user/kimchi/mo')
+
+ def test_installed_plugin_paths(self):
+ PluginPaths.get_prefix = lambda self: '@pkgdatadir@'
+ paths = PluginPaths('sample')
+ self.assertInstalledPath(paths.conf_dir, '/etc/kimchi/plugins.d')
+ self.assertInstalledPath(paths.conf_file,
+ '/etc/kimchi/plugins.d/sample.conf')
+ self.assertInstalledPath(paths.src_dir, '@kimchidir@/plugins/sample')
+ self.assertInstalledPath(paths.ui_dir,
+ '@pkgdatadir@/plugins/sample/ui')
+ self.assertInstalledPath(paths.mo_dir,
+ '@pkgdatadir@/plugins/sample/mo')
+
+ def test_uninstalled_plugin_paths(self):
+ PluginPaths.get_prefix = lambda self: '/home/user/kimchi'
+ paths = PluginPaths('sample')
+ self.assertEquals(paths.conf_dir, '/home/user/kimchi/plugins/sample')
+ self.assertEquals(
+ paths.conf_file, '/home/user/kimchi/plugins/sample/sample.conf')
+ self.assertEquals(paths.src_dir, '/home/user/kimchi/plugins/sample')
+ self.assertEquals(paths.ui_dir, '/home/user/kimchi/plugins/sample/ui')
+ self.assertEquals(paths.mo_dir, '/home/user/kimchi/plugins/sample/mo')
--
1.8.4.2