Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with i18n , gettext and the "_" function #393

Open
jpellerin opened this issue Dec 14, 2011 · 5 comments
Open

Problems with i18n , gettext and the "_" function #393

jpellerin opened this issue Dec 14, 2011 · 5 comments
Assignees

Comments

@jpellerin
Copy link
Member

What steps will reproduce the problem?

  1. Download w3af's source code
  2. Run nosetests --rednose --with-doctest --doctest-tests -e 'extlib.*'

What is the expected output? What do you see instead?
I expect nose to run the different modules and show the tests that failed, instead I'm getting:


  1. ERROR: Failure: NameError (name '_' is not defined)

Traceback (most recent call last):
/usr/lib/python2.5/site-packages/nose-0.11.3-py2.5.egg/nose/loader.py line 382 in loadTestsFromName
addr.filename, addr.module)
/usr/lib/python2.5/site-packages/nose-0.11.3-py2.5.egg/nose/importer.py line 39 in importFromPath
return self.importFromDir(dir_path, fqname)
/usr/lib/python2.5/site-packages/nose-0.11.3-py2.5.egg/nose/importer.py line 86 in importFromDir
mod = load_module(part_fqname, fh, filename, desc)
core/ui/gtkUi/reqResViewer.py line 43 in
from .export_request import export_request
core/ui/gtkUi/export_request.py line 25 in
from .encdec import SimpleTextView
core/ui/gtkUi/encdec.py line 502 in
(("URL Encode"), urlencode),
NameError: name '
' is not defined

These errors are generated because my tool has some i18n features. These features are added with the gettext module. This module adds the "_" function to globals when I run this in the init script:

Translation stuff

gettext.install('w3af', 'locales/')

The "_" is defined at runtime, and nose is not being able to handle that.

What version of the product are you using? On what operating system?
Latest version, with the rednose plugin installed.
Ubuntu 8.04.
Python 2.5.2

Please provide any additional information below.
Feel free to contact me via email (andres.riancho !at! gmail . com)

Google Code Info:
Issue #: 373
Author: andres.riancho@gmail.com
Created On: 2010-11-09T15:09:22.000Z
Closed On:

@jpellerin
Copy link
Member Author

Extra note: We don't need a final solution, a workaround could be enough for now :)

Google Code Info:
Author: andres.riancho@gmail.com
Created On: 2010-11-09T15:13:46.000Z

@ghost ghost assigned jpellerin Dec 14, 2011
@jpellerin
Copy link
Member Author

Any comments about this issue?

Google Code Info:
Author: andres.riancho@gmail.com
Created On: 2010-11-12T23:18:20.000Z

@jpellerin
Copy link
Member Author

Fixed by adding this code to the "init.py" file of the package that was raising all those errors:

"""

Intended to be called by nose.

def setUpPackage():
# Hack to init i18n function
import builtins
builtins.dict['_'] = lambda x: x
"""

Google Code Info:
Author: andres.riancho@gmail.com
Created On: 2010-11-30T17:13:42.000Z

@jpellerin
Copy link
Member Author

Andres, your fix did not work for me. First, there is a typo... it's builtin, not builtins, but even after making that fix, I still get the same NameError: name '_' is not defined message when running nosetests.

Any thoughts or ideas?

Google Code Info:
Author: jaypi...@gmail.com
Created On: 2010-12-10T16:24:00.000Z

@jpellerin
Copy link
Member Author

Following up, I was able to get nosetests to work using the following in a /tests/init.py file where tests/ contains all the test case files.

My project is structured like so:

/src
/project
/tests

Putting the below code in /src/project/init.py did not work, however putting it in /src/tests/init.py did work...

import builtin
setattr(builtin, '_', lambda x: x)

If I put the above inside a setup or setUpProject function, it does NOT work.

Just a heads up.

Cheers,
jay

Google Code Info:
Author: jaypi...@gmail.com
Created On: 2010-12-10T16:55:44.000Z

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant