I've just repackaged my program. Previously all modules lived under the "whyteboard" package, with a "fakewidgets" package containing a bunch of dummy GUI test objects.
Now, all my modules are in packages, e.g. whyteboard.gui, whyteboard.misc, whyteboard.test - which is where fakewidgets now lives.
Now, when running my tests, I get an exception,
File "/home/steve/Documents/whyteboard/whyteboard/gui/canvas.py", line 77, in __init__
wx.ScrolledWindow.__init__(self, tab, style=wx.NO_FULL_REPAINT_ON_RESIZE | wx.CLIP_CHILDREN)
TypeError: unbound method __init__() must be called with ScrolledWindow instance as first argument (got Canvas instance instead)
here's the class in question
class Canvas(wx.ScrolledWindow):
def __init__(self, tab, gui, area):
wx.ScrolledWindow.__init__(self, tab, style=wx.NO_FULL_REPAINT_ON_RESIZE | wx.CLIP_CHILDREN)
However, my program loads and runs correctly, except from unit tests. The code is the same, just the code for my tests' imports are different to pull in from the new packages.
Before:
import os
import wx
import fakewidgets
import gui
import lib.mock as mock
from canvas import Canvas, RIGHT, DIAGONAL, BOTTOM
from fakewidgets.core import Bitmap, Event, Colour
from lib.configobj import ConfigObj
from lib.pubsub import pub
from lib.validate import Validator
now:
import os
import wx
import whyteboard.test
import whyteboard.gui.frame as gui
from whyteboard.lib import ConfigObj, mock, pub, Validator
from whyteboard.gui.canvas import Canvas, RIGHT, DIAGONAL, BOTTOM
from whyteboard.test.fakewidgets.core import Bitmap, Event, Colour, PySimpleApp
It may be worth noting that the fakewidgets package does some trickery into make my program think it's using wxPython classes, even though they're mocks.
This is from a module that's imported by whyteboard.test.fakewidgets' __init__
class Window(object):
def __init__(self, parent, *args, **kwds):
self.parent = parent
self.Enabled = True
self.calls = []
self.size = (0, 0)
self.captured = False
def GetClientSizeTuple(self):
return (0, 0)
self.captured = True
def GetId(self):
pass
def Fit(self):
pass
def SetFocus(self):
pass
def PrepareDC(self, dc):
pass
def Destroy(self):
pass
...
class ScrolledWindow(Window):
def SetVirtualSize(self, *size):
pass
def SetVirtualSizeHints(self, *size):
pass
import wx
wx.__dict__.update(locals())