Using wxPython data classes without a GUI?

I like to keep my data processing and my GUI separate to make it easier to test the processing.

For example, I tried creating a wx.RichTextBuffer without a GUI and it didn’t work. (I created a wx.App(), and it still didn’t work.) Is it possible to load and save wx richtext XML without a GUI?

Is it possible to create a wx.dataview.DataViewModel or a wx.grid.GridTableBase without a GUI, again for the purposes of testing?

In most cases wxWidgets assumes that there is a wxApp object, an event loop, and etc. so it is hard to say what will work without a GUI and what won’t. For certain groups of classes I ensure that there is a wx.App and raise an exception from the constructor if there isn’t, (windows, gdi objects, bitmaps, etc.)

In what way did the RichTextBuffer experiment not work?

As I described in another post:

import wx.richtext
import wx

def main():
    app = wx.App()
    buf = wx.richtext.RichTextBuffer()
    ok = buf.LoadFile('/tmp/q.html', type=wx.richtext.RICHTEXT_TYPE_HTML)
    print(f'load q {ok}')
    ok = buf.SaveFile('/tmp/q.xml', type=wx.richtext.RICHTEXT_TYPE_XML)
    print(f'save q {ok}')
    del buf
    buf = wx.richtext.RichTextBuffer()
    ok = buf.LoadFile('/tmp/d.html', type=wx.richtext.RICHTEXT_TYPE_HTML)
    print(f'load d {ok}')
    ok = buf.SaveFile('/tmp/d.xml', type=wx.richtext.RICHTEXT_TYPE_XML)
    print(f'save d {ok}')

if __name__ == '__main__':
    main()

This just prints False four times. so the load file doesn’t work. But /tmp/q.html and /tmp/d.html are both present and both appear correctly in a web browser.