~ubuntu-branches/ubuntu/precise/pida/precise

« back to all changes in this revision

Viewing changes to tests/command_test.py

  • Committer: Bazaar Package Importer
  • Author(s): Jan Luebbe
  • Date: 2007-04-17 16:08:06 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070417160806-3ttlb6igf94x9i03
Tags: 0.4.4-1
* New upstream release (closes: #419129)
* Add dependency on python-glade2 (closes: #418716)
* Update copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*- 
2
 
 
3
 
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
4
 
#Copyright (c) 2005 Ali Afshar aafshar@gmail.com
5
 
 
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:
12
 
 
13
 
#The above copyright notice and this permission notice shall be included in
14
 
#all copies or substantial portions of the Software.
15
 
 
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
22
 
#SOFTWARE.
23
 
 
24
 
import command
25
 
import unittest
26
 
 
27
 
 
28
 
class test_a_argument(unittest.TestCase):
29
 
 
30
 
 
31
 
    def setUp(self):
32
 
        self.a1 = command.argument('banana', False)
33
 
        self.a2 = command.argument('melon', True)
34
 
 
35
 
    def test_a_init(self):
36
 
        self.assert_(self.a1)
37
 
        self.assert_(self.a2)
38
 
 
39
 
    def test_b_name(self):
40
 
        self.assertEquals(self.a1.name, 'banana')
41
 
        self.assertEquals(self.a2.name, 'melon')
42
 
 
43
 
    def test_c_required(self):
44
 
        self.assertFalse(self.a1.required)
45
 
        self.assertTrue(self.a2.required)
46
 
 
47
 
class test_b_command(unittest.TestCase):
48
 
 
49
 
    def setUp(self):
50
 
        self.__dummycount = 0
51
 
        self.__dummyargs = []
52
 
        self.__dummykw = {}
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,
57
 
                                  [arg1, arg2])
58
 
 
59
 
    def __dummy_callback(self, *args, **kw):
60
 
        self.__dummycount = self.__dummycount + 1
61
 
        self.__dummyargs = args
62
 
        self.__dummykw = kw
63
 
        return True
64
 
 
65
 
    def test_a_init(self):
66
 
        self.assert_(self.c1)
67
 
        self.assert_(self.c2)
68
 
 
69
 
    def test_b_call_good(self):
70
 
        self.assertEquals(self.__dummycount, 0)
71
 
        self.assertTrue(self.c1())
72
 
        self.assertEquals(self.__dummycount, 1)
73
 
 
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'})
79
 
 
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',
85
 
                                           'melon': 'green'})
86