##// END OF EJS Templates
Backport PR #4019: Test skipping without unicode paths...
MinRK -
Show More
@@ -17,6 +17,7 b' from os.path import join'
17
17
18 from IPython.core.completerlib import magic_run_completer, module_completion
18 from IPython.core.completerlib import magic_run_completer, module_completion
19 from IPython.utils.tempdir import TemporaryDirectory
19 from IPython.utils.tempdir import TemporaryDirectory
20 from IPython.testing.decorators import onlyif_unicode_paths
20
21
21
22
22 class MockEvent(object):
23 class MockEvent(object):
@@ -29,7 +30,7 b' class MockEvent(object):'
29 class Test_magic_run_completer(unittest.TestCase):
30 class Test_magic_run_completer(unittest.TestCase):
30 def setUp(self):
31 def setUp(self):
31 self.BASETESTDIR = tempfile.mkdtemp()
32 self.BASETESTDIR = tempfile.mkdtemp()
32 for fil in [u"aaø.py", u"a.py", u"b.py"]:
33 for fil in [u"aao.py", u"a.py", u"b.py"]:
33 with open(join(self.BASETESTDIR, fil), "w") as sfile:
34 with open(join(self.BASETESTDIR, fil), "w") as sfile:
34 sfile.write("pass\n")
35 sfile.write("pass\n")
35 self.oldpath = os.getcwdu()
36 self.oldpath = os.getcwdu()
@@ -45,7 +46,7 b' class Test_magic_run_completer(unittest.TestCase):'
45 event = MockEvent(u"%run a")
46 event = MockEvent(u"%run a")
46 mockself = None
47 mockself = None
47 match = set(magic_run_completer(mockself, event))
48 match = set(magic_run_completer(mockself, event))
48 self.assertEqual(match, set([u"a.py", u"aaø.py"]))
49 self.assertEqual(match, set([u"a.py", u"aao.py"]))
49
50
50 def test_2(self):
51 def test_2(self):
51 """Test magic_run_completer, should match one alterntive
52 """Test magic_run_completer, should match one alterntive
@@ -53,14 +54,14 b' class Test_magic_run_completer(unittest.TestCase):'
53 event = MockEvent(u"%run aa")
54 event = MockEvent(u"%run aa")
54 mockself = None
55 mockself = None
55 match = set(magic_run_completer(mockself, event))
56 match = set(magic_run_completer(mockself, event))
56 self.assertEqual(match, set([u"aaø.py"]))
57 self.assertEqual(match, set([u"aao.py"]))
57
58
58 def test_3(self):
59 def test_3(self):
59 """Test magic_run_completer with unterminated " """
60 """Test magic_run_completer with unterminated " """
60 event = MockEvent(u'%run "a')
61 event = MockEvent(u'%run "a')
61 mockself = None
62 mockself = None
62 match = set(magic_run_completer(mockself, event))
63 match = set(magic_run_completer(mockself, event))
63 self.assertEqual(match, set([u"a.py", u"aaø.py"]))
64 self.assertEqual(match, set([u"a.py", u"aao.py"]))
64
65
65 def test_import_invalid_module(self):
66 def test_import_invalid_module(self):
66 """Testing of issue https://github.com/ipython/ipython/issues/1107"""
67 """Testing of issue https://github.com/ipython/ipython/issues/1107"""
@@ -77,3 +78,43 b' class Test_magic_run_completer(unittest.TestCase):'
77 self.assertFalse(intersection, intersection)
78 self.assertFalse(intersection, intersection)
78
79
79 assert valid_module_names.issubset(s), valid_module_names.intersection(s)
80 assert valid_module_names.issubset(s), valid_module_names.intersection(s)
81
82 class Test_magic_run_completer_nonascii(unittest.TestCase):
83 @onlyif_unicode_paths
84 def setUp(self):
85 self.BASETESTDIR = tempfile.mkdtemp()
86 for fil in [u"aaø.py", u"a.py", u"b.py"]:
87 with open(join(self.BASETESTDIR, fil), "w") as sfile:
88 sfile.write("pass\n")
89 self.oldpath = os.getcwdu()
90 os.chdir(self.BASETESTDIR)
91
92 def tearDown(self):
93 os.chdir(self.oldpath)
94 shutil.rmtree(self.BASETESTDIR)
95
96 @onlyif_unicode_paths
97 def test_1(self):
98 """Test magic_run_completer, should match two alterntives
99 """
100 event = MockEvent(u"%run a")
101 mockself = None
102 match = set(magic_run_completer(mockself, event))
103 self.assertEqual(match, set([u"a.py", u"aaø.py"]))
104
105 @onlyif_unicode_paths
106 def test_2(self):
107 """Test magic_run_completer, should match one alterntive
108 """
109 event = MockEvent(u"%run aa")
110 mockself = None
111 match = set(magic_run_completer(mockself, event))
112 self.assertEqual(match, set([u"aaø.py"]))
113
114 @onlyif_unicode_paths
115 def test_3(self):
116 """Test magic_run_completer with unterminated " """
117 event = MockEvent(u'%run "a')
118 mockself = None
119 match = set(magic_run_completer(mockself, event))
120 self.assertEqual(match, set([u"a.py", u"aaø.py"]))
@@ -33,7 +33,7 b' from StringIO import StringIO'
33 import nose.tools as nt
33 import nose.tools as nt
34
34
35 # Our own
35 # Our own
36 from IPython.testing.decorators import skipif
36 from IPython.testing.decorators import skipif, onlyif_unicode_paths
37 from IPython.testing import tools as tt
37 from IPython.testing import tools as tt
38 from IPython.utils import io
38 from IPython.utils import io
39
39
@@ -404,6 +404,7 b' class InteractiveShellTestCase(unittest.TestCase):'
404
404
405 class TestSafeExecfileNonAsciiPath(unittest.TestCase):
405 class TestSafeExecfileNonAsciiPath(unittest.TestCase):
406
406
407 @onlyif_unicode_paths
407 def setUp(self):
408 def setUp(self):
408 self.BASETESTDIR = tempfile.mkdtemp()
409 self.BASETESTDIR = tempfile.mkdtemp()
409 self.TESTDIR = join(self.BASETESTDIR, u"åäö")
410 self.TESTDIR = join(self.BASETESTDIR, u"åäö")
@@ -418,6 +419,7 b' class TestSafeExecfileNonAsciiPath(unittest.TestCase):'
418 os.chdir(self.oldpath)
419 os.chdir(self.oldpath)
419 shutil.rmtree(self.BASETESTDIR)
420 shutil.rmtree(self.BASETESTDIR)
420
421
422 @onlyif_unicode_paths
421 def test_1(self):
423 def test_1(self):
422 """Test safe_execfile with non-ascii path
424 """Test safe_execfile with non-ascii path
423 """
425 """
@@ -425,6 +427,7 b' class TestSafeExecfileNonAsciiPath(unittest.TestCase):'
425
427
426
428
427 class TestSystemRaw(unittest.TestCase):
429 class TestSystemRaw(unittest.TestCase):
430 @onlyif_unicode_paths
428 def test_1(self):
431 def test_1(self):
429 """Test system_raw with non-ascii cmd
432 """Test system_raw with non-ascii cmd
430 """
433 """
@@ -122,9 +122,11 b' def test_list_profiles_in():'
122 # the module-level teardown.
122 # the module-level teardown.
123 td = tempfile.mkdtemp(dir=TMP_TEST_DIR)
123 td = tempfile.mkdtemp(dir=TMP_TEST_DIR)
124 td = py3compat.str_to_unicode(td)
124 td = py3compat.str_to_unicode(td)
125 for name in ('profile_foo', u'profile_ünicode', 'profile_hello',
125 for name in ('profile_foo', 'profile_hello', 'not_a_profile'):
126 'not_a_profile'):
127 os.mkdir(os.path.join(td, name))
126 os.mkdir(os.path.join(td, name))
127 if dec.unicode_paths:
128 os.mkdir(os.path.join(td, u'profile_ünicode'))
129
128 with open(os.path.join(td, 'profile_file'), 'w') as f:
130 with open(os.path.join(td, 'profile_file'), 'w') as f:
129 f.write("I am not a profile directory")
131 f.write("I am not a profile directory")
130 profiles = list_profiles_in(td)
132 profiles = list_profiles_in(td)
@@ -139,7 +141,8 b' def test_list_profiles_in():'
139 profiles.remove(p)
141 profiles.remove(p)
140 found_unicode = True
142 found_unicode = True
141 break
143 break
142 nt.assert_true(found_unicode)
144 if dec.unicode_paths:
145 nt.assert_true(found_unicode)
143 nt.assert_equal(set(profiles), set(['foo', 'hello']))
146 nt.assert_equal(set(profiles), set(['foo', 'hello']))
144
147
145
148
@@ -63,6 +63,7 b' class PromptTests(unittest.TestCase):'
63 self.pm.in_template = r'\#>'
63 self.pm.in_template = r'\#>'
64 self.assertEqual(self.pm.render('in',color=False), '%d>' % ip.execution_count)
64 self.assertEqual(self.pm.render('in',color=False), '%d>' % ip.execution_count)
65
65
66 @dec.onlyif_unicode_paths
66 def test_render_unicode_cwd(self):
67 def test_render_unicode_cwd(self):
67 save = os.getcwdu()
68 save = os.getcwdu()
68 with TemporaryDirectory(u'ünicødé') as td:
69 with TemporaryDirectory(u'ünicødé') as td:
@@ -6,6 +6,7 b' import os.path'
6 import unittest
6 import unittest
7
7
8 from IPython.testing import tools as tt
8 from IPython.testing import tools as tt
9 from IPython.testing.decorators import onlyif_unicode_paths
9 from IPython.utils.syspathcontext import prepended_to_syspath
10 from IPython.utils.syspathcontext import prepended_to_syspath
10 from IPython.utils.tempdir import TemporaryDirectory
11 from IPython.utils.tempdir import TemporaryDirectory
11
12
@@ -59,9 +60,22 b' def fail():'
59 '''
60 '''
60
61
61 class NonAsciiTest(unittest.TestCase):
62 class NonAsciiTest(unittest.TestCase):
62 def test_iso8859_5(self):
63 @onlyif_unicode_paths
64 def test_nonascii_path(self):
63 # Non-ascii directory name as well.
65 # Non-ascii directory name as well.
64 with TemporaryDirectory(suffix=u'é') as td:
66 with TemporaryDirectory(suffix=u'é') as td:
67 fname = os.path.join(td, u"fooé.py")
68 with open(fname, "w") as f:
69 f.write(file_1)
70
71 with prepended_to_syspath(td):
72 ip.run_cell("import foo")
73
74 with tt.AssertPrints("ZeroDivisionError"):
75 ip.run_cell("foo.f()")
76
77 def test_iso8859_5(self):
78 with TemporaryDirectory() as td:
65 fname = os.path.join(td, 'dfghjkl.py')
79 fname = os.path.join(td, 'dfghjkl.py')
66
80
67 with io.open(fname, 'w', encoding='iso-8859-5') as f:
81 with io.open(fname, 'w', encoding='iso-8859-5') as f:
@@ -28,7 +28,8 b' from nose import with_setup'
28
28
29 import IPython
29 import IPython
30 from IPython.testing import decorators as dec
30 from IPython.testing import decorators as dec
31 from IPython.testing.decorators import skip_if_not_win32, skip_win32
31 from IPython.testing.decorators import (skip_if_not_win32, skip_win32,
32 onlyif_unicode_paths,)
32 from IPython.testing.tools import make_tempfile, AssertPrints
33 from IPython.testing.tools import make_tempfile, AssertPrints
33 from IPython.utils import path
34 from IPython.utils import path
34 from IPython.utils import py3compat
35 from IPython.utils import py3compat
@@ -479,7 +480,8 b' def test_get_py_filename():'
479 else:
480 else:
480 nt.assert_raises(IOError, path.get_py_filename, '"foo with spaces.py"', force_win32=False)
481 nt.assert_raises(IOError, path.get_py_filename, '"foo with spaces.py"', force_win32=False)
481 nt.assert_raises(IOError, path.get_py_filename, "'foo with spaces.py'", force_win32=False)
482 nt.assert_raises(IOError, path.get_py_filename, "'foo with spaces.py'", force_win32=False)
482
483
484 @onlyif_unicode_paths
483 def test_unicode_in_filename():
485 def test_unicode_in_filename():
484 """When a file doesn't exist, the exception raised should be safe to call
486 """When a file doesn't exist, the exception raised should be safe to call
485 str() on - i.e. in Python 2 it must only have ASCII characters.
487 str() on - i.e. in Python 2 it must only have ASCII characters.
General Comments 0
You need to be logged in to leave comments. Login now