ulif.openoffice.testing – Helpers for testing

Test helpers.

class ulif.openoffice.testing.ConvertLogCatcher

This log catcher catches the log messages of u.o.convert().

It must be instantiated before any call to u.o.convert.

class ulif.openoffice.testing.FakeServerProxy(url)

An xmlrpclib.ServerProxy for doctests.

Different to normal ServerProxy instances, this one uses a special transport to talk directly to the ulif.openoffice.xmlrpc.WSGIXMLRPCApplication set in xmlrpcapp.

New in version 1.1.

class ulif.openoffice.testing.HTTPWSGIResponse(webob_resp)

A fake httplib-like HTTP response.

Used by WSGILikeHTTP for use by WSGIXMLRPCAppTransport.

New in version 1.1.

class ulif.openoffice.testing.TestOOServerSetup(methodName='runTest')

A setup that starts an OO.org server in background

and shuts it down after tests in the accompanied test suite have been run.

This setup is special in that it detects whether an instance of the openoffice server is already running and in that case uses this instance.

For people running tests does that mean:

  • You can decrease test time (dramatically) by starting oooctl in backgroud before running tests.
  • An already running instance of OO.org server will be still running after tests.
  • Be prepared for slightly different test output when using an already running OO.org server instance.
class ulif.openoffice.testing.TypeAwareStreamHandler(stream=None)

A logging.StreamHandler that turns anything into ‘unicode’.

In tests we want to use StringIO buffers to read log messages (at least until we py.testified everything). As StringIO instances require unicode() instances under Python 2.x and str() instances under Python 3.x we do our best to convert anything before we emit messages. I.e. we decode any string to UTF-8 if possible (and let it pass as-is otherwise).

class ulif.openoffice.testing.WSGILikeHTTP(host, app)

An httplib-like HTTP layer for WSGIXMLRPCAppTransport.

New in version 1.1.

class ulif.openoffice.testing.WSGIXMLRPCAppTransport(app)

A fake HTTP transport.

The given app should be the XMLRPC WSGI app to serve. Usually a ulif.openoffice.xmlrpc.WSGIXMLRPCApplication instance.

Usable by xmlrpclib clients to fake connections to ‘real’ servers like xmlrpclib.SimpleXMLRPCServer instances.

With this transport you can create xmlrpclib.ServerProxy instances that talk directly to the given app instead of doing real network requests.

New in version 1.1.

ulif.openoffice.testing.doctest_rm_resultdir(path)

Remove directory path.

If path is a file, the parent directory is removed.

The directory is only removed, if it is not the current working directory.

ulif.openoffice.testing.doctest_setup()

Set up doctest env.

Creates a temporary working dir and changes to it.

Creates a ‘document.doc’ file in that directory.

ulif.openoffice.testing.doctest_teardown()

Tear down doctest env.

Removes any temporary working directory (if it is different from initial CWD).

ulif.openoffice.testing.envpath_wo_virtualenvs()

Return the local os.environ[“PATH”] without virtual envs included.

Returns a version of os.environ[‘PATH’] with all paths removed, that probably are inside a virtualenv.

These paths are those located in $VIRTUAL_ENV and $VIRTUAL_ENV_BEFORE_TOX. The latter is an enviroment variable set locally by tox (see local tox.ini).

The stripped path is returned.

If PATH is not set and VIRTUAL_ENV is not set, we return None.

This function does not modify environment vars (but looks it up).

New in version 1.2.

ulif.openoffice.testing.xmlrcpapp = None

A WSGIXMLRPCApplication instance for use by FakeServerProxy. Set this var before creating a FakeServerProxy instance and the proxy will send requests to the set application.