Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add test decorator onlyif_unicode_paths. #471

Merged
merged 2 commits into from

2 participants

@takluyver
Owner

Some of our tests hit an error where unicode paths weren't supported. Since they're specifically to test unicode paths, it didn't make sense to change them. This adds a decorator which skips them in those circumstances.

Closes gh-466

IPython/testing/decorators.py
@@ -318,3 +319,15 @@ skip_known_failure = knownfailureif(True,'This test is known to fail')
# A null 'decorator', useful to make more readable code that needs to pick
# between different decorators based on OS or other conditions
null_deco = lambda f: f
+
+# Some tests only run where we can use unicode paths. Note that we can't just
+# check os.path.supports_unicode_filenames, which is always False on Linux.
+try:
+ tempfile.mkdtemp(u"€")
@fperez Owner
fperez added a note

Looks good, but since you're putting explicit unicode in the file, it should carry an encoding mark at the top:

# -*- coding: utf-8 -*-
@fperez Owner
fperez added a note

Also, note that mkdtemp doesn't clean up the temporary directory. you might want to use instead

f = tempfile.NamedTemproraryFile(prefix=u"tmp€")
f.close()

This will ensure we don't leave junk behind after each run of these tests.

@takluyver Owner

I always seem to forget the encoding line. Will do on both counts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@takluyver
Owner

@fperez: Followed your suggestions.

@fperez
Owner

Looks great, merge away!

@takluyver takluyver merged commit eeba6ff into from
@takluyver
Owner

Rebased and merged.

@damianavila damianavila referenced this pull request from a commit
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
This page is out of date. Refresh to see the latest.
View
5 IPython/core/tests/test_application.py
@@ -5,7 +5,9 @@
import tempfile
from IPython.core.application import Application
+from IPython.testing import decorators as testdec
+@testdec.onlyif_unicode_paths
def test_unicode_cwd():
"""Check that IPython starts with non-ascii characters in the path."""
wd = tempfile.mkdtemp(suffix=u"")
@@ -32,7 +34,8 @@ def test_unicode_cwd():
app.load_file_config(suppress_errors=False)
finally:
os.chdir(old_wd)
-
+
+@testdec.onlyif_unicode_paths
def test_unicode_ipdir():
"""Check that IPython starts with non-ascii characters in the IP dir."""
ipdir = tempfile.mkdtemp(suffix=u"")
View
15 IPython/testing/decorators.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
"""Decorators for labeling test objects.
Decorators that merely return a modified version of the original function
@@ -49,6 +50,7 @@
# Stdlib imports
import inspect
import sys
+import tempfile
import unittest
# Third-party imports
@@ -318,3 +320,16 @@ def module_not_available(module):
# A null 'decorator', useful to make more readable code that needs to pick
# between different decorators based on OS or other conditions
null_deco = lambda f: f
+
+# Some tests only run where we can use unicode paths. Note that we can't just
+# check os.path.supports_unicode_filenames, which is always False on Linux.
+try:
+ f = tempfile.NamedTemporaryFile(prefix=u"tmp€")
+except UnicodeEncodeError:
+ unicode_paths = False
+else:
+ unicode_paths = True
+ f.close()
+
+onlyif_unicode_paths = onlyif(unicode_paths, ("This test is only applicable "
+ "where we can use unicode in filenames."))
Something went wrong with that request. Please try again.