Show More
@@ -17,6 +17,7 b' from os.path import join' | |||
|
17 | 17 | |
|
18 | 18 | from IPython.core.completerlib import magic_run_completer, module_completion |
|
19 | 19 | from IPython.utils.tempdir import TemporaryDirectory |
|
20 | from IPython.testing.decorators import onlyif_unicode_paths | |
|
20 | 21 | |
|
21 | 22 | |
|
22 | 23 | class MockEvent(object): |
@@ -29,7 +30,7 b' class MockEvent(object):' | |||
|
29 | 30 | class Test_magic_run_completer(unittest.TestCase): |
|
30 | 31 | def setUp(self): |
|
31 | 32 | self.BASETESTDIR = tempfile.mkdtemp() |
|
32 |
for fil in [u"aa |
|
|
33 | for fil in [u"aao.py", u"a.py", u"b.py"]: | |
|
33 | 34 | with open(join(self.BASETESTDIR, fil), "w") as sfile: |
|
34 | 35 | sfile.write("pass\n") |
|
35 | 36 | self.oldpath = os.getcwdu() |
@@ -45,7 +46,7 b' class Test_magic_run_completer(unittest.TestCase):' | |||
|
45 | 46 | event = MockEvent(u"%run a") |
|
46 | 47 | mockself = None |
|
47 | 48 | match = set(magic_run_completer(mockself, event)) |
|
48 |
self.assertEqual(match, set([u"a.py", u"aa |
|
|
49 | self.assertEqual(match, set([u"a.py", u"aao.py"])) | |
|
49 | 50 | |
|
50 | 51 | def test_2(self): |
|
51 | 52 | """Test magic_run_completer, should match one alterntive |
@@ -53,14 +54,14 b' class Test_magic_run_completer(unittest.TestCase):' | |||
|
53 | 54 | event = MockEvent(u"%run aa") |
|
54 | 55 | mockself = None |
|
55 | 56 | match = set(magic_run_completer(mockself, event)) |
|
56 |
self.assertEqual(match, set([u"aa |
|
|
57 | self.assertEqual(match, set([u"aao.py"])) | |
|
57 | 58 | |
|
58 | 59 | def test_3(self): |
|
59 | 60 | """Test magic_run_completer with unterminated " """ |
|
60 | 61 | event = MockEvent(u'%run "a') |
|
61 | 62 | mockself = None |
|
62 | 63 | match = set(magic_run_completer(mockself, event)) |
|
63 |
self.assertEqual(match, set([u"a.py", u"aa |
|
|
64 | self.assertEqual(match, set([u"a.py", u"aao.py"])) | |
|
64 | 65 | |
|
65 | 66 | def test_import_invalid_module(self): |
|
66 | 67 | """Testing of issue https://github.com/ipython/ipython/issues/1107""" |
@@ -77,3 +78,43 b' class Test_magic_run_completer(unittest.TestCase):' | |||
|
77 | 78 | self.assertFalse(intersection, intersection) |
|
78 | 79 | |
|
79 | 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 | 33 | import nose.tools as nt |
|
34 | 34 | |
|
35 | 35 | # Our own |
|
36 | from IPython.testing.decorators import skipif | |
|
36 | from IPython.testing.decorators import skipif, onlyif_unicode_paths | |
|
37 | 37 | from IPython.testing import tools as tt |
|
38 | 38 | from IPython.utils import io |
|
39 | 39 | |
@@ -404,6 +404,7 b' class InteractiveShellTestCase(unittest.TestCase):' | |||
|
404 | 404 | |
|
405 | 405 | class TestSafeExecfileNonAsciiPath(unittest.TestCase): |
|
406 | 406 | |
|
407 | @onlyif_unicode_paths | |
|
407 | 408 | def setUp(self): |
|
408 | 409 | self.BASETESTDIR = tempfile.mkdtemp() |
|
409 | 410 | self.TESTDIR = join(self.BASETESTDIR, u"åäö") |
@@ -418,6 +419,7 b' class TestSafeExecfileNonAsciiPath(unittest.TestCase):' | |||
|
418 | 419 | os.chdir(self.oldpath) |
|
419 | 420 | shutil.rmtree(self.BASETESTDIR) |
|
420 | 421 | |
|
422 | @onlyif_unicode_paths | |
|
421 | 423 | def test_1(self): |
|
422 | 424 | """Test safe_execfile with non-ascii path |
|
423 | 425 | """ |
@@ -425,6 +427,7 b' class TestSafeExecfileNonAsciiPath(unittest.TestCase):' | |||
|
425 | 427 | |
|
426 | 428 | |
|
427 | 429 | class TestSystemRaw(unittest.TestCase): |
|
430 | @onlyif_unicode_paths | |
|
428 | 431 | def test_1(self): |
|
429 | 432 | """Test system_raw with non-ascii cmd |
|
430 | 433 | """ |
@@ -122,9 +122,11 b' def test_list_profiles_in():' | |||
|
122 | 122 | # the module-level teardown. |
|
123 | 123 | td = tempfile.mkdtemp(dir=TMP_TEST_DIR) |
|
124 | 124 | td = py3compat.str_to_unicode(td) |
|
125 |
for name in ('profile_foo', |
|
|
126 | 'not_a_profile'): | |
|
125 | for name in ('profile_foo', 'profile_hello', 'not_a_profile'): | |
|
127 | 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 | 130 | with open(os.path.join(td, 'profile_file'), 'w') as f: |
|
129 | 131 | f.write("I am not a profile directory") |
|
130 | 132 | profiles = list_profiles_in(td) |
@@ -139,6 +141,7 b' def test_list_profiles_in():' | |||
|
139 | 141 | profiles.remove(p) |
|
140 | 142 | found_unicode = True |
|
141 | 143 | break |
|
144 | if dec.unicode_paths: | |
|
142 | 145 | nt.assert_true(found_unicode) |
|
143 | 146 | nt.assert_equal(set(profiles), set(['foo', 'hello'])) |
|
144 | 147 |
@@ -63,6 +63,7 b' class PromptTests(unittest.TestCase):' | |||
|
63 | 63 | self.pm.in_template = r'\#>' |
|
64 | 64 | self.assertEqual(self.pm.render('in',color=False), '%d>' % ip.execution_count) |
|
65 | 65 | |
|
66 | @dec.onlyif_unicode_paths | |
|
66 | 67 | def test_render_unicode_cwd(self): |
|
67 | 68 | save = os.getcwdu() |
|
68 | 69 | with TemporaryDirectory(u'ünicødé') as td: |
@@ -6,6 +6,7 b' import os.path' | |||
|
6 | 6 | import unittest |
|
7 | 7 | |
|
8 | 8 | from IPython.testing import tools as tt |
|
9 | from IPython.testing.decorators import onlyif_unicode_paths | |
|
9 | 10 | from IPython.utils.syspathcontext import prepended_to_syspath |
|
10 | 11 | from IPython.utils.tempdir import TemporaryDirectory |
|
11 | 12 | |
@@ -59,9 +60,22 b' def fail():' | |||
|
59 | 60 | ''' |
|
60 | 61 | |
|
61 | 62 | class NonAsciiTest(unittest.TestCase): |
|
62 | def test_iso8859_5(self): | |
|
63 | @onlyif_unicode_paths | |
|
64 | def test_nonascii_path(self): | |
|
63 | 65 | # Non-ascii directory name as well. |
|
64 | 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 | 79 | fname = os.path.join(td, 'dfghjkl.py') |
|
66 | 80 | |
|
67 | 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 | 29 | import IPython |
|
30 | 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 | 33 | from IPython.testing.tools import make_tempfile, AssertPrints |
|
33 | 34 | from IPython.utils import path |
|
34 | 35 | from IPython.utils import py3compat |
@@ -480,6 +481,7 b' def test_get_py_filename():' | |||
|
480 | 481 | nt.assert_raises(IOError, path.get_py_filename, '"foo with spaces.py"', force_win32=False) |
|
481 | 482 | nt.assert_raises(IOError, path.get_py_filename, "'foo with spaces.py'", force_win32=False) |
|
482 | 483 | |
|
484 | @onlyif_unicode_paths | |
|
483 | 485 | def test_unicode_in_filename(): |
|
484 | 486 | """When a file doesn't exist, the exception raised should be safe to call |
|
485 | 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