diff --git a/unittests/imp_unittest.py b/unittests/imp_unittest.py new file mode 100644 index 00000000..0f9bb707 --- /dev/null +++ b/unittests/imp_unittest.py @@ -0,0 +1,10 @@ +import sys + +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 + sys.modules['unittest'] = unittest2 + +else: + import unittest diff --git a/unittests/runtests.py b/unittests/runtests.py index c8336ca0..b530232a 100755 --- a/unittests/runtests.py +++ b/unittests/runtests.py @@ -18,15 +18,8 @@ print "wx.version:", wx.version() print "pid:", os.getpid() #print "executable:", sys.executable; raw_input("Press Enter...") -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 - unittest = unittest2 -else: - import unittest - sys.modules['unittest2'] = unittest - +import imp_unittest, unittest + args = sys.argv[:1] + 'discover -p test_*.py -s unittests -t .'.split() + sys.argv[1:] unittest.main( argv=args ) diff --git a/unittests/test_app.py b/unittests/test_app.py index cbaf0996..602c18b0 100644 --- a/unittests/test_app.py +++ b/unittests/test_app.py @@ -1,4 +1,4 @@ -import unittest2 +import imp_unittest, unittest import wx ##import os; print 'PID:', os.getpid(); raw_input('Ready to start, press enter...') @@ -6,7 +6,7 @@ import warnings #--------------------------------------------------------------------------- -class App(unittest2.TestCase): +class App(unittest.TestCase): def test_App(self): app = wx.App() @@ -47,7 +47,7 @@ class App(unittest2.TestCase): # wx.PySimpleApp is supposed to be deprecated, make sure it is. with warnings.catch_warnings(): warnings.simplefilter("error") - with self.assertRaises(DeprecationWarning): + with self.assertRaises(wx.wxPyDeprecationWarning): app = wx.PySimpleApp() @@ -71,4 +71,4 @@ class App(unittest2.TestCase): if __name__ == '__main__': - unittest2.main() + unittest.main() diff --git a/unittests/test_apptraits.py b/unittests/test_apptraits.py new file mode 100644 index 00000000..1310c5d9 --- /dev/null +++ b/unittests/test_apptraits.py @@ -0,0 +1,24 @@ +import imp_unittest, unittest +import wtc +import wx + +#--------------------------------------------------------------------------- + +class AppTraitsTests(wtc.WidgetTestCase): + + def test_AppTraits(self): + t = self.app.GetTraits() + self.assertTrue(t is not None) + + v = t.GetToolkitVersion() + self.assertTrue( len(v) == 3) + + t.HasStderr() + t.IsUsingUniversalWidgets() + + +#--------------------------------------------------------------------------- + + +if __name__ == '__main__': + unittest.main() diff --git a/unittests/test_arrayint.py b/unittests/test_arrayint.py index 08999ffe..f8c0479f 100644 --- a/unittests/test_arrayint.py +++ b/unittests/test_arrayint.py @@ -1,13 +1,13 @@ -import unittest2 +import imp_unittest, unittest import wx #--------------------------------------------------------------------------- -class ArrayInt(unittest2.TestCase): +class ArrayInt(unittest.TestCase): if hasattr(wx, 'testArrayIntTypemap'): - def test_ArrayStringTypemaps(self): + def test_ArrayIntTypemaps(self): # basic conversion of list or tuples of numbers seqList = [1,2,3,4.5,6.7] self.assertEqual(wx.testArrayIntTypemap(seqList), [1,2,3,4,6]) #floats are truncated to int @@ -24,4 +24,4 @@ class ArrayInt(unittest2.TestCase): if __name__ == '__main__': - unittest2.main() + unittest.main() diff --git a/unittests/test_arraystring.py b/unittests/test_arraystring.py index 02c1addf..46cfdfd5 100644 --- a/unittests/test_arraystring.py +++ b/unittests/test_arraystring.py @@ -1,10 +1,10 @@ -import unittest2 +import imp_unittest, unittest import wx #--------------------------------------------------------------------------- -class ArrayString(unittest2.TestCase): +class ArrayString(unittest.TestCase): if hasattr(wx, 'testArrayStringTypemap'): def test_ArrayStringTypemaps(self): @@ -28,4 +28,4 @@ class ArrayString(unittest2.TestCase): if __name__ == '__main__': - unittest2.main() + unittest.main() diff --git a/unittests/test_bitmap.py b/unittests/test_bitmap.py new file mode 100644 index 00000000..97045200 --- /dev/null +++ b/unittests/test_bitmap.py @@ -0,0 +1,70 @@ +import imp_unittest, unittest +import wtc +import wx +import os + +pngFile = os.path.join(os.path.dirname(__file__), 'toucan.png') + +#--------------------------------------------------------------------------- + +class BitmapTests(wtc.WidgetTestCase): + + def test_BitmapCtors(self): + b1 = wx.Bitmap() + self.assertTrue( not b1.IsOk() ) + b2 = wx.Bitmap(5, 10, 32) + self.assertTrue( b2.IsOk() ) + b3 = wx.Bitmap(wx.Size(5,10), 32) + self.assertTrue( b3.IsOk() ) + b4 = wx.Bitmap((5,10), 32) + self.assertTrue( b4.IsOk() ) + b5 = wx.Bitmap(pngFile) + self.assertTrue( b5.IsOk() ) + img = wx.Image(pngFile) + b6 = wx.Bitmap(img) + self.assertTrue( b6.IsOk() ) + + + def test_Bitmap__nonzero__(self): + b1 = wx.Bitmap() + self.assertTrue( not b1.IsOk() ) + b2 = wx.Bitmap(5, 10, 24) + self.assertTrue( b2.IsOk() ) + self.assertTrue( b2.__nonzero__() == b2.IsOk() ) + + # check that the __nonzero__ method can be used with if satements + nzcheck = False + if b2: + nzcheck = True + self.assertTrue(nzcheck) + nzcheck = False + if not b1: + nzcheck = True + self.assertTrue(nzcheck) + + + def test_BitmapNullBitmap(self): + # just make sure this one exists + wx.NullBitmap + self.assertTrue(not wx.NullBitmap.IsOk()) + + + def test_BitmapSetMaskColour(self): + b5 = wx.Bitmap(pngFile) + b5.SetMaskColour(wx.Colour(1,2,3)) + b5.SetMaskColour('black') + + + def test_BitmapMask(self): + b5 = wx.Bitmap(pngFile) + m = wx.Mask() + m = wx.Mask(b5, 4) + m = wx.Mask(b5) + m = wx.Mask(b5, wx.Colour(1,2,3)) + + +#--------------------------------------------------------------------------- + + +if __name__ == '__main__': + unittest.main() diff --git a/unittests/test_bmpbuttn.py b/unittests/test_bmpbuttn.py new file mode 100644 index 00000000..247e2bd8 --- /dev/null +++ b/unittests/test_bmpbuttn.py @@ -0,0 +1,28 @@ +import imp_unittest, unittest +import wtc +import wx +import os + +pngFile = os.path.join(os.path.dirname(__file__), 'toucan.png') + +#--------------------------------------------------------------------------- + +class BitmapButtonTests(wtc.WidgetTestCase): + + def test_BitmapButtonCtor(self): + bmp = wx.Bitmap(pngFile) + btn = wx.BitmapButton(self.frame, -1, bmp) + + + def test_BitmapButtonDefaultCtor(self): + bmp = wx.Bitmap(pngFile) + btn = wx.BitmapButton() + btn.Create(self.frame, -1, bmp) + + + +#--------------------------------------------------------------------------- + + +if __name__ == '__main__': + unittest.main() diff --git a/unittests/test_brush.py b/unittests/test_brush.py new file mode 100644 index 00000000..1ba9639b --- /dev/null +++ b/unittests/test_brush.py @@ -0,0 +1,36 @@ +import imp_unittest, unittest +import wtc +import wx +import os + +pngFile = os.path.join(os.path.dirname(__file__), 'toucan.png') + +#--------------------------------------------------------------------------- + +class BrushTests(wtc.WidgetTestCase): + + def test_BrushCtors(self): + b = wx.Brush() + b = wx.Brush(wx.Colour(1,2,3), wx.BRUSHSTYLE_SOLID) + bmp = wx.Bitmap(pngFile) + b = wx.Brush(bmp) + copy = wx.Brush(b) + + + def test_BrushOperators(self): + b1 = wx.Brush(wx.Colour(1,2,3), wx.BRUSHSTYLE_SOLID) + b2 = wx.Brush(wx.Colour(1,2,3), wx.BRUSHSTYLE_SOLID) + b3 = wx.Brush(wx.Colour(4,5,6), wx.BRUSHSTYLE_SOLID) + + self.assertTrue(b1 == b2) + self.assertTrue(b2 != b3) + self.assertFalse(b1 != b2) + self.assertFalse(b2 == b3) + + + +#--------------------------------------------------------------------------- + + +if __name__ == '__main__': + unittest.main() diff --git a/unittests/test_button.py b/unittests/test_button.py new file mode 100644 index 00000000..5b95cdb7 --- /dev/null +++ b/unittests/test_button.py @@ -0,0 +1,43 @@ +import imp_unittest, unittest +import wtc +import wx +import os + +pngFile = os.path.join(os.path.dirname(__file__), 'toucan.png') + +#--------------------------------------------------------------------------- + +class ButtonTests(wtc.WidgetTestCase): + + def test_ButtonCtors(self): + btn = wx.Button(self.frame, label='label') + btn = wx.Button(self.frame, -1, 'label', (10,10), (100,-1), wx.BU_LEFT) + bmp = wx.Bitmap(pngFile) + btn.SetBitmap(bmp) + + def test_ButtonProperties(self): + btn = wx.Button(self.frame, label='label') + + # do the properties exist? + btn.AuthNeeded + btn.Bitmap + btn.BitmapCurrent + btn.BitmapDisabled + btn.BitmapFocus + btn.BitmapLabel + btn.BitmapMargins + btn.BitmapPressed + btn.Label + + + def test_ButtonDefaultCtor(self): + btn = wx.Button() + btn.Create(self.frame, -1, 'button label') + + + +#--------------------------------------------------------------------------- + + +if __name__ == '__main__': + unittest.main() diff --git a/unittests/test_choice.py b/unittests/test_choice.py new file mode 100644 index 00000000..aeaf42db --- /dev/null +++ b/unittests/test_choice.py @@ -0,0 +1,37 @@ +import imp_unittest, unittest +import wtc +import wx + +#--------------------------------------------------------------------------- + +class ChoiceTests(wtc.WidgetTestCase): + + def test_ChoiceCtors(self): + c = wx.Choice(self.frame, choices="one two three four".split()) + c = wx.Choice(self.frame, -1, wx.Point(10,10), wx.Size(80,-1), + "one two three four".split(), 0) + c = wx.Choice(self.frame, -1, (10,10), (80,-1), "one two three four".split(), 0) + + self.assertTrue(c.GetCount() == 4) + + + def test_ChoiceDefaultCtor(self): + c = wx.Choice() + c.Create(self.frame, choices="one two three four".split()) + + + def test_ChoiceProperties(self): + c = wx.Choice(self.frame, choices="one two three four".split()) + + # do the properties exist? + c.Columns + c.Count + c.CurrentSelection + c.Selection + + +#--------------------------------------------------------------------------- + + +if __name__ == '__main__': + unittest.main() diff --git a/unittests/test_collpane.py b/unittests/test_collpane.py new file mode 100644 index 00000000..d71618e2 --- /dev/null +++ b/unittests/test_collpane.py @@ -0,0 +1,35 @@ +import imp_unittest, unittest +import wtc +import wx + +#--------------------------------------------------------------------------- + +class CollapsiblePaneTests(wtc.WidgetTestCase): + + def test_CollPaneCtors(self): + c = wx.CollapsiblePane(self.frame, label='label') + c = wx.CollapsiblePane(self.frame, -1, 'label', (12, 34), (45, 67)) + + c.Collapse() + c.Expand() + c.IsCollapsed() + c.IsExpanded() + + + def test_CollPaneDefaultCtor(self): + c = wx.CollapsiblePane() + c.Create(self.frame) + + + def test_CollPaneProperties(self): + c = wx.CollapsiblePane(self.frame) + + # do the properties exist? + c.Pane + + +#--------------------------------------------------------------------------- + + +if __name__ == '__main__': + unittest.main() diff --git a/unittests/test_colour.py b/unittests/test_colour.py index acdb2365..88452112 100644 --- a/unittests/test_colour.py +++ b/unittests/test_colour.py @@ -1,10 +1,10 @@ -import unittest2 +import imp_unittest, unittest import wx #--------------------------------------------------------------------------- -class Colour(unittest2.TestCase): +class Colour(unittest.TestCase): def setUp(self): if hasattr(wx, 'InitializeStockLists'): wx.InitializeStockLists() # switch to wx.App once we have that class working @@ -52,4 +52,4 @@ class Colour(unittest2.TestCase): if __name__ == '__main__': - unittest2.main() + unittest.main() diff --git a/unittests/test_event.py b/unittests/test_event.py index b29e3726..5624ca73 100644 --- a/unittests/test_event.py +++ b/unittests/test_event.py @@ -1,10 +1,10 @@ -import unittest2 +import imp_unittest, unittest import wx #--------------------------------------------------------------------------- -class Events(unittest2.TestCase): +class Events(unittest.TestCase): # Test the constructors to make sure the classes are not abstract, except # for wx.Event @@ -144,4 +144,4 @@ class Events(unittest2.TestCase): if __name__ == '__main__': - unittest2.main() + unittest.main() diff --git a/unittests/test_gdicmn.py b/unittests/test_gdicmn.py index 5fe42f3b..293fd338 100644 --- a/unittests/test_gdicmn.py +++ b/unittests/test_gdicmn.py @@ -1,10 +1,10 @@ -import unittest2 +import imp_unittest, unittest import wx #--------------------------------------------------------------------------- -class Point(unittest2.TestCase): +class Point(unittest.TestCase): def test_default_ctor(self): p = wx.Point() @@ -86,7 +86,7 @@ class Point(unittest2.TestCase): #--------------------------------------------------------------------------- -class Size(unittest2.TestCase): +class Size(unittest.TestCase): def test_default_ctor(self): s = wx.Size() @@ -203,7 +203,7 @@ class Size(unittest2.TestCase): #--------------------------------------------------------------------------- -class RealPoint(unittest2.TestCase): +class RealPoint(unittest.TestCase): def test_default_ctor(self): p = wx.RealPoint() @@ -228,7 +228,7 @@ class RealPoint(unittest2.TestCase): #--------------------------------------------------------------------------- -class Rect(unittest2.TestCase): +class Rect(unittest.TestCase): def test_default_ctor(self): r = wx.Rect() @@ -272,4 +272,4 @@ class Rect(unittest2.TestCase): if __name__ == '__main__': - unittest2.main() + unittest.main() diff --git a/unittests/test_geometry.py b/unittests/test_geometry.py index 545a5ae2..42c083fa 100644 --- a/unittests/test_geometry.py +++ b/unittests/test_geometry.py @@ -1,10 +1,10 @@ -import unittest2 +import imp_unittest, unittest import wx #--------------------------------------------------------------------------- -class Point2D(unittest2.TestCase): +class Point2D(unittest.TestCase): def test_default_ctor(self): p = wx.Point2D() @@ -21,7 +21,7 @@ class Point2D(unittest2.TestCase): -class Rect2D(unittest2.TestCase): +class Rect2D(unittest.TestCase): def test_default_ctor(self): r = wx.Rect2D() @@ -42,5 +42,5 @@ class Rect2D(unittest2.TestCase): if __name__ == '__main__': - unittest2.main() + unittest.main() \ No newline at end of file diff --git a/unittests/test_mousestate.py b/unittests/test_mousestate.py index 9c9bb449..11c7e60c 100644 --- a/unittests/test_mousestate.py +++ b/unittests/test_mousestate.py @@ -1,9 +1,9 @@ -import unittest2 +import imp_unittest, unittest import wx #--------------------------------------------------------------------------- -class MouseState(unittest2.TestCase): +class MouseState(unittest.TestCase): def test_MouseState(self): ms = wx.MouseState() @@ -28,4 +28,4 @@ class MouseState(unittest2.TestCase): if __name__ == '__main__': - unittest2.main() + unittest.main() diff --git a/unittests/test_pyevent.py b/unittests/test_pyevent.py index 10f2907c..ce85d1df 100644 --- a/unittests/test_pyevent.py +++ b/unittests/test_pyevent.py @@ -1,11 +1,11 @@ import sys -import unittest2 +import imp_unittest, unittest import wx ##import os; print 'PID:', os.getpid(); raw_input('Ready to start, press enter...') #--------------------------------------------------------------------------- -class PyEvents(unittest2.TestCase): +class PyEvents(unittest.TestCase): def test_PyEvent(self): id = wx.NewId() @@ -97,4 +97,4 @@ class PyEvents(unittest2.TestCase): if __name__ == '__main__': - unittest2.main() + unittest.main() diff --git a/unittests/test_string.py b/unittests/test_string.py index 6c58bd8d..6c1ab4af 100644 --- a/unittests/test_string.py +++ b/unittests/test_string.py @@ -1,10 +1,10 @@ -import unittest2 +import imp_unittest, unittest import wx #--------------------------------------------------------------------------- -class String(unittest2.TestCase): +class String(unittest.TestCase): if hasattr(wx, 'testStringTypemap'): def test_StringTypemaps(self): @@ -59,4 +59,4 @@ class String(unittest2.TestCase): if __name__ == '__main__': - unittest2.main() + unittest.main() diff --git a/unittests/test_window.py b/unittests/test_window.py new file mode 100644 index 00000000..86afd01a --- /dev/null +++ b/unittests/test_window.py @@ -0,0 +1,84 @@ +import imp_unittest, unittest +import wtc +import wx + +#--------------------------------------------------------------------------- + +class WindowTests(wtc.WidgetTestCase): + + def test_SimpleWindowCtor(self): + w = wx.Window(self.frame, -1, (10,10), (50,50), + wx.BORDER_SIMPLE|wx.VSCROLL) + self.assertTrue(w.GetWindowStyle() == wx.BORDER_SIMPLE|wx.VSCROLL) + self.assertTrue(w.Parent is self.frame) + + # Just test that these properties exist for now. More tests can be + # added later to ensure that they work correctly. + w.AcceleratorTable + w.AutoLayout + w.BackgroundColour + w.BackgroundStyle + w.EffectiveMinSize + w.BestSize + w.BestVirtualSize + w.Border + w.Caret + w.CharHeight + w.CharWidth + w.Children + w.ClientAreaOrigin + w.ClientRect + w.ClientSize + w.Constraints + w.ContainingSizer + w.Cursor + w.DefaultAttributes + w.DropTarget + w.EventHandler + w.ExtraStyle + w.Font + w.ForegroundColour + w.GrandParent + w.TopLevelParent + w.Handle + w.HelpText + w.Id + w.Label + w.LayoutDirection + w.MaxHeight + w.MaxSize + w.MaxWidth + w.MinHeight + w.MinSize + w.MinWidth + w.Name + w.Parent + w.Position + w.Rect + w.ScreenPosition + w.ScreenRect + w.Size + w.Sizer + w.ThemeEnabled + w.ToolTip + w.UpdateClientRect + w.UpdateRegion + w.Validator + w.VirtualSize + w.WindowStyle + w.WindowStyleFlag + w.WindowVariant + w.Shown + w.Enabled + w.TopLevel + w.MinClientSize + w.MaxClientSize + + + + +#--------------------------------------------------------------------------- + + +if __name__ == '__main__': + unittest.main() diff --git a/unittests/test_windowid.py b/unittests/test_windowid.py new file mode 100644 index 00000000..203df9eb --- /dev/null +++ b/unittests/test_windowid.py @@ -0,0 +1,21 @@ +import imp_unittest, unittest +import wx + + +#--------------------------------------------------------------------------- + +class IdManagerTest(unittest.TestCase): + + def test_idManager(self): + id = wx.IdManager.ReserveId(5) + self.assertTrue(id != wx.ID_NONE) + + wx.IdManager.UnreserveId(id, 5) + + + +#--------------------------------------------------------------------------- + + +if __name__ == '__main__': + unittest.main() diff --git a/unittests/test_windowlist.py b/unittests/test_windowlist.py index f7d1a0c4..6decbc7d 100644 --- a/unittests/test_windowlist.py +++ b/unittests/test_windowlist.py @@ -1,11 +1,11 @@ import sys -import unittest2 +import imp_unittest, unittest import wx ##import os; print 'PID:', os.getpid(); raw_input('Ready to start, press enter...') #--------------------------------------------------------------------------- -class WindowList(unittest2.TestCase): +class WindowList(unittest.TestCase): def setUp(self): self.app = wx.App() self.frames = list() @@ -44,4 +44,4 @@ class WindowList(unittest2.TestCase): if __name__ == '__main__': - unittest2.main() + unittest.main() diff --git a/unittests/toucan.png b/unittests/toucan.png new file mode 100644 index 00000000..8a33e241 Binary files /dev/null and b/unittests/toucan.png differ diff --git a/unittests/wtc.py b/unittests/wtc.py new file mode 100644 index 00000000..1a2faf7b --- /dev/null +++ b/unittests/wtc.py @@ -0,0 +1,25 @@ +import imp_unittest, unittest +import wx + +#--------------------------------------------------------------------------- + +class WidgetTestCase(unittest.TestCase): + """ + A testcase that will create an app and frame for various widget test + modules to use. They can inherit from this class to save some work. This + is also good for test cases that need to have an application object + created. + """ + def setUp(self): + self.app = wx.App() + self.frame = wx.Frame(None, title='WTC: '+self.__class__.__name__) + self.frame.Show() + + def tearDown(self): + wx.CallAfter(self.frame.Close) + self.app.MainLoop() + del self.app + +#--------------------------------------------------------------------------- + +