Add test decorator onlyif_unicode_paths. #471

Merged
merged 2 commits into from May 26, 2011
Jump to file or symbol
Failed to load files and symbols.
+19 −1
Split
@@ -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"")
@@ -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."))