Translate Toolkit & Pootle

Tools to help you make your software local

User Tools


Testing

Our aim is that all new functionality is adequately tested.

Translate Toolkit

We use py.test for unit testing. You need at least py.test >= 1.0.0

To run the all tests in the current directory and its subdirectories.

py.test

to run tests in a specific test file.

py.test storage/test_dtd.py

py.test functionality that we use

We use some of the py.test plugins for simplify testing

recwarn

The recwarn plugin allows us to test for Warnings.

recwarn is a funcargs plugins which means that you need it in your test function parameters.

def test_example(recwarn):
    # do something
    w = recwarn.pop()
    # w.{message,category,filename,lineno}
    assert 'something' in str(w.message)

To test for DeprecationWarning it is even simpler:

from py.test import deprecated_call
 
def test_something():
    deprecated_call(function_to_run, arguments_for_function)

Will check that a function that we run raises a DeprecationWarning

xfail

The xfail decorator is part of the skipping plugin. xfail allows us to run tests that we expect to fail.

This allows you to do the following:

  • Build tests for functionality that we haven't implemented yet
  • Mark tests that will fail on certain platforms or Python versions
  • Mark out tests that we want to fix but haven't got round to fixing yet

The simplest form is the following:

@py.test.mark.xfail
def test_function():
    ...

You can also pass the following parameters:

  • xfail(“sys.version_info >= (3,0)”) - skip the test if certain condition is met.
  • xfail(…, run=False) - don't run the test but still regard it as xfailed
  • xfail(…, reason=“my reason”) - provide a reason for the xfail.

Pootle

Run tests with Pootle 2.x this way:

./manage.py  test  pootle_store pootle_app

Some of the other Django applications also have tests, but don't run in our default setup, so it is probably best to ignore them for now. If you use Django 1.2, the tests should run out of the box, as long as you don't use database cache but rather in-memory cache or memcached. With older versions of Django, disable the page following middleware in pootle/settings.py:

  • django.contrib.csrf.middleware.CsrfMiddleware
  • django.middleware.cache.UpdateCacheMiddleware
  • django.middleware.cache.FetchFromCacheMiddleware