The Python Papers Anthology
Not a member yet
207 research outputs found
Sort by
Doctest and unittest... now they'll be merrily together
Testing is a very important discipline to ensure and validate software quality. Python includes two standard modules to perform functional testing. Prior to version 2.4 both tools were unrelated, leading to scattered testing code. From this version on a unittest API is provided by doctest. The present work aims to propose some enhancements to this API in order to achieve a better unittest-doctest integration. Although there are more complex testing tools (e.g. nose) which allow performing both kinds of tests, they are outside the scope of this article. Firstly, they are not standard modules. Besides, the intent is to load and execute doctests just like if we were using unittest.Even though many types of tests exist these days1, functional testing is very important. Firstly, it validates whether software behavior matches the business rules documented in the software requirements. Besides, for continuously evolving systems and iterative development processes it is also crucial to perform regression testing. Thereby introduced defects are handled as soon as possible and the defect does not propagate to future versions. These tests are also the main building block for test-driven development and extreme programming techniques. A scripting language like Python ought to be aware of this since it is often used to write test scripts (e.g. for Java2 and .NET3). Because of this, the paper also covers the standard modules available nowadays in Python for functional testing
Automatic C Library Wrapping -- Ctypes from the Trenches
At some point of time many Python developers -- at least in computational science -- will face the situation that they want to interface some natively compiled library from Python. For binding native code to Python by now a larger variety of tools and technologies are available. This paper focuses on wrapping shared C libraries, using Python's default Ctypes. Particularly tools to ease the process (by using code generation) and some best practises will be stressed. The paper will try to tell a ``step--by--step'' story of the wrapping and development process, that should be transferable to similar problems
ctypes. ctypes run!
One of the new features of Python 2.5 is the introduction of ctypes as a standard library module. At the simplest level, ctypes adds the standard C types to Python: signed and unsigned bytes, shorts, ints and longs; as well as structs, unions, pointers and functions. At run-time it can load a shared library (DLL) and import its symbols, allowing a Python application to make function calls into the library without any special preparation. ctypes can be used to wrap native libraries in place of interface generators such as SWIG, to manipulate memory and Python objects at the lowest level, and to prototype application development in other languages.This paper begins with a quick introduction to ctypes, shows some advanced techniques, and describes some examples of how it has been used by the author in his recent work