# HG changeset patch # User Thomas De Schampheleire # Date 1479671500 -3600 # Node ID 6a9f8269675079c55fd847c894d859f142065500 # Parent 70d3a838a9f423fe702fb3c374ad4db857c5c320 tests: introduce test_context to handle internationalization As preparation to the migration to Turbogears2, introduce a test_context context manager to wrap certain tests. The context manager provides a translator for tests that need it. This translator was previously provided globally to all tests via the TestController. When swapping Pylons with Turbogears2, the new file kallithea/tests/test_context.py can be removed, and the test_context from tg2/tg/util/webtest.py should be used. diff -r 70d3a838a9f4 -r 6a9f82696750 kallithea/tests/test_context.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kallithea/tests/test_context.py Sun Nov 20 20:51:40 2016 +0100 @@ -0,0 +1,18 @@ +# Based on Turbogears2 2.3.8: util/webtest.py but almost entirely stripped +# and translator bits added. + +import pylons +from pylons.i18n.translation import _get_translator + +class test_context(object): + def __init__(self, app): + self._app = app + + def __enter__(self): + # Initialize a translator for tests that utilize i18n + translator = _get_translator(pylons.config.get('lang')) + pylons.translator._push_object(translator) + return self._app + + def __exit__(self, exc_type, exc_val, exc_tb): + pylons.translator._pop_object()