Package flumotion :: Package extern :: Package command :: Package command :: Module test_command
[hide private]

Source Code for Module flumotion.extern.command.command.test_command

  1  # -*- Mode: Python; test-case-name: test_command -*- 
  2  # vi:si:et:sw=4:sts=4:ts=4 
  3  # 
  4  # Copyright (C) 2006,2007 Thomas Vander Stichele <thomas at apestaart dot org> 
  5   
  6  # This program is free software; you can redistribute it and/or modify 
  7  # it under the terms of the GNU General Public License as published by 
  8  # the Free Software Foundation; either version 2 of the License, or 
  9  # (at your option) any later version. 
 10  # 
 11  # This program is distributed in the hope that it will be useful, 
 12  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 14  # GNU General Public License for more details. 
 15  # 
 16  # You should have received a copy of the GNU General Public License 
 17  # along with this program; if not, write to the Free Software 
 18  # Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. 
 19   
 20  import sys 
 21  import unittest 
 22  import StringIO 
 23   
 24  import command 
 25   
 26   
27 -class CommandTestCase(unittest.TestCase):
28
29 - def testCommandNoName(self):
30 c = command.Command() 31 self.assertEquals(c.name, "command")
32
34 35 class NewCommand(command.Command, object): 36 pass
37 38 c = NewCommand() 39 self.assertEquals(c.name, "newcommand")
40 41
42 -class FakeSubSubCommand(command.Command):
43 description = "Fake subsubcommand" 44 aliases = "fssc"
45 46
47 -class FakeSubCommand(command.Command):
48 description = "Fake subcommand" 49 subCommandClasses = [FakeSubSubCommand, ]
50 51
52 -class FakeCommand(command.Command):
53 description = "Fake command" 54 subCommandClasses = [FakeSubCommand, ]
55 56
57 -class FakeCommandTestCase(unittest.TestCase):
58
59 - def setUp(self):
60 unittest.TestCase.setUp(self) 61 self.out = StringIO.StringIO() 62 self.err = StringIO.StringIO() 63 self.c = FakeCommand(stdout=self.out, stderr=self.err) 64 self.assertEquals(self.c.name, "fakecommand")
65
66 - def testHelpCommands(self):
67 self.assertEquals(None, self.c.parse(['--help', ])) 68 lookFor = "%s " % self.c.subCommands.keys()[0] 69 self.failUnless(self.out.getvalue().find(lookFor) > -1, 70 "out %r does not contain %s" % (self.out.getvalue(), lookFor))
71
72 - def testNoCommand(self):
73 ret = self.c.parse([]) 74 self.assertEquals(ret, 1) 75 out = self.err.getvalue() 76 self.failIf(out, "Should not get output on stderr, but got %r" % out) 77 # It seems the F7 version uppercases the first letter, making it Usage 78 out = self.out.getvalue() 79 self.failUnless(out[1:].startswith('sage:'), 80 "output %s does not start with U/usage" % out)
81 82
83 -class FakeSubCommandTestCase(unittest.TestCase):
84
85 - def setUp(self):
86 unittest.TestCase.setUp(self) 87 self.out = StringIO.StringIO() 88 self.err = StringIO.StringIO() 89 self.c = FakeSubCommand(stdout=self.out, stderr=self.err) 90 self.assertEquals(self.c.name, "fakesubcommand")
91
92 - def testHelpCommands(self):
93 self.assertEquals(None, self.c.parse(['--help', ])) 94 lookFor = "%s " % self.c.subCommands.keys()[0] 95 self.failUnless(self.out.getvalue().find(lookFor) > -1, 96 "out %r does not contain %s" % (self.out.getvalue(), lookFor))
97 98 99 if __name__ == '__main__': 100 unittest.main() 101