From 7c12027311c4483de05bc0c583890382f7517536 Mon Sep 17 00:00:00 2001 From: Steven Armstrong Date: Mon, 10 Oct 2011 09:30:28 +0200 Subject: [PATCH] test and fixtures for Object class/static methods Signed-off-by: Steven Armstrong --- lib/cdist/test/object/__init__.py | 61 +++++++++++++++++++ .../test/object/fixtures/object/__first/.keep | 0 .../fixtures/object/__first/man/.cdist/.keep | 0 .../object/fixtures/object/__second/.keep | 0 .../object/__second/on-the/.cdist/.keep | 0 .../test/object/fixtures/object/__third/.keep | 0 .../fixtures/object/__third/moon/.cdist/.keep | 0 .../test/object/fixtures/type/__first/.keep | 0 .../test/object/fixtures/type/__second/.keep | 0 .../test/object/fixtures/type/__third/.keep | 0 lib/cdist/test/test_object.py | 46 -------------- 11 files changed, 61 insertions(+), 46 deletions(-) create mode 100644 lib/cdist/test/object/__init__.py create mode 100644 lib/cdist/test/object/fixtures/object/__first/.keep create mode 100644 lib/cdist/test/object/fixtures/object/__first/man/.cdist/.keep create mode 100644 lib/cdist/test/object/fixtures/object/__second/.keep create mode 100644 lib/cdist/test/object/fixtures/object/__second/on-the/.cdist/.keep create mode 100644 lib/cdist/test/object/fixtures/object/__third/.keep create mode 100644 lib/cdist/test/object/fixtures/object/__third/moon/.cdist/.keep create mode 100644 lib/cdist/test/object/fixtures/type/__first/.keep create mode 100644 lib/cdist/test/object/fixtures/type/__second/.keep create mode 100644 lib/cdist/test/object/fixtures/type/__third/.keep delete mode 100644 lib/cdist/test/test_object.py diff --git a/lib/cdist/test/object/__init__.py b/lib/cdist/test/object/__init__.py new file mode 100644 index 00000000..3d04a7a3 --- /dev/null +++ b/lib/cdist/test/object/__init__.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +# +# 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# + +import os +import tempfile +import unittest +import shutil + +import cdist.core + +import os.path as op +my_dir = op.abspath(op.dirname(__file__)) +fixtures = op.join(my_dir, 'fixtures') +object_base_path = op.join(fixtures, 'object') +type_base_path = op.join(fixtures, 'type') + +class ObjectClassTestCase(unittest.TestCase): + + def test_list_object_names(self): + object_names = list(cdist.core.Object.list_object_names(object_base_path)) + self.assertEqual(object_names, ['__first/man', '__second/on-the', '__third/moon']) + + def test_list_type_names(self): + type_names = list(cdist.core.Object.list_type_names(object_base_path)) + self.assertEqual(type_names, ['__first', '__second', '__third']) + + def test_list_objects(self): + objects = list(cdist.core.Object.list_objects(object_base_path, type_base_path)) + objects_expected = [ + cdist.core.Object(cdist.core.Type(type_base_path, '__first'), object_base_path, 'man'), + cdist.core.Object(cdist.core.Type(type_base_path, '__second'), object_base_path, 'on-the'), + cdist.core.Object(cdist.core.Type(type_base_path, '__third'), object_base_path, 'moon'), + ] + self.assertEqual(objects, objects_expected) + + +''' +suite = unittest.TestLoader().loadTestsFromTestCase(ObjectTestCase) + +def suite(): + tests = [] + return unittest.TestSuite(map(ObjectTestCase, tests)) +''' diff --git a/lib/cdist/test/object/fixtures/object/__first/.keep b/lib/cdist/test/object/fixtures/object/__first/.keep new file mode 100644 index 00000000..e69de29b diff --git a/lib/cdist/test/object/fixtures/object/__first/man/.cdist/.keep b/lib/cdist/test/object/fixtures/object/__first/man/.cdist/.keep new file mode 100644 index 00000000..e69de29b diff --git a/lib/cdist/test/object/fixtures/object/__second/.keep b/lib/cdist/test/object/fixtures/object/__second/.keep new file mode 100644 index 00000000..e69de29b diff --git a/lib/cdist/test/object/fixtures/object/__second/on-the/.cdist/.keep b/lib/cdist/test/object/fixtures/object/__second/on-the/.cdist/.keep new file mode 100644 index 00000000..e69de29b diff --git a/lib/cdist/test/object/fixtures/object/__third/.keep b/lib/cdist/test/object/fixtures/object/__third/.keep new file mode 100644 index 00000000..e69de29b diff --git a/lib/cdist/test/object/fixtures/object/__third/moon/.cdist/.keep b/lib/cdist/test/object/fixtures/object/__third/moon/.cdist/.keep new file mode 100644 index 00000000..e69de29b diff --git a/lib/cdist/test/object/fixtures/type/__first/.keep b/lib/cdist/test/object/fixtures/type/__first/.keep new file mode 100644 index 00000000..e69de29b diff --git a/lib/cdist/test/object/fixtures/type/__second/.keep b/lib/cdist/test/object/fixtures/type/__second/.keep new file mode 100644 index 00000000..e69de29b diff --git a/lib/cdist/test/object/fixtures/type/__third/.keep b/lib/cdist/test/object/fixtures/type/__third/.keep new file mode 100644 index 00000000..e69de29b diff --git a/lib/cdist/test/test_object.py b/lib/cdist/test/test_object.py deleted file mode 100644 index ae584840..00000000 --- a/lib/cdist/test/test_object.py +++ /dev/null @@ -1,46 +0,0 @@ -# -*- coding: utf-8 -*- -# -# 2010-2011 Steven Armstrong (steven-cdist at armstrong.cc) -# -# This file is part of cdist. -# -# cdist is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# cdist 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 General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with cdist. If not, see . -# -# - -import os -import tempfile -import unittest -import shutil - -import os.path as op -my_dir = op.abspath(op.dirname(__file__)) -base_path = op.join(my_dir, 'fixtures') - -class ObjectTestCase(unittest.TestCase): - def setUp(self): - # FIXME: use defined set of types for testing? - # FIXME: generate object tree or use predefined? - self.object_base_dir = tempfile.mkdtemp() - - def tearDown(self): - shutil.rmtree(self.temp_dir) - -''' -suite = unittest.TestLoader().loadTestsFromTestCase(ObjectTestCase) - -def suite(): - tests = [] - return unittest.TestSuite(map(ObjectTestCase, tests)) -'''