Skip to content
This repository

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

Merged
merged 3 commits into from over 2 years ago

2 participants

Olivier Verdier Thomas Kluyver
Olivier Verdier

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

Thomas Kluyver
Collaborator

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 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
Collaborator

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 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 September 15, 2011
Thomas Kluyver takluyver closed this September 15, 2011
Thomas Kluyver
Collaborator

Excellent. Thanks, Olivier - it's merged.

Brian E. Granger ellisonbg referenced this pull request from a commit January 10, 2012
Commit has since been removed from the repository and is no longer available.
Brian E. Granger ellisonbg referenced this pull request from a commit January 10, 2012
Commit has since been removed from the repository and is no longer available.
Brian E. Granger ellisonbg referenced this pull request from a commit January 10, 2012
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 3 unique commits by 1 author.

Sep 14, 2011
Olivier Verdier TST: add future unicode_literals test (#786) 42e2485
Sep 15, 2011
Olivier Verdier TST: simpler check for unicode literals (#790)
check using isinstance instead for the length of the string
0ffa2ed
Olivier Verdier TST: remove assert messages (#790)
remove ambiguous assert messages for unicode_literals test
963bcc5
This page is out of date. Refresh to see the latest.
13  IPython/core/tests/test_interactiveshell.py
@@ -133,3 +133,16 @@ def test_future_flags(self):
133 133
         finally:
134 134
             # Reset compiler flags so we don't mess up other tests.
135 135
             ip.compile.reset_compiler_flags()
  136
+
  137
+    def test_future_unicode(self):
  138
+        """Check that unicode_literals is imported from __future__ (gh #786)"""
  139
+        ip = get_ipython()
  140
+        try:
  141
+            ip.run_cell(u'byte_str = "a"')
  142
+            assert isinstance(ip.user_ns['byte_str'], str) # string literals are byte strings by default
  143
+            ip.run_cell('from __future__ import unicode_literals')
  144
+            ip.run_cell(u'unicode_str = "a"')
  145
+            assert isinstance(ip.user_ns['unicode_str'], unicode) # strings literals are now unicode
  146
+        finally:
  147
+            # Reset compiler flags so we don't mess up other tests.
  148
+            ip.compile.reset_compiler_flags()
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.