<div dir="ltr">Hi Thomas,<div><br></div><div>did you manage to fix this be replacing "from tg.i18n import ugettext as _" with from "tg.i18n import lazy_ugettext as _" as suggested? I didn't have time to check but that should actually fix the issues you are facing.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 26, 2016 at 9:34 AM, Alessandro Molina <span dir="ltr"><<a href="mailto:alessandro.molina@gmail.com" target="_blank">alessandro.molina@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Reason is kallithea/model/forms.py using _() calls ( from tg.i18n import ugettext as _ )<div>Those translate the text the moment they are called, but as they are used in class attributes they actually get called the moment you import the module.</div><div><br></div><div>As when you import the module there is no request in place TG is unable to get the language that should be used for that request and translate those.</div><div>The proper fix is to use lazy_ugettext in place of ugettext -> <a href="http://turbogears.readthedocs.org/en/latest/reference/classes.html#tg.i18n.lazy_ugettext" target="_blank">http://turbogears.readthedocs.org/en/latest/reference/classes.html#tg.i18n.lazy_ugettext</a></div><div><br></div><div>Probably my fault, I converted most of those global imports using sed, but I have not been wise enough to convert those to the lazy version :)</div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Apr 23, 2016 at 9:51 PM, Thomas De Schampheleire <span dir="ltr"><<a href="mailto:patrickdepinguin@gmail.com" target="_blank">patrickdepinguin@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Alessandro,<br>
<br>
Parking the routes problems to let Søren look into the post/delete<br>
handling, the other thing I have been struggling with for a very long<br>
time is with internationalization in tests.<br>
<br>
I seem to fail to understand how the initialization of Kallithea is<br>
different in the test suite versus in the normal run. In the normal<br>
case, internationalization is set up 'automatically' but with the test<br>
suite it does not seem the case.<br>
Even for the original pylons based test suite, some special actions<br>
are made, for internationalization and for others, which do not seem<br>
necessary in the standard run. Can you elaborate about the cause of<br>
this difference?<br>
<br>
Specifically, a reproduction scenario is:<br>
<br>
- start from the lastly pushed patches in the kallithea-tg repo (7da2b0b701c4)<br>
<br>
- run:<br>
<br>
$ py.test kallithea/tests/functional/test_pullrequests.py<br>
<br>
- result is this:<br>
<br>
No handlers could be found for logger "tg.appwrappers.transaction_manager"<br>
Test session starts (platform: linux2, Python 2.7.10, pytest 2.9.1,<br>
pytest-sugar 0.6.0)<br>
rootdir: /home/tdescham/repo/contrib/kallithea/kallithea-tg, inifile: pytest.ini<br>
plugins: sugar-0.6.0<br>
<br>
――――――――――――――――――――――――――――――――――――――――――――――――――― ERROR collecting<br>
kallithea/tests/functional/test_pullrequests.py<br>
―――――――――――――――――――――――――――――――――――――――――――――――――――<br>
kallithea/tests/functional/test_pullrequests.py:7: in <module><br>
    from kallithea.controllers.pullrequests import PullrequestsController<br>
kallithea/controllers/pullrequests.py:57: in <module><br>
    from kallithea.model.forms import PullRequestForm, PullRequestPostForm<br>
kallithea/model/forms.py:49: in <module><br>
    class LoginForm(formencode.Schema):<br>
kallithea/model/forms.py:57: in LoginForm<br>
    'empty': _('Please enter a login'),<br>
../venv/kallithea-tg/lib/python2.7/site-packages/tg/i18n.py:89: in ugettext<br>
    return tg.translator.ugettext(value)<br>
../venv/kallithea-tg/lib/python2.7/site-packages/tg/support/objectproxy.py:19:<br>
in __getattr__<br>
    return getattr(self._current_obj(), attr)<br>
../venv/kallithea-tg/lib/python2.7/site-packages/tg/request_local.py:178:<br>
in _current_obj<br>
    return getattr(context, <a href="http://self.name" rel="noreferrer" target="_blank">self.name</a>)<br>
../venv/kallithea-tg/lib/python2.7/site-packages/tg/support/objectproxy.py:19:<br>
in __getattr__<br>
    return getattr(self._current_obj(), attr)<br>
../venv/kallithea-tg/lib/python2.7/site-packages/tg/support/registry.py:72:<br>
in _current_obj<br>
    'thread' % self.____name__)<br>
E   TypeError: No object (name: context) has been registered for this thread<br>
<br>
=======================================================================<br>
short test summary info<br>
========================================================================<br>
ERROR kallithea/tests/functional/test_pullrequests.py<br>
<br>
<br>
So, upon executing the imports of the test (not even real test code),<br>
some step uses tg.translator.ugettext() which fails.<br>
<br>
I have been adding gazilions of print statements all over the place<br>
trying to grasping the issue, I tried editing the test.ini file to<br>
explicitly set a language, or even set a language in the test setup<br>
code, but all in vain.<br>
<br>
I hope you could spare some time to help me out here.<br>
(I'm still also very interested in understanding how to debug such<br>
issues in a more clever way than just with print statements.)<br>
<br>
<br>
Thanks again,<br>
Thomas<br>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>