Skip to content
This repository

Add test decorator onlyif_unicode_paths. #471

Merged
merged 2 commits into from about 3 years ago

2 participants

Thomas Kluyver Fernando Perez
Thomas Kluyver
Collaborator

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')
318 319 # A null 'decorator', useful to make more readable code that needs to pick
319 320 # between different decorators based on OS or other conditions
320 321 null_deco = lambda f: f
  322 +
  323 +# Some tests only run where we can use unicode paths. Note that we can't just
  324 +# check os.path.supports_unicode_filenames, which is always False on Linux.
  325 +try:
  326 + tempfile.mkdtemp(u"€")
3
Fernando Perez 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 -*-
Fernando Perez 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.

Thomas Kluyver Collaborator
takluyver added a note

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

@fperez: Followed your suggestions.

Fernando Perez
Owner
fperez commented

Looks great, merge away!

Thomas Kluyver takluyver merged commit eeba6ff into from
Thomas Kluyver takluyver closed this
Thomas Kluyver
Collaborator

Rebased and merged.

Damián Avila 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.
5 IPython/core/tests/test_application.py
@@ -5,7 +5,9 @@
5 5 import tempfile
6 6
7 7 from IPython.core.application import Application
  8 +from IPython.testing import decorators as testdec
8 9
  10 +@testdec.onlyif_unicode_paths
9 11 def test_unicode_cwd():
10 12 """Check that IPython starts with non-ascii characters in the path."""
11 13 wd = tempfile.mkdtemp(suffix=u"€")
@@ -32,7 +34,8 @@ def test_unicode_cwd():
32 34 app.load_file_config(suppress_errors=False)
33 35 finally:
34 36 os.chdir(old_wd)
35   -
  37 +
  38 +@testdec.onlyif_unicode_paths
36 39 def test_unicode_ipdir():
37 40 """Check that IPython starts with non-ascii characters in the IP dir."""
38 41 ipdir = tempfile.mkdtemp(suffix=u"€")
15 IPython/testing/decorators.py
... ... @@ -1,3 +1,4 @@
  1 +# -*- coding: utf-8 -*-
1 2 """Decorators for labeling test objects.
2 3
3 4 Decorators that merely return a modified version of the original function
@@ -49,6 +50,7 @@
49 50 # Stdlib imports
50 51 import inspect
51 52 import sys
  53 +import tempfile
52 54 import unittest
53 55
54 56 # Third-party imports
@@ -318,3 +320,16 @@ def module_not_available(module):
318 320 # A null 'decorator', useful to make more readable code that needs to pick
319 321 # between different decorators based on OS or other conditions
320 322 null_deco = lambda f: f
  323 +
  324 +# Some tests only run where we can use unicode paths. Note that we can't just
  325 +# check os.path.supports_unicode_filenames, which is always False on Linux.
  326 +try:
  327 + f = tempfile.NamedTemporaryFile(prefix=u"tmp€")
  328 +except UnicodeEncodeError:
  329 + unicode_paths = False
  330 +else:
  331 + unicode_paths = True
  332 + f.close()
  333 +
  334 +onlyif_unicode_paths = onlyif(unicode_paths, ("This test is only applicable "
  335 + "where we can use unicode in filenames."))

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.