From df86e70ed2318a149e80469e1b75ba5bf076088c 2011-05-26 18:14:29
From: Thomas Kluyver <takowl@gmail.com>
Date: 2011-05-26 18:14:29
Subject: [PATCH] Add test decorator onlyif_unicode_paths.

Closes gh-466

---

diff --git a/IPython/core/tests/test_application.py b/IPython/core/tests/test_application.py
index 24e0f61..3f337ed 100644
--- a/IPython/core/tests/test_application.py
+++ b/IPython/core/tests/test_application.py
@@ -5,7 +5,9 @@ import os
 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"€")
diff --git a/IPython/testing/decorators.py b/IPython/testing/decorators.py
index 9f4ae9d..2faeb33 100644
--- a/IPython/testing/decorators.py
+++ b/IPython/testing/decorators.py
@@ -49,6 +49,7 @@ Authors
 # Stdlib imports
 import inspect
 import sys
+import tempfile
 import unittest
 
 # Third-party imports
@@ -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"€")
+except UnicodeEncodeError:
+    unicode_paths = False
+else:
+    unicode_paths = True
+
+onlyif_unicode_paths = onlyif(unicode_paths, ("This test is only applicable "
+                                    "where we can use unicode in filenames."))