mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2025-12-16 09:40:07 +01:00
Unit tests for wx.Point
git-svn-id: https://svn.wxwidgets.org/svn/wx/sandbox/trunk/Phoenix@66135 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
12
runtests.py
Executable file
12
runtests.py
Executable file
@@ -0,0 +1,12 @@
|
|||||||
|
import sys, os
|
||||||
|
|
||||||
|
if sys.version_info < (2,7):
|
||||||
|
# The unittest2 package has back-ported most of the new features of the
|
||||||
|
# unittest module in Python 2.7, you can get it at PyPI.
|
||||||
|
import unittest2
|
||||||
|
else:
|
||||||
|
import unittest
|
||||||
|
sys.modules['unittest2'] = unittest
|
||||||
|
|
||||||
|
args = sys.argv[:1] + 'discover -p test_*.py -s unittests -t .'.split() + sys.argv[1:]
|
||||||
|
unittest2.main( argv=args )
|
||||||
0
unittests/__init__.py
Normal file
0
unittests/__init__.py
Normal file
87
unittests/test_gdicmn.py
Normal file
87
unittests/test_gdicmn.py
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
import unittest2
|
||||||
|
import wx
|
||||||
|
|
||||||
|
class Point(unittest2.TestCase):
|
||||||
|
|
||||||
|
def test_default_ctor(self):
|
||||||
|
p = wx.Point()
|
||||||
|
self.assertTrue(p == (0,0))
|
||||||
|
|
||||||
|
def test_xy_ctor(self):
|
||||||
|
p = wx.Point(123,456)
|
||||||
|
|
||||||
|
def test_RealPoint_ctor(self):
|
||||||
|
p = wx.Point(wx.RealPoint(1.2, 2.9))
|
||||||
|
self.assertTrue(p == (1,2))
|
||||||
|
|
||||||
|
def test_copy_ctor(self):
|
||||||
|
p1 = wx.Point(3,4)
|
||||||
|
p2 = wx.Point(p1)
|
||||||
|
self.assertTrue(p1 is not p2)
|
||||||
|
self.assertTrue(p1 == p2)
|
||||||
|
|
||||||
|
def test_bogus_ctor1(self):
|
||||||
|
with self.assertRaises(TypeError):
|
||||||
|
p = wx.Point('fiddle-fadle')
|
||||||
|
|
||||||
|
def test_bogus_ctor2(self):
|
||||||
|
with self.assertRaises(TypeError):
|
||||||
|
p = wx.Point(1,2,3)
|
||||||
|
|
||||||
|
def test_DefaultPosition(self):
|
||||||
|
wx.DefaultPosition
|
||||||
|
self.assertTrue(wx.DefaultPosition == (-1,-1))
|
||||||
|
|
||||||
|
def test_FullySpecified(self):
|
||||||
|
p = wx.Point(1,2)
|
||||||
|
self.assertTrue(p.IsFullySpecified())
|
||||||
|
p = wx.Point(-1,2)
|
||||||
|
self.assertTrue(not p.IsFullySpecified())
|
||||||
|
|
||||||
|
def test_xy(self):
|
||||||
|
p = wx.Point(2, 3)
|
||||||
|
self.assertTrue(p.x == 2 and p.y == 3)
|
||||||
|
p.x += 1
|
||||||
|
p.y += 2
|
||||||
|
self.assertTrue(p.x == 3 and p.y == 5)
|
||||||
|
self.assertTrue(p == (3,5))
|
||||||
|
|
||||||
|
def test_Get(self):
|
||||||
|
p = wx.Point(5,6)
|
||||||
|
self.assertTrue(type(p.Get()) == tuple)
|
||||||
|
self.assertTrue(p.Get() == (5,6))
|
||||||
|
|
||||||
|
def test_operators(self):
|
||||||
|
p1 = wx.Point(100, 500)
|
||||||
|
p2 = wx.Point(50, 100)
|
||||||
|
p1 == p2
|
||||||
|
p1 != p2
|
||||||
|
p = p1 + p2
|
||||||
|
p = p1 + wx.Size(5,5)
|
||||||
|
p = -p1
|
||||||
|
p = p1 - p2
|
||||||
|
p = p1 - wx.Size(5,5)
|
||||||
|
p = p1 * 5
|
||||||
|
p = 5 * p1
|
||||||
|
p = p1 / 5
|
||||||
|
p1 += p2
|
||||||
|
p1 -= p2
|
||||||
|
|
||||||
|
def test_magic(self):
|
||||||
|
p = wx.Point(5,6)
|
||||||
|
self.assertTrue(str(p) == "(5, 6)")
|
||||||
|
self.assertTrue(repr(p) == "wx.Point(5, 6)")
|
||||||
|
self.assertTrue(len(p) == 2)
|
||||||
|
x, y = p
|
||||||
|
self.assertTrue(x == 5 and y == 6)
|
||||||
|
p[0] += 1 # tests both getitem and setitem
|
||||||
|
p[1] += 2
|
||||||
|
self.assertTrue(p == (6,8))
|
||||||
|
with self.assertRaises(IndexError):
|
||||||
|
p[2]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest2.main()
|
||||||
Reference in New Issue
Block a user