1
# -*- coding: utf-8 -*-
3
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
4
#Copyright (c) 2005 Ali Afshar aafshar@gmail.com
6
#Permission is hereby granted, free of charge, to any person obtaining a copy
7
#of this software and associated documentation files (the "Software"), to deal
8
#in the Software without restriction, including without limitation the rights
9
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
#copies of the Software, and to permit persons to whom the Software is
11
#furnished to do so, subject to the following conditions:
13
#The above copyright notice and this permission notice shall be included in
14
#all copies or substantial portions of the Software.
16
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
class test_a_argument(unittest.TestCase):
32
self.a1 = command.argument('banana', False)
33
self.a2 = command.argument('melon', True)
35
def test_a_init(self):
39
def test_b_name(self):
40
self.assertEquals(self.a1.name, 'banana')
41
self.assertEquals(self.a2.name, 'melon')
43
def test_c_required(self):
44
self.assertFalse(self.a1.required)
45
self.assertTrue(self.a2.required)
47
class test_b_command(unittest.TestCase):
53
arg1 = command.argument('banana', True)
54
arg2 = command.argument('melon', False)
55
self.c1 = command.command('peel', self.__dummy_callback, [])
56
self.c2 = command.command('fruitbowl', self.__dummy_callback,
59
def __dummy_callback(self, *args, **kw):
60
self.__dummycount = self.__dummycount + 1
61
self.__dummyargs = args
65
def test_a_init(self):
69
def test_b_call_good(self):
70
self.assertEquals(self.__dummycount, 0)
71
self.assertTrue(self.c1())
72
self.assertEquals(self.__dummycount, 1)
74
def test_c_call_good_argument(self):
75
self.assertEquals(self.__dummycount, 0)
76
self.assertTrue(self.c2(banana='yellow'))
77
self.assertEquals(self.__dummycount, 1)
78
self.assertEquals(self.__dummykw, {'banana': 'yellow'})
80
def test_d_call_opt_argument(self):
81
self.assertEquals(self.__dummycount, 0)
82
self.assertTrue(self.c2(banana='yellow', melon='green'))
83
self.assertEquals(self.__dummycount, 1)
84
self.assertEquals(self.__dummykw, {'banana': 'yellow',