From 36e09a96ad12973b38cf0e403d6ddd5ae429de09 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Sat, 13 Nov 2010 08:15:40 +0000 Subject: [PATCH] Unit tests for wx.Point git-svn-id: https://svn.wxwidgets.org/svn/wx/sandbox/trunk/Phoenix@66135 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- runtests.py | 12 ++++++ unittests/__init__.py | 0 unittests/test_gdicmn.py | 87 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100755 runtests.py create mode 100644 unittests/__init__.py create mode 100644 unittests/test_gdicmn.py diff --git a/runtests.py b/runtests.py new file mode 100755 index 00000000..f61d2b6c --- /dev/null +++ b/runtests.py @@ -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 ) diff --git a/unittests/__init__.py b/unittests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/unittests/test_gdicmn.py b/unittests/test_gdicmn.py new file mode 100644 index 00000000..ba81ae46 --- /dev/null +++ b/unittests/test_gdicmn.py @@ -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() \ No newline at end of file