python-utils is a loose set of modules and packages, that can be easily
dropped into any Python project. They are usually small (code to read),
easy to use and limited in the functionality, they provide.
There is nothing to install. Just copy the files, you want to use, into
your own project.
All code within this project is given to the public domain. There are no
licensing restrictions. Please see *COPYING.txt* for further details.
The following packages are currently available.
A simple test framework based on `unittest`. It supports improved test
behaviour, automated test loading, tagging, randomisation and
parallelised execution of tests.
How to use
You can simply copy it into your main project. It is recommended to keep the
hierarchy as it is, so that you put your unittest files into test/ and keep
all the framework files in test/util. ::
You just need to stick to a single naming rule for files, which have to
end with ``_test.py``. This can be changed in the `gettestfiles()`
function in the *runtests.py* file.
The whole test suite can be executed with a simple module execution: ::
python -m awesomepackage.test.util.runtests
The following modules are currently available.
n-dimensional buffer access classes and ctypes sequence conversion helpers.
Several compatibility helpers to make writing Python code for Python 2.x and
Python 3.x easier without too many if/else gates.
A simple ctypes wrapper class for loading shared libraries.
A simple component-based framework.
System font handling functions.
Resource management methods and classes. This allows you to easily handle
non-Python resource files in your application. The `Resources` class can be
used to scan folders or compressed archives and to access the files within them
without the need to fiddle around with absolute or relative paths.
If you for example intend to ship some content files with your application and
need to access them, just put them into some content-specific folder and access
them via the Resource class. If you want to package all those content files to
save the user some disk space, you can use the ZIP or TAR compression to bundle
them into one or more single files.
Let's assume your application features something like the following
Within Application.exe (which previously might have been application.py,
compiled and packaged via py2exe or something similar), you can define
the resource bundle like ::
apppath = os.path.dirname(os.path.abspath(__file__))
appresources = Resources(os.path.join(apppath, "resources"))
and access your data files like ::
button_image = appresources.get("button.png")
info_file = appresources.get("info.dat")
# Get textfile1.txt from textcontent.zip
textfile1 = appresources.get("textfile1.txt")
Easy, isn't it?