From ed8bd56bc23923cdf6a8a32c3ea6a0d7646e85bd Mon Sep 17 00:00:00 2001 From: Joel Andres Granados Date: Mon, 2 Jun 2008 18:48:31 +0200 Subject: Add the testsuite controler (test) and some tests. --- test | 49 +++++++++++++ testsuite/__init__.py | 18 +++++ testsuite/initialization.py | 63 +++++++++++++++++ testsuite/initialization/directory/__init__.py | 3 + testsuite/initialization/directory/directory.py | 43 ++++++++++++ testsuite/initialization/initialization.conf | 91 +++++++++++++++++++++++++ testsuite/initialization/pluginInfo.py | 55 +++++++++++++++ testsuite/initialization/pyFile.py | 46 +++++++++++++ testsuite/initialization/pycFile | 46 +++++++++++++ 9 files changed, 414 insertions(+) create mode 100755 test create mode 100644 testsuite/__init__.py create mode 100644 testsuite/initialization.py create mode 100644 testsuite/initialization/directory/__init__.py create mode 100644 testsuite/initialization/directory/directory.py create mode 100644 testsuite/initialization/initialization.conf create mode 100644 testsuite/initialization/pluginInfo.py create mode 100644 testsuite/initialization/pyFile.py create mode 100644 testsuite/initialization/pycFile diff --git a/test b/test new file mode 100755 index 0000000..785e4c7 --- /dev/null +++ b/test @@ -0,0 +1,49 @@ +#!/usr/bin/python -tt +# First Aid Kit - diagnostic and repair tool for Linux +# Copyright (C) 2008 Joel Granados +# +# This program 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 2 of the License, or +# (at your option) any later version. +# +# This program 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 this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +import unittest, imp, sys +from testsuite import modnames +testloader = unittest.defaultTestLoader + +testsuitedir = "testsuite" +flawless = True + +for modname in modnames: + modinfo = imp.find_module(modname, [testsuitedir]) + modfile = open(modinfo[1], 'r') + modload = imp.load_module(modname, modfile, modinfo[1], modinfo[2]) + + result = unittest.TestResult() + suite = testloader.loadTestsFromModule(modload) + suite.run(result) + if len(result.failures) == 0 and len(result.errors) == 0: + # Nothing to worry about + continue + else: + flawless = False + if len(result.failures) > 0: + for failure in result.failures: + print failure + if len(result.errors) > 0: + for error in result.errors: + print error + +if flawless: + sys.exit(0) +else: + sys.exit(1) diff --git a/testsuite/__init__.py b/testsuite/__init__.py new file mode 100644 index 0000000..d302cc0 --- /dev/null +++ b/testsuite/__init__.py @@ -0,0 +1,18 @@ +# First Aid Kit - diagnostic and repair tool for Linux +# Copyright (C) 2008 Joel Granados +# +# This program 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 2 of the License, or +# (at your option) any later version. +# +# This program 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 this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +modnames = ['initialization'] diff --git a/testsuite/initialization.py b/testsuite/initialization.py new file mode 100644 index 0000000..4599c43 --- /dev/null +++ b/testsuite/initialization.py @@ -0,0 +1,63 @@ +# First Aid Kit - diagnostic and repair tool for Linux +# Copyright (C) 2008 Joel Granados +# +# This program 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 2 of the License, or +# (at your option) any later version. +# +# This program 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 this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +import unittest, imp +from pyfirstaidkit import Config +from pyfirstaidkit import initLogger +from pyfirstaidkit.plugins import PluginSystem +from pyfirstaidkit.reporting import Reports +from pyfirstaidkit.dependency import Dependencies + +class Initialization(unittest.TestCase): + def setUp(self): + self.confPath = "testsuite/initialization/initialization.conf" + Config.read(self.confPath) + initLogger(Config) + self.pluginSystem = PluginSystem(reporting=Reports(), dependencies=Dependencies()) + self.plugin = self.pluginSystem.getplugin("pluginInfo") + + +class Imports(Initialization): + """Tests the capability of importing 3 typs of files.""" + + def testImportsPy(self): + self.assert_('pyFile' in self.pluginSystem.list(), "Firstaidkit failed to import a 'py' file.") + + def testImportsPyc(self): + self.assert_('pycFile' in self.pluginSystem.list(), "Firstaidkit failed to import a 'pyc' file.") + + def testImportsDir(self): + self.assert_('directory' in self.pluginSystem.list(), "Firstaidkit failed to import from a directory.") + +class Info(Initialization): + """Test the infomration from the plugins.""" + def testInfoName(self): + self.assertEqual(self.plugin.name, "TestInfoPlugin") + + def testInfoAuthor(self): + self.assertEqual(self.plugin.author, "John Galt") + + def testInfoVersion(self): + self.assertEqual(self.plugin.version, "3.4.5") + + def testInfoFlowName(self): + self.assert_('newflow' in self.plugin.getFlows(), "Firstaidkit failed to show access the flow name") + + def testInfoFlowDescription(self): + self.assert_('This is the newflow' == self.plugin.getFlow("newflow").description, "Firstaidkit failed to show access the flow name") + diff --git a/testsuite/initialization/directory/__init__.py b/testsuite/initialization/directory/__init__.py new file mode 100644 index 0000000..9e799a0 --- /dev/null +++ b/testsuite/initialization/directory/__init__.py @@ -0,0 +1,3 @@ +import directory +def get_plugin(): + return directory.Dir diff --git a/testsuite/initialization/directory/directory.py b/testsuite/initialization/directory/directory.py new file mode 100644 index 0000000..accee7a --- /dev/null +++ b/testsuite/initialization/directory/directory.py @@ -0,0 +1,43 @@ +# First Aid Kit - diagnostic and repair tool for Linux +# Copyright (C) 2008 Joel Granados +# +# This program 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 2 of the License, or +# (at your option) any later version. +# +# This program 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 this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +from pyfirstaidkit.plugins import Plugin + +class Dir(Plugin): + name = "TestPlugin" + version = "0.0.1" + author = "Joel Andres Granados" + def __init__(self, *args, **kwargs): + Plugin.__init__(self, *args, **kwargs) + + def prepare(self): + pass + + def backup(self): + pass + + def restore(self): + pass + + def diagnose(self): + pass + + def fix(self): + pass + + def clean(self): + pass diff --git a/testsuite/initialization/initialization.conf b/testsuite/initialization/initialization.conf new file mode 100644 index 0000000..b6cf64c --- /dev/null +++ b/testsuite/initialization/initialization.conf @@ -0,0 +1,91 @@ +# +# First Aid Kit configuration file. +# +# This file basically expresses what firstaidkit defaults to. You may uncomment +# lines that you want to change. + + +# +# System: +# +[system] + +# +# root: +# Defines the relative root that firstaidkit will use for the execution of its +# plugins. +#root = /mnt/sysimage + +# +# frontend: +# Where to look for the frontend modules +#frontend = '/usr/lib64/firstaidkit/frontend' '/usr/lib/firstaidkit/frontend' + +# +# configuration: +# Where to look for configuration tidbits for plugins and other subparts +#configuration = /etc/firstaidkit/ + +# +# Operation: +# +[operation] + +# +# flags: +# +#flags = "" + +# +# mode: +# +#mode = + +# +# help: +# +#help= + +# +# gui: +# +#gui= + +# +# verbose: +# +#verbose= + +# +# interactive: +# +#interactive= + +# +# Log: +# +[log] + +# +# method: +# +#method= + +# +# filename: +# +filename = testsuite/initialization/initialization.log + + +# +# Paths: +# Will hold all the paths defined by the user that hold plugins. +# +[paths] +# +# These directories are the possible places where one can find plugin or example +# plugins. Add directories as you see fit. Unless you are developing plugins +# the default values should be enough. +# lib64: +# +plugin_examples = testsuite/initialization diff --git a/testsuite/initialization/pluginInfo.py b/testsuite/initialization/pluginInfo.py new file mode 100644 index 0000000..8b2d80f --- /dev/null +++ b/testsuite/initialization/pluginInfo.py @@ -0,0 +1,55 @@ +# First Aid Kit - diagnostic and repair tool for Linux +# Copyright (C) 2008 Joel Granados +# +# This program 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 2 of the License, or +# (at your option) any later version. +# +# This program 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 this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +from pyfirstaidkit.plugins import Plugin, Flow +from pyfirstaidkit.returns import * + +class PluginInfo(Plugin): + name = "TestInfoPlugin" + version = "3.4.5" + author = "John Galt" + flows={} + flows["newflow"] = Flow({ + Plugin.initial: {Return: "prepare"}, + "prepare" : {ReturnSuccess: "fix"}, + "fix" : {ReturnSuccess: "clean", ReturnFailure: "clean"}, + "clean" : {ReturnSuccess: Plugin.final} + }, description="This is the newflow") + + def __init__(self, *args, **kwargs): + Plugin.__init__(self, *args, **kwargs) + + def prepare(self): + pass + + def backup(self): + pass + + def restore(self): + pass + + def diagnose(self): + pass + + def fix(self): + pass + + def clean(self): + pass + +def get_plugin(): + return PluginInfo diff --git a/testsuite/initialization/pyFile.py b/testsuite/initialization/pyFile.py new file mode 100644 index 0000000..a8afa98 --- /dev/null +++ b/testsuite/initialization/pyFile.py @@ -0,0 +1,46 @@ +# First Aid Kit - diagnostic and repair tool for Linux +# Copyright (C) 2008 Joel Granados +# +# This program 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 2 of the License, or +# (at your option) any later version. +# +# This program 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 this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +from pyfirstaidkit.plugins import Plugin + +class PyFile(Plugin): + name = "TestPlugin" + version = "0.0.1" + author = "Joel Andres Granados" + def __init__(self, *args, **kwargs): + Plugin.__init__(self, *args, **kwargs) + + def prepare(self): + pass + + def backup(self): + pass + + def restore(self): + pass + + def diagnose(self): + pass + + def fix(self): + pass + + def clean(self): + pass + +def get_plugin(): + return PyFile diff --git a/testsuite/initialization/pycFile b/testsuite/initialization/pycFile new file mode 100644 index 0000000..40f2f79 --- /dev/null +++ b/testsuite/initialization/pycFile @@ -0,0 +1,46 @@ +# First Aid Kit - diagnostic and repair tool for Linux +# Copyright (C) 2008 Joel Granados +# +# This program 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 2 of the License, or +# (at your option) any later version. +# +# This program 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 this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +from pyfirstaidkit.plugins import Plugin + +class PycFile(Plugin): + name = "TestPlugin" + version = "0.0.1" + author = "Joel Andres Granados" + def __init__(self, *args, **kwargs): + Plugin.__init__(self, *args, **kwargs) + + def prepare(self): + pass + + def backup(self): + pass + + def restore(self): + pass + + def diagnose(self): + pass + + def fix(self): + pass + + def clean(self): + pass + +def get_plugin(): + return PycFile -- cgit