summaryrefslogtreecommitdiffstats
path: root/testsuite/cli.py
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/cli.py')
-rw-r--r--testsuite/cli.py282
1 files changed, 196 insertions, 86 deletions
diff --git a/testsuite/cli.py b/testsuite/cli.py
index 94ae731..c68302a 100644
--- a/testsuite/cli.py
+++ b/testsuite/cli.py
@@ -16,99 +16,209 @@
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-import unittest, subprocess, os, os.path, difflib, exceptions
-
-clioutputdir="testsuite/cli/outputs"
-class Cli(unittest.TestCase):
- def generateDiff(self, args, filename):
- fd = os.open(os.path.join(clioutputdir, filename+".current"), \
- os.O_WRONLY|os.O_CREAT)
- subprocess.Popen(args, stdout=fd).wait()
- os.close(fd)
-
- fda = open(os.path.join(clioutputdir, filename+".current"), "r")
- fdb = open(os.path.join(clioutputdir, filename), "r")
- linesa = fda.readlines()
- linesb = fdb.readlines()
- fda.close()
- fdb.close()
- return difflib.unified_diff(linesa, linesb)
-
-
+import unittest, subprocess, os, os.path, exceptions
+
+# List of messages that each plugin outputs when entering a task.
+# for Plugincli1
+enteringM1 = {
+ "init" :"INFO: Entering the init phase... (Plugincli1)",
+ "prepare" :"INFO: Entering the prepare phase... (Plugincli1)",
+ "backup" :"INFO: Entering the backup phase... (Plugincli1)",
+ "restore" :"INFO: Entering the restore phase... (Plugincli1)",
+ "diagnose" :"INFO: Entering the diagnose phase... (Plugincli1)",
+ "fix" :"INFO: Entering the fix phase... (Plugincli1)",
+ "clean" :"INFO: Entering the clean phase... (Plugincli1)"
+ }
+
+# List of messages that each plugin outputs when entering a task.
+# for Plugincli2
+enteringM2 = {
+ "init" :"INFO: Entering the init phase... (Plugincli2)",
+ "prepare" :"INFO: Entering the prepare phase... (Plugincli2)",
+ "backup" :"INFO: Entering the backup phase... (Plugincli2)",
+ "restore" :"INFO: Entering the restore phase... (Plugincli2)",
+ "diagnose" :"INFO: Entering the diagnose phase... (Plugincli2)",
+ "fix" :"INFO: Entering the fix phase... (Plugincli2)",
+ "clean" :"INFO: Entering the clean phase... (Plugincli2)"
+ }
+
+# List of messages that the Plugin System outputs.
+psM = {
+ "usingfix":"INFO: Using fix flow (Plugin System)"
+ }
+
+# List of messages that the Tasker outputs for Plugincli1
+taskerM1 = {
+ "flownoexist":"INFO: Plugin plugincli1 does not contain flow nonexistent (Task interpreter)"
+ }
+
+# List of messages that the Tasker outputs for Plugincli2
+taskerM2 = {
+ "flownoexist":"INFO: Plugin plugincli2 does not contain flow nonexistent (Task interpreter)"
+ }
+
+# FAK error message
+fakerror = {
+ "pluginnoexist":"FAK_ERROR: No plugin by the name of \"nonexistent\" was found."
+ }
+
+
+class FAKfirstaidkit__a(unittest.TestCase):
def setUp(self):
- # All the diff objects will be in this list.
- self.udiffs = {}
-
- # We generate all the needed cli call files from a dict.
- # The key is considered the filename.
- self.clicallfiles = {
- "firstaidkit_-a" : \
- ["./firstaidkit", "-P", "testsuite/cli/", "-a"],
- "firstaidkit_-a_fix" : \
- ["./firstaidkit", "-P", "testsuite/cli/", "-a", \
- "fix"],
- "firstaidkit_-a_nonexistent" : \
- ["./firstaidkit", "-P", "testsuite/cli/", "-a", \
- "nonexistent"],
- "firstaidkit_-a_-x_plugincli1" : \
- ["./firstaidkit", "-P", "testsuite/cli/", "-a", \
- "-x", "plugincli1"],
- "firstaidkit_-f_nonexistent" : \
- ["./firstaidkit", "-P", "testsuite/cli/", "-f", \
- "nonexistent"],
- "firstaidkit_-f_plugincli1" : \
- ["./firstaidkit", "-P", "testsuite/cli/", "-f", \
- "plugincli1"],
- "firstaidkit_-f_plugincli1_fix" : \
- ["./firstaidkit", "-P", "testsuite/cli/", "-f", \
- "plugincli1", "fix"],
- "firstaidkit_-f_plugincli1_nonexistent" : \
- ["./firstaidkit", "-P", "testsuite/cli/", "-f", \
- "plugincli1", "nonexistent"]
- }
-
- for (key, arg) in self.clicallfiles.iteritems():
- self.udiffs[key] = self.generateDiff(arg, key)
-
- def tearDown(self):
- for (key, arg) in self.clicallfiles.iteritems():
- os.remove(os.path.join(clioutputdir, key+".current"))
-
-class AutoExec(Cli):
- def testfirstaidkit__a(self):
- self.failUnlessRaises(exceptions.StopIteration, \
- self.udiffs["firstaidkit_-a"].next)
-
- def testfirstaidkit__a_fix(self):
- self.failUnlessRaises(exceptions.StopIteration, \
- self.udiffs["firstaidkit_-a_fix"].next)
-
- def testfirstaidkit__a_nonexistent(self):
- self.failUnlessRaises(exceptions.StopIteration, \
- self.udiffs["firstaidkit_-a_nonexistent"].next)
-
- def testfirstaidkit__a__x_plugincli1(self):
- self.failUnlessRaises(exceptions.StopIteration, \
- self.udiffs["firstaidkit_-a_-x_plugincli1"].next)
+ self.command = ["./firstaidkit", "-P", "testsuite/cli/", "-a"]
+ (out, err) = subprocess.Popen(self.command, stdout=subprocess.PIPE, \
+ stderr=subprocess.PIPE).communicate()
+ self.output = out
+ self.trueMes = [ "init", "prepare", "diagnose", "clean"]
+ self.falseMes = [ "fix", "backup", "restore"]
+
+ def testOutput(self):
+ for elem in self.trueMes:
+ self.assertTrue(enteringM1[elem] in self.output, \
+ "message: '%s' not preesnt in output" % \
+ enteringM1[elem])
+ self.assertTrue(enteringM2[elem] in self.output, \
+ "message: '%s' not preesnt in output" % \
+ enteringM2[elem])
+
+ for elem in self.falseMes:
+ self.assertFalse(enteringM1[elem] in self.output, \
+ "message:'%s' is present in output" % \
+ enteringM1[elem])
+ self.assertFalse(enteringM2[elem] in self.output, \
+ "message '%s' is presetn in output" % \
+ enteringM2[elem])
+
+class FAKfirstaidkit__a_fix(unittest.TestCase):
+ def setUp(self):
+ self.command = ["./firstaidkit", "-P", "testsuite/cli/", "-a", "fix"]
+ (out, err) = subprocess.Popen(self.command, stdout=subprocess.PIPE, \
+ stderr=subprocess.PIPE).communicate()
+ self.output = out
+ self.mess = ["fix", "backup"]
+
+ def testOutput(self):
+ for elem in self.mess:
+ self.assertTrue(enteringM1[elem] in self.output, \
+ "message: '%s' is not present in output" % \
+ enteringM1[elem])
+ self.assertFalse(enteringM2[elem] in self.output, \
+ "message: '%s' is present in output" % \
+ enteringM2[elem])
+
+ self.assertTrue(psM["usingfix"] in self.output, \
+ "Plugin System '%s' message not in output" % \
+ psM["usingfix"])
+
+
+class FAKfirstaidkit__a_nonexistent(unittest.TestCase):
+ def setUp(self):
+ self.command = ["./firstaidkit", "-P", "testsuite/cli/", "-a", \
+ "nonexistent"]
+ (out, err) = subprocess.Popen(self.command, stdout=subprocess.PIPE, \
+ stderr=subprocess.PIPE).communicate()
+ self.output = out
+
+ def testOutput(self):
+ self.assertTrue(taskerM1["flownoexist"] in self.output, \
+ "Tasker '%s' message not present in output for plugincli1" % \
+ taskerM1["flownoexist"])
+
+ self.assertTrue(taskerM2["flownoexist"] in self.output, \
+ "Tasker '%s' message not present in output for plugincli2" % \
+ taskerM1["flownoexist"])
+
+class FAKfirstaidkit__a__x_plugincli1(unittest.TestCase):
+ def setUp(self):
+ self.command = ["./firstaidkit", "-P", "testsuite/cli/", "-a", \
+ "-x", "plugincli1"]
+ (out, err) = subprocess.Popen(self.command, stdout=subprocess.PIPE, \
+ stderr=subprocess.PIPE).communicate()
+ self.output = out
+ def test1(self):
+ for (key, val) in enteringM1.iteritems():
+ self.assertFalse(val in self.output, \
+ "There was a message containing plugincli1 related "\
+ "messages")
-class FlowExec(Cli):
- def testfirstaidkit__f_nonexistent(self):
- self.failUnlessRaises(exceptions.StopIteration, \
- self.udiffs["firstaidkit_-f_nonexistent"].next)
+class FAKfirstaidkit__f_nonexistent(unittest.TestCase):
+ def setUp(self):
+ self.command = ["./firstaidkit", "-P", "testsuite/cli/", "-f", \
+ "nonexistent"]
+ (out, err) = subprocess.Popen(self.command, stdout=subprocess.PIPE, \
+ stderr=subprocess.PIPE).communicate()
+ self.output = out
- def testfirstaidkit__f_plugincli1(self):
- self.failUnlessRaises(exceptions.StopIteration, \
- self.udiffs["firstaidkit_-f_plugincli1"].next)
+ def test1(self):
+ self.assertTrue(fakerror["pluginnoexist"] in self.output, \
+ "FAK error 'nonexistent plugin' message not present in output")
- def testfirstaidkit__f_plugincli1_fix(self):
- self.failUnlessRaises(exceptions.StopIteration, \
- self.udiffs["firstaidkit_-f_plugincli1_fix"].next)
- def testfirstaidkit__f_plugincli1_nonexistent(self):
- self.failUnlessRaises(exceptions.StopIteration, \
- self.udiffs["firstaidkit_-f_plugincli1_nonexistent"].next)
+class FAKfirstaidkit__f_plugincli1(unittest.TestCase):
+ def setUp(self):
+ self.command = ["./firstaidkit", "-P", "testsuite/cli/", "-f", \
+ "plugincli1"]
+ (out, err) = subprocess.Popen(self.command, stdout=subprocess.PIPE, \
+ stderr=subprocess.PIPE).communicate()
+ self.output = out
+ self.trueMes = ["init", "prepare", "diagnose", "clean"]
+ self.falseMes = ["fix", "backup", "restore"]
+
+ def testOutput(self):
+ for elem in self.trueMes:
+ self.assertTrue(enteringM1[elem] in self.output, \
+ "message: '%s' is not present in output" % \
+ enteringM1[elem])
+
+ for elem in self.falseMes:
+ self.assertFalse(enteringM1[elem] in self.output, \
+ "message: '%s' is present in output" % \
+ enteringM1[elem])
+
+ # No plugincli2 messages should be present
+ for elem in enteringM2:
+ self.assertFalse(enteringM2[elem] in self.output, \
+ "message: '%s' is present in output" % \
+ enteringM2[elem])
+
+class FAKfirstaidkit__f_plugincli1_fix(unittest.TestCase):
+ def setUp(self):
+ self.command = ["./firstaidkit", "-P", "testsuite/cli/", "-f", \
+ "plugincli1", "fix"]
+ (out, err) = subprocess.Popen(self.command, stdout=subprocess.PIPE, \
+ stderr=subprocess.PIPE).communicate()
+ self.output = out
+ self.trueMes = ["init", "prepare", "diagnose", "clean", "fix", "backup"]
+ self.falseMes = ["restore"]
+
+ def testOutput(self):
+ for elem in self.trueMes:
+ self.assertTrue(enteringM1[elem] in self.output, \
+ "message: '%s' is not present in output" % \
+ enteringM1[elem])
+
+ for elem in self.falseMes:
+ self.assertFalse(enteringM1[elem] in self.output, \
+ "message: '%s' is present in output" % \
+ enteringM1[elem])
+
+ # No plugincli2 messages should be present
+ for elem in enteringM2:
+ self.assertFalse(enteringM2[elem] in self.output, \
+ "message: '%s' is present in output" % \
+ enteringM2[elem])
+
+class FAKfirstaidkit__f_plugincli1_nonexistent(unittest.TestCase):
+ def setUp(self):
+ self.command = ["./firstaidkit", "-P", "testsuite/cli/", "-f", \
+ "plugincli1", "nonexistent"]
+ (out, err) = subprocess.Popen(self.command, stdout=subprocess.PIPE, \
+ stderr=subprocess.PIPE).communicate()
+ self.output = out
+ def testOutput(self):
+ self.assertTrue(taskerM1["flownoexist"] in self.output)