Opened 6 years ago

Closed 6 years ago

#26232 closed Bug (fixed)

i18n unit test fails on xgettext in /usr/local/bin

Reported by: Jeroen Pulles Owned by: nobody
Component: Internationalization Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The test_compilation unit test sets a very minimalist environment so that the unit test fails to find xgettext in /usr/local/bin (homebrew on mac, anyone?).

======================================================================               [51/291]
ERROR: test_msgfmt_error_including_non_ascii (i18n.test_compilation.CompilationErrorHandling$
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.
5/unittest/case.py", line 58, in testPartExecutor
    yield
  File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.
5/unittest/case.py", line 600, in run
    testMethod()
  File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.
5/unittest/mock.py", line 1157, in patched
    return func(*args, **keywargs)
  File "/Users/jeroenp/projects/django/tests/i18n/test_compilation.py", line 184, in test_msg
fmt_error_including_non_ascii
    if cmd.gettext_version < (0, 18, 3):

....[snip]

  File "/Users/jeroenp/projects/django/django/core/management/utils.py", line 21, in popen_wr
apper
    p = Popen(args, shell=False, stdout=PIPE, stderr=PIPE, close_fds=os.name != 'nt')
  File "/Users/jeroenp/projects/django/tests/i18n/test_compilation.py", line 171, in <lambda>
    lambda *args, **kwargs: Popen(*args, env={'LANG': 'C'}, **kwargs))
  File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.
5/subprocess.py", line 950, in __init__
    restore_signals, start_new_session)
  File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.
5/subprocess.py", line 1544, in _execute_child
   raise child_exception_type(errno_num, err_msg)
django.core.management.base.CommandError: Error executing xgettext: No such file or directory
: 'xgettext'

----------------------------------------------------------------------
Ran 10518 tests in 97.610s

Verifying with a stripped environment in a shell:

(django-env-py3) tests$ env -i LANG=C xgettext
env: xgettext: No such file or directory
(django-env-py3) tests$ which xgettext
/usr/local/bin/xgettext
(django-env-py3) tests$ env -i LANG=C  PATH=/usr/local/bin:/usr/bin:/bin xgettext
xgettext: no input file given
Try 'xgettext --help' for more information.

Adding a hardcoded PATH to the env argument to Popen in test_compilation.py fixes this, but I'm assuming that's not the way to go forward.

See #25925

Change History (8)

comment:1 Changed 6 years ago by Tim Graham

Component: Testing frameworkInternationalization
Triage Stage: UnreviewedAccepted

I guess something like 1d9fc5caa947ff4ee72180185e91a9a145171712 might work (with PATH instead of PYTHONPATH). Can you try to develop a patch that works for you?

comment:2 Changed 6 years ago by Claude Paroz

The fix for #25925 was maybe not the best one. We may have copy os.environ and only override the LANG key.

comment:3 Changed 6 years ago by Jeroen Pulles

I'm new to Django development, so I have no idea what the design ideas around its testing framework are. That said, I was wondering if it doesn't make more sense to set LC_ALL, LC_NUMERIC, LC_COLLATE, ..., for all unit tests; Might help with consistently testing things that are locale-dependent, such as string formatting and sorting.

comment:4 Changed 6 years ago by Claude Paroz

Has patch: set

Jeroen, could you test this PR ?

comment:5 Changed 6 years ago by Tim Graham

Triage Stage: AcceptedReady for checkin

Haven't tested myself, but the approach looks good.

comment:6 Changed 6 years ago by Jeroen Pulles

Sure, works for me.

It might break the original #25925 since you're not un-setting any of the other LC environment variables.

comment:7 Changed 6 years ago by Claude Paroz

Thanks for testing. I'm not sure it might break #25925, as what we are interested to change is the language of gettext messages and I'm pretty convinced that LANG will do the job for that.

comment:8 Changed 6 years ago by Claude Paroz <claude@…>

Resolution: fixed
Status: newclosed

In eda306f1:

Fixed #26232 -- Fixed Popen mocking environment in i18n tests

Refs #25925. Thanks Jeroen Pulles for the report.

Note: See TracTickets for help on using tickets.
Back to Top