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

@olivierverdier

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

@takluyver
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).

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

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.

@takluyver
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'
@olivierverdier olivierverdier TST: remove assert messages (#790)
remove ambiguous assert messages for unicode_literals test
963bcc5
@olivierverdier

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

@takluyver takluyver merged commit 54e67c3 into from
@takluyver
Owner

Excellent. Thanks, Olivier - it's merged.

@ellisonbg ellisonbg referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@ellisonbg ellisonbg referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@ellisonbg ellisonbg referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@mattvonrocketstein mattvonrocketstein referenced this pull request from a commit in mattvonrocketstein/ipython
@olivierverdier olivierverdier TST: simpler check for unicode literals (#790)
check using isinstance instead for the length of the string
5d8340e
@mattvonrocketstein mattvonrocketstein referenced this pull request from a commit in mattvonrocketstein/ipython
@olivierverdier 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. @olivierverdier
Commits on Sep 15, 2011
  1. @olivierverdier

    TST: simpler check for unicode literals (#790)

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

    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
View
13 IPython/core/tests/test_interactiveshell.py
@@ -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.