Changeset - 6a9f82696750
[Not reviewed]
default
0 0 1
Thomas De Schampheleire - 9 years ago 2016-11-20 20:51:40
thomas.de.schampheleire@gmail.com
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.
1 file changed with 18 insertions and 0 deletions:
0 comments (0 inline, 0 general)
kallithea/tests/test_context.py
Show inline comments
 
new file 100644
 
# 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()
0 comments (0 inline, 0 general)