Python Programming, news on the Voidspace Python Projects and all things techie.

Released: Mock 0.6.0, Python mocking and testing module

emoticon:new_document mock is a Python mock object library for testing, with additional support for runtime monkey patching.

Most mocking libraries follow the 'record -> replay' pattern of mocking. I prefer the 'action -> assertion' pattern, which is more readable and intuitive; particularly when working with the Python unittest module.

This release, version 0.6.0, is a minor release but with a few new features:

New in 0.6.0:

  • New test layout compatible with test discovery
  • Descriptors (static methods / class methods etc) can now be patched and restored correctly
  • Mocks can raise exceptions when called by setting side_effect to an exception class or instance
  • Mocks that wrap objects will not pass on calls to the underlying object if an explicit return_value is set

Like this post? Digg it or Del.icio.us it.

Posted by Fuzzyman on 2009-08-28 13:47:07 | |

Categories: , Tags: , ,


Two Releases: discover 0.3.0 and rst2xaml 0.1.0 (and a note on PyPI)

emoticon:ir_scope I've just pushed out two small releases, both up on PyPI. These are version 0.3.0 of discover for automatic test discovery of unittest tests and version 0.1.0 of rst2xaml for writing WPF / Silverlight XAML from ReStructured Text documents.

For small projects I'm starting to like using PyPI (the Python Packages Index) as the homepage, with the documentation on the project page itself rather than having a separate webpage. You can now host multiple pages of documentation on PyPI but I haven't tried this yet. Nor can I find any documentation on the feature itself, but it is there as an option when you edit a listing.

It's also great to see Distribute, which is the replacement for setuptools by Tarek Ziade, make progress. I'm actually using on at least a couple of machines now and haven't had any problems so far. The easy_install script from Distribute (yep - same name as the script from setuptools) installs packages direct from PyPI of course - so the package index is becoming an ever more important and useful part of the Python infrastructure.

discover 0.3.0, automatic test discovery for unittest

The discover module is a backport of the automatic test discovery from the unittest module in Python-trunk (what will become Python 2.7 and 3.2).

The discover module should work on versions of Python 2.4 upwards:

The discover module can be used to run all, or a subset, of your unittest based tests automatically from the command line. See the PyPI page for details.

Version 0.3.0 has two new features:

  • Failing to import a file (e.g. due to a syntax error) no longer halts discovery but is reported as an error.
  • Discovery will not attempt to import test files whose names are not valid Python identifiers, even if they match the pattern.

rst2xaml 0.1.0, ReStructuredText to XAML for WPF and Silverlight / Moonlight

rst2xaml is a script and set of libraries for writing out XAML text markup from ReStructured Text (docutils). It includes a Pygments writer to include highlighted sourcecode (for all the myriad languages Pygments supports) in the output.

XAML is the text markup used by Windows Presentation Foundation (WPF) user interfaces, both for the desktop and for Silverlight / Moonlight web applications. It outputs two different varieties of XAML, FlowDocument XAML for WPF and a restricted subset for Silverlight.

rst2xaml itself runs under CPython, but the generated XAML is intended for use from IronPython (or any other .NET language). There is an example IronPython script for displaying the generated XAML using a WPF FlowDocumentReader.

In this 0.1.0 release only a small subset of the ReST markup is supported - although the subset is enough to be useful, hence the release. Both the FlowDocument and Silverlight XAML output support the following features:

  • title and headings
  • paragraphs
  • bold
  • italics
  • literal blocks
  • inline literals
  • line blocks
  • bullet lists
  • enumerated lists
  • blockquotes
  • the raw:: xaml directive
  • the pygments code-block directive

In addition FlowDocument supports superscript, although this only works with fonts that support it.

There are three scripts that come with rst2xaml:

python rst2xaml.py source.txt output.xaml
python rst2xamlsl.py silverlight-source.txt silverlight-output.xaml
ipy.exe display_xaml.py output.xaml

If display_xaml.py is run without a command line argument it will open a file dialog for you to choose a xaml file to display.

The tests use the discover module, which is included in the repository for convenience. You run the tests with:

python discover.py

The google code project page has screenshots showing the XAML output displayed in both WPF and Silverlight. My goal with this project is to have a Python tutorial that can run in the browser with an interactive interpreter. I have enough of the docutils markup to make a start, so the next step is to work on the interpreter and Silverlight document viewer.


Hosted by Webfaction

Counter...