Package pytilities :: Package overloading :: Package test :: Module overloaded
[hide private]
[frames] | no frames]

Source Code for Module pytilities.overloading.test.overloaded

 1  # Copyright (C) 2010 Tim Diels <limyreth@users.sourceforge.net> 
 2  #  
 3  # This file is part of pytilities. 
 4  #  
 5  # pytilities is free software: you can redistribute it and/or modify 
 6  # it under the terms of the GNU General Public License as published by 
 7  # the Free Software Foundation, either version 3 of the License, or 
 8  # (at your option) any later version. 
 9  #  
10  # pytilities is distributed in the hope that it will be useful, 
11  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
12  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
13  # GNU General Public License for more details. 
14  #  
15  # You should have received a copy of the GNU General Public License 
16  # along with pytilities.  If not, see <http://www.gnu.org/licenses/>. 
17  # 
18   
19  __docformat__ = 'reStructuredText' 
20   
21  import unittest 
22  from .. import overloaded, Overload, Param 
23  from pytilities.types import NumberType 
24 25 -class Storage(object):
26 """Something with an x and y""" 27 x = 1 28 y = 1
29
30 -class A(object):
31 """Some class to test with""" 32
33 - def __init_xy(self, x, y):
34 return "xy", self, x, y
35
36 - def __init_storage(self, storage):
37 return "storage", self, storage
38 39 @overloaded(( 40 Overload(__init_xy, 41 Param("x", NumberType, default=0), 42 Param("y", NumberType, default=0)), 43 Overload(__init_storage, 44 Param("storage"))))
45 - def say_ni(self):
46 """docstring is docstring""" 47 pass
48
49 50 -class TestCase(unittest.TestCase):
51 - def setUp(self):
52 self.a = A() 53 self.s = Storage()
54
55 - def test_xy(self):
56 """Calls that should end up at xy""" 57 self.assertEquals(self.a.say_ni(), ("xy", self.a, 0, 0)) 58 self.assertEquals(self.a.say_ni(3), ("xy", self.a, 3, 0)) 59 self.assertEquals(self.a.say_ni(x=3), ("xy", self.a, 3, 0)) 60 self.assertEquals(self.a.say_ni(3, 6), ("xy", self.a, 3, 6)) 61 self.assertEquals(self.a.say_ni(x=3, y=6), ("xy", self.a, 3, 6)) 62 self.assertEquals(self.a.say_ni(y=6), ("xy", self.a, 0, 6))
63
64 - def test_storage(self):
65 """Calls that should end up at storage""" 66 self.assertEquals(self.a.say_ni(self.s), ("storage", self.a, self.s))
67
68 - def test_bad(self):
69 """Calls that should cause assertion errors""" 70 self.assertRaises(AssertionError, lambda: self.a.say_ni(0, self.s))
71
72 # TODO test for match(val):bool 73 74 -def run():
75 unittest.main(__name__)
76