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

Source Code for Module flumotion.extern.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 os 
21  import sys 
22  import tempfile 
23  import commands 
24  import unittest 
25  import StringIO 
26   
27  import command 
28     
29 -class CommandTestCase(unittest.TestCase):
30 - def testCommandNoName(self):
31 c = command.Command() 32 self.assertEquals(c.name, "command")
33
34 -class FakeSubSubCommand(command.Command):
35 description = "Fake subsubcommand" 36 aliases = "fssc"
37
38 -class FakeSubCommand(command.Command):
39 description = "Fake subcommand" 40 subCommandClasses = [FakeSubSubCommand, ]
41
42 -class FakeCommand(command.Command):
43 description = "Fake command" 44 subCommandClasses = [FakeSubCommand, ]
45
46 -class FakeCommandTestCase(unittest.TestCase):
47 - def setUp(self):
48 unittest.TestCase.setUp(self) 49 self.out = StringIO.StringIO() 50 self.err = StringIO.StringIO() 51 self.c = FakeCommand(stdout=self.out, stderr=self.err) 52 self.assertEquals(self.c.name, "fakecommand")
53
54 - def testHelpCommands(self):
55 self.assertEquals(0, self.c.parse(['--help', ])) 56 lookFor = "%s " % self.c.subCommands.keys()[0] 57 self.failUnless(self.out.getvalue().find(lookFor) > -1, 58 "out %r does not contain %s" % (self.out.getvalue(), lookFor))
59
60 - def testNoCommand(self):
61 ret = self.c.parse([]) 62 self.assertEquals(ret, 1) 63 self.failIf(self.out.getvalue(), "Should not get output") 64 # It seems the F7 version uppercases the first letter, making it Usage 65 out = self.err.getvalue() 66 self.failUnless(out[1:].startswith('sage:'), 67 "output %s does not start with U/usage" % out)
68
69 -class FakeSubCommandTestCase(unittest.TestCase):
70 - def setUp(self):
71 unittest.TestCase.setUp(self) 72 self.out = StringIO.StringIO() 73 self.err = StringIO.StringIO() 74 self.c = FakeSubCommand(stdout=self.out, stderr=self.err) 75 self.assertEquals(self.c.name, "fakesubcommand")
76
77 - def testHelpCommands(self):
78 self.assertEquals(0, self.c.parse(['--help', ])) 79 lookFor = "%s " % self.c.subCommands.keys()[0] 80 self.failUnless(self.out.getvalue().find(lookFor) > -1, 81 "out %r does not contain %s" % (self.out.getvalue(), lookFor))
82 83 84 if __name__ == '__main__': 85 unittest.main() 86