I just realized I can run arbitrary Python scripts through calibre-debug, which is finally allowing me to start writing some proper tests. There's a couple things I'm wondering about though. I'll be running everything on a Linux machine which I hope makes it all easier.
- Is there some way I can tell calibre-debug to add extra paths to sys.path? Or do I need to append to sys.path in my Python unittest scripts? To mock objects in Python 2 I need to include extra ZIP files in sys.path and calibre-debug doesn't respect PYTHONPATH.
- Is there a way I can change the language and encoding calibre uses? I need to run at least some tests using different languages and encodings, I run en_CA.UTF-8 but I want to also run tests in other languages (at least one with accented characters and one with a non-Latin alphabet, like Russian or Arabic) and encodings (US-ASCII, CP1252, possibly others).
- Related to the above, is there a way I can tell calibre-debug to use a different location for its config and library directories for tests so I don't risk breaking my current configs and library by having calibre rapidly swap languages and encodings? Is it enough to set XDG_CONFIG_HOME to a temporary location and write out a minimal global.py.json setting library_path to a temporary directory?
- Is there a way to tell calibre to load local versions of my plugin ZIPs instead of the ones in my config plugins directory? Does that just need me to write a minimal customize.py.json alongside global.py.json to reference my local build instead?
1) You append to sys.path
2, 3) See the various environment variables calibre uses, including controlling interface language and config directory
https://manual.calibre-ebook.com/customize.html#environment-variables Note that binary builds of calibre from the python 3 betas onward always use UTF-8 regardless of environment variables.
For python 2 calibre things are more complicated, since there python's internal encoding selection mechanics are used.
4) Just create your own empyt config dir and tell calibre to use it via the env var above and then use calibre-customize -b to install your plugin into that config dir.