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

Vroom fails when trying to print any non-ASCII content #28

Closed
malcolmr opened this issue Mar 29, 2014 · 2 comments · Fixed by #70
Closed

Vroom fails when trying to print any non-ASCII content #28

malcolmr opened this issue Mar 29, 2014 · 2 comments · Fixed by #70
Labels

Comments

@malcolmr
Copy link
Member

As noted in #25, Vroom currently fails when attempting to print a failure message containing non-ASCII content.

For example, running LANG=de_DE.UTF-8 vroom examples/directives.vroom currently fails because vim returns E605: Ausnahme nicht aufgefangen: I broke something! rather than the message we match against. That's simple to fix, but it suffices to demonstrate the problem:

$ LANG=de_DE.UTF-8 vroom examples/directives.vroom
Traceback (most recent call last):
  File "vroom", line 55, in <module>
    writers.append(runner(f))
  File "vroom/runner.py", line 75, in __call__
    self.Record(vroom.test.RESULT.FAILED, e)
  File "vroom/runner.py", line 111, in Record
    self.env.writer.actions.Log(result, lineno, error)
  File "vroom/output.py", line 324, in Log
    self._Error(result, error, lineno)
  File "vroom/output.py", line 416, in _Error
    QueueContext('messages', ErrorMessageContext)
  File "vroom/output.py", line 414, in QueueContext
    writer(value, self.Queue, *args)
  File "vroom/output.py", line 568, in WriteExtraData
    printer(str(datum))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xdc' in position 0: ordinal not in range(128)

In this case, the message that it's failing to print is actually the message-maintainer text, Übersetzt von Georg Dahn <gorgyd@yahoo.co.uk>, meaning that any test failure breaks vroom.

I've also seen a similar stacktrace in Failures.__str__() in the multiple-failures case.

I spent a short while looking at this yesterday. The core problem is that, from what I can see, in Python 2.x (which I guess we're assuming?) __str__() must return a byte string in an unspecified encoding, which in some cases (i.e. above) becomes ascii. (See this blog post for more detail.)

We're implementing __str__() to print a number of the objects (Failures and Log, for example), and I suspect these should implement __unicode__() instead, and probably leave __str__() effectively unimplemented. (This also means that we'd need to call unicode() instead of str(), and use u'%s' % x rather than '%s' % x.)

The other Failure subclasses already implement a useful __unicode__(), but they have the same problem if you attempt to call __str__(); we probably want to block that as well.

@dbarnett
Copy link
Contributor

dbarnett commented Oct 9, 2014

Similar error for

  :throw '¬'

The error there is:

Traceback (most recent call last):
  File "/usr/bin/vroom", line 7, in <module>
    sys.exit(vroom.__main__.main())
  File "/usr/lib/python2.7/dist-packages/vroom/__main__.py", line 52, in main
    writers.append(runner(f))
  File "/usr/lib/python2.7/dist-packages/vroom/runner.py", line 75, in __call__
    self.Record(vroom.test.RESULT.FAILED, e)
  File "/usr/lib/python2.7/dist-packages/vroom/runner.py", line 111, in Record
    self.env.writer.actions.Log(result, lineno, error)
  File "/usr/lib/python2.7/dist-packages/vroom/output.py", line 324, in Log
    self._Error(result, error, lineno)
  File "/usr/lib/python2.7/dist-packages/vroom/output.py", line 393, in _Error
    self.Queue(str(error))
  File "/usr/lib/python2.7/dist-packages/vroom/test.py", line 96, in __str__
    '\n\n'.join(str(f) for f in flattened_failures))
  File "/usr/lib/python2.7/dist-packages/vroom/test.py", line 96, in <genexpr>
    '\n\n'.join(str(f) for f in flattened_failures))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xac' in position 53: ordinal not in range(128)

@dbarnett
Copy link
Contributor

This and #59 actually work fine in python3. I just sank hours and hours into trying to make it support python2 and python3 seamlessly, but I think we should just bless python 3 and drop python 2 support instead (#67).

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

Successfully merging a pull request may close this issue.

2 participants