[Kimchi-devel] [PATCH v4 2/3] Add test cases for paths generation code

Sheldon shaohef at linux.vnet.ibm.com
Tue Jan 28 14:48:59 UTC 2014


Reviewed-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>

seems test_config comply with pep8, need add to check-list?


On 01/28/2014 02:21 PM, Mark Wu wrote:
> This patch adds test cases for paths generation code.
>
> Signed-off-by: Mark Wu <wudxw at linux.vnet.ibm.com>
> ---
>   .gitignore              |  1 +
>   tests/Makefile.am       |  9 ++++--
>   tests/test_config.py.in | 85 +++++++++++++++++++++++++++++++++++++++++++++++++
>   3 files changed, 93 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/tests/Makefile.am b/tests/Makefile.am
> index 59e344d..61022f8 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,20 @@ 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,[@]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..a87ede5
> --- /dev/null
> +++ b/tests/test_config.py.in
> @@ -0,0 +1,85 @@
> +#
> +# Project Kimchi
> +#
> +# Copyright IBM, Corp. 2013
> +#
> +# Authors:
> +#  Mark Wu <wudxw at 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 expected.startswith('/usr'):
> +                expected = usr_local + expected[len('/usr'):]
> +            else:
> +                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,
> +                                 '/usr/lib/python2.7/site-packages/kimchi')
> +        self.assertInstalledPath(paths.plugins_dir,
> +                                 '/usr/lib/python2.7/site-packages/kimchi')
> +        self.assertInstalledPath(paths.ui_dir, '/usr/share/kimchi/ui')
> +        self.assertInstalledPath(paths.mo_dir, '/usr/share/kimchi/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,
> +            '/usr/lib/python2.7/site-packages/kimchi/plugins/sample')
> +        self.assertInstalledPath(paths.ui_dir,
> +                                 '/usr/share/kimchi/plugins/sample/ui')
> +        self.assertInstalledPath(paths.mo_dir,
> +                                 '/usr/share/kimchi/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')


-- 
Thanks and best regards!

Sheldon Feng(冯少合)<shaohef at linux.vnet.ibm.com>
IBM Linux Technology Center




More information about the Kimchi-devel mailing list