Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

TST: add future unicode_literals test (#786) #790

Merged
merged 3 commits into from

2 participants

Olivier Verdier Thomas Kluyver
Olivier Verdier

add simple test to check that the bug #786 is indeed fixed in master

Thomas Kluyver
Owner

I'm not quite sure if this is reliably cross-platform. On Windows, \xe9 may be equivalent to the single byte \xe9 (although due to limitations in Python, it may not be). Can we use an isinstance test instead of len?

Also, we're aiming for Python 3 compatibility for 0.12, so we need to be careful with this test. We probably need to add a skipif_python3 decorator for this. Have a look at IPython.testing.decorators (or I can add that, if you prefer).

Olivier Verdier olivierverdier TST: simpler check for unicode literals (#790)
check using isinstance instead for the length of the string
0ffa2ed
Olivier Verdier

Ok, I used isinstance instead of length, which is indeed more elegant. I'm not sure how to skip the test in Python 3, so I let you do that.

Thomas Kluyver
Owner

Great, thanks, that's definitely neater. In fact, I think it would now pass after conversion to Python 3, but I'll probably add a decorator to skip it anyway.

One minor niggle: the second argument to assert is the message that shows up if the assertion fails, and you've worded it as a description of what happens if it passes. I think it makes more sense for the message to say what went wrong, e.g.

assert isinstance(ip.user_ns['unicode_str'], unicode), 'strings literals are not being interpreted as unicode'
Olivier Verdier olivierverdier TST: remove assert messages (#790)
remove ambiguous assert messages for unicode_literals test
963bcc5
Olivier Verdier

ok, you're right about the assert message. Since I find it a bit awkward, I remove them altogether.

Thomas Kluyver takluyver merged commit 54e67c3 into from
Thomas Kluyver
Owner

Excellent. Thanks, Olivier - it's merged.

Brian E. Granger ellisonbg referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Brian E. Granger ellisonbg referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Brian E. Granger ellisonbg referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
matthew von rocketstein mattvonrocketstein referenced this pull request from a commit in mattvonrocketstein/ipython
Olivier Verdier olivierverdier TST: simpler check for unicode literals (#790)
check using isinstance instead for the length of the string
5d8340e
matthew von rocketstein mattvonrocketstein referenced this pull request from a commit in mattvonrocketstein/ipython
Olivier Verdier olivierverdier TST: remove assert messages (#790)
remove ambiguous assert messages for unicode_literals test
17b1cc7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 14, 2011
  1. Olivier Verdier
Commits on Sep 15, 2011
  1. Olivier Verdier

    TST: simpler check for unicode literals (#790)

    olivierverdier authored
    check using isinstance instead for the length of the string
  2. Olivier Verdier

    TST: remove assert messages (#790)

    olivierverdier authored
    remove ambiguous assert messages for unicode_literals test
This page is out of date. Refresh to see the latest.
Showing with 13 additions and 0 deletions.
  1. +13 −0 IPython/core/tests/test_interactiveshell.py
13 IPython/core/tests/test_interactiveshell.py
View
@@ -133,3 +133,16 @@ def test_future_flags(self):
finally:
# Reset compiler flags so we don't mess up other tests.
ip.compile.reset_compiler_flags()
+
+ def test_future_unicode(self):
+ """Check that unicode_literals is imported from __future__ (gh #786)"""
+ ip = get_ipython()
+ try:
+ ip.run_cell(u'byte_str = "a"')
+ assert isinstance(ip.user_ns['byte_str'], str) # string literals are byte strings by default
+ ip.run_cell('from __future__ import unicode_literals')
+ ip.run_cell(u'unicode_str = "a"')
+ assert isinstance(ip.user_ns['unicode_str'], unicode) # strings literals are now unicode
+ finally:
+ # Reset compiler flags so we don't mess up other tests.
+ ip.compile.reset_compiler_flags()
Something went wrong with that request. Please try again.