Package moap :: Package extern :: Package command :: Module test_command
[hide private]
[frames] | no frames]

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