Add failing test for gh-3459
Thomas Kluyver -
r14813:faf01ee7
Not Reviewed
Show More
Add another comment
TODOs: 0 unresolved 0 Resolved
COMMENTS: 0 General 0 Inline
@@ -15,6 +15,8 import tempfile
15 import unittest
15 import unittest
16 from os.path import join
16 from os.path import join
17
17
18 import nose.tools as nt
19
18 from IPython.core.completerlib import magic_run_completer, module_completion
20 from IPython.core.completerlib import magic_run_completer, module_completion
19 from IPython.utils import py3compat
21 from IPython.utils import py3compat
20 from IPython.utils.tempdir import TemporaryDirectory
22 from IPython.utils.tempdir import TemporaryDirectory
@@ -31,7 +33,7 class MockEvent(object):
31 class Test_magic_run_completer(unittest.TestCase):
33 class Test_magic_run_completer(unittest.TestCase):
32 def setUp(self):
34 def setUp(self):
33 self.BASETESTDIR = tempfile.mkdtemp()
35 self.BASETESTDIR = tempfile.mkdtemp()
34 for fil in [u"aao.py", u"a.py", u"b.py"]:
36 for fil in [u"aao.py", u"a.py", u"b.py", u"aao.txt"]:
35 with open(join(self.BASETESTDIR, fil), "w") as sfile:
37 with open(join(self.BASETESTDIR, fil), "w") as sfile:
36 sfile.write("pass\n")
38 sfile.write("pass\n")
37 self.oldpath = py3compat.getcwd()
39 self.oldpath = py3compat.getcwd()
@@ -64,21 +66,13 class Test_magic_run_completer(unittest.TestCase):
64 match = set(magic_run_completer(mockself, event))
66 match = set(magic_run_completer(mockself, event))
65 self.assertEqual(match, set([u"a.py", u"aao.py"]))
67 self.assertEqual(match, set([u"a.py", u"aao.py"]))
66
68
67 def test_import_invalid_module(self):
69 def test_completion_in_dir(self):
68 """Testing of issue https://github.com/ipython/ipython/issues/1107"""
70 # Github issue #3459
69 invalid_module_names = set(['foo-bar', 'foo:bar', '10foo'])
71 event = MockEvent(u'%run a.py {}'.format(join(self.BASETESTDIR, 'a')))
70 valid_module_names = set(['foobar'])
72 print(repr(event.line))
71 with TemporaryDirectory() as tmpdir:
73 match = set(magic_run_completer(None, event))
72 sys.path.insert( 0, tmpdir )
74 self.assertEqual(match,
73 for name in invalid_module_names | valid_module_names:
75 {join(self.BASETESTDIR, f) for f in (u'a.py', u'aao.py', u'aao.txt')})
74 filename = os.path.join(tmpdir, name + '.py')
75 open(filename, 'w').close()
76
77 s = set( module_completion('import foo') )
78 intersection = s.intersection(invalid_module_names)
79 self.assertFalse(intersection, intersection)
80
81 assert valid_module_names.issubset(s), valid_module_names.intersection(s)
82
76
83 class Test_magic_run_completer_nonascii(unittest.TestCase):
77 class Test_magic_run_completer_nonascii(unittest.TestCase):
84 @onlyif_unicode_paths
78 @onlyif_unicode_paths
@@ -119,3 +113,21 class Test_magic_run_completer_nonascii(unittest.TestCase):
119 mockself = None
113 mockself = None
120 match = set(magic_run_completer(mockself, event))
114 match = set(magic_run_completer(mockself, event))
121 self.assertEqual(match, set([u"a.py", u"aaø.py"]))
115 self.assertEqual(match, set([u"a.py", u"aaø.py"]))
116
117 # module_completer:
118
119 def test_import_invalid_module():
120 """Testing of issue https://github.com/ipython/ipython/issues/1107"""
121 invalid_module_names = set(['foo-bar', 'foo:bar', '10foo'])
122 valid_module_names = set(['foobar'])
123 with TemporaryDirectory() as tmpdir:
124 sys.path.insert( 0, tmpdir )
125 for name in invalid_module_names | valid_module_names:
126 filename = os.path.join(tmpdir, name + '.py')
127 open(filename, 'w').close()
128
129 s = set( module_completion('import foo') )
130 intersection = s.intersection(invalid_module_names)
131 nt.assert_equal(intersection, set())
132
133 assert valid_module_names.issubset(s), valid_module_names.intersection(s)
Comments 0
You need to be logged in to leave comments. Login now