forked from svn2github/wxPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestSize.py
More file actions
136 lines (117 loc) · 4.4 KB
/
Copy pathtestSize.py
File metadata and controls
136 lines (117 loc) · 4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
"""Unit tests for wx.Size.
Methods yet to test:
__init__, __del__, __getitem__, __len__, __nonzero__,
__reduce__, __repr__, __setitem__, __str__, __sub__, DecBy, DecTo,
IncBy, IncTo, Scale, SetDefaults"""
import unittest
import wx
import wxtest
import math
def getSizes(ctrl, kind):
# determine get/set methods
set,get = None,None
if kind == wxtest.SIZE:
set,get = ctrl.SetSize, ctrl.GetSize
elif kind == wxtest.VIRTUAL_SIZE:
set,get = ctrl.SetVirtualSize, ctrl.GetVirtualSize
elif kind == wxtest.CLIENT_SIZE:
set,get = ctrl.SetClientSize, ctrl.GetClientSize
else:
raise TypeError("Incorrect type constant used")
# get mins and maxes
set((1,1))
xmin,ymin = get()
set((2**15-1,2**15-1)) # 16-bit signed int
# for more information, see issue #1756896.
# if the limit is exceeded, wx will sometimes return junk
# values rather than asserting the max possible value
xmax,ymax = get()
# print?
#print "%s [x]: %s (min), %s (max)" % (str(type(ctrl)), str(xmin), str(xmax))
#print "%s [y]: %s (min), %s (max)" % (str(type(ctrl)), str(ymin), str(ymax))
# generate data sets
xset = [xmin,xmax]
yset = [ymin,ymax]
xrange = xmax-xmin
yrange = ymax-ymin
xinc = int(math.floor(xrange/11))
yinc = int(math.floor(yrange/11))
for i in range(1,11):
xset.append(xmin+xinc*i)
yset.append(ymin+yinc*i)
return zip(xset,yset)
def getSizeData():
data = []
for x in range(0,100,10):
for y in range(0,100,10):
data.append(wx.Size(x,y))
return data
# -----------------------------------------------------------
NEG_TWO = wx.Size(-2,-2)
NEG_ONE = wx.Size(-1,-1)
ZERO = wx.Size(0,0)
ONE = wx.Size(1,1)
TWO = wx.Size(2,2)
# -----------------------------------------------------------
class SizeTest(unittest.TestCase):
def setUp(self):
self.testControl = wx.Size()
# NOTE:
# testEquals, testNotEquals, testAddition, testSubtraction
# were copied from testPoint class. In the future, possibly
# refactor out code duplication.
def testEquals(self):
"""__eq__"""
self.assert_( ZERO == ZERO )
self.assert_( ZERO == wx.Size(0,0) )
self.assert_( ZERO == wx.Size() )
self.assert_( NEG_ONE == NEG_ONE )
self.assert_( NEG_ONE == wx.Size(-1,-1) )
self.assert_( ONE == ONE )
self.assert_( ONE == wx.Size(1,1) )
def testNotEquals(self):
"""__ne__"""
self.assert_( ZERO != ONE )
self.assert_( ONE != NEG_ONE )
self.assert_( TWO != NEG_TWO )
self.assert_( NEG_TWO != ZERO )
def testAddition(self):
"""__add__"""
self.assertEquals( ONE+NEG_ONE, ZERO )
self.assertEquals( TWO+NEG_TWO, ZERO )
self.assertEquals( ONE+ONE, TWO )
self.assertEquals( ZERO+ZERO, ZERO )
self.assertEquals( NEG_ONE+NEG_ONE, NEG_TWO )
self.assertEquals( ONE+ZERO, ONE )
self.assertEquals( TWO+NEG_ONE, ONE )
def testSubtraction(self):
"""__sub__"""
self.assertEquals( ONE-ONE, ZERO )
self.assertEquals( NEG_ONE-NEG_ONE, ZERO )
self.assertEquals( ONE-NEG_ONE, TWO )
self.assertEquals( NEG_ONE-ONE, NEG_TWO )
self.assertEquals( ZERO-ONE, NEG_ONE )
self.assertEquals( ZERO-NEG_ONE, ONE )
self.assertEquals( NEG_ONE-ZERO, NEG_ONE )
self.assertEquals( ONE-ZERO, ONE )
def testFullySpecified(self):
"""IsFullySpecified"""
self.assert_(self.testControl.IsFullySpecified())
self.assert_(wx.Size(10,10).IsFullySpecified())
self.assert_(wx.Size(-10,-10).IsFullySpecified())
self.assert_(not wx.Size(-1,-1).IsFullySpecified())
def testGetSet(self):
"""Set, Get"""
for w,h in getSizeData():
self.testControl.Set(w,h)
self.assertEquals((w,h), self.testControl.Get())
def testHeight(self):
"""SetHeight, GetHeight"""
for w,h in getSizeData():
self.testControl.SetHeight(h)
self.assertEquals(h, self.testControl.GetHeight())
def testWidth(self):
"""SetWidth, GetWidth"""
for w,h in getSizeData():
self.testControl.SetWidth(w)
self.assertEquals(w, self.testControl.GetWidth())