Show More
@@ -83,10 +83,15 b' def module_list(path):' | |||||
83 | pjoin = os.path.join |
|
83 | pjoin = os.path.join | |
84 | basename = os.path.basename |
|
84 | basename = os.path.basename | |
85 |
|
85 | |||
|
86 | def is_importable_file(path): | |||
|
87 | """Returns True if the provided path is a valid importable module""" | |||
|
88 | name, extension = os.path.splitext( path ) | |||
|
89 | return import_re.match(path) and py3compat.isidentifier(name) | |||
|
90 | ||||
86 | # Now find actual path matches for packages or modules |
|
91 | # Now find actual path matches for packages or modules | |
87 | folder_list = [p for p in folder_list |
|
92 | folder_list = [p for p in folder_list | |
88 | if isfile(pjoin(path, p,'__init__.py')) |
|
93 | if isfile(pjoin(path, p,'__init__.py')) | |
89 |
or import |
|
94 | or is_importable_file(p) ] | |
90 |
|
95 | |||
91 | return [basename(p).split('.')[0] for p in folder_list] |
|
96 | return [basename(p).split('.')[0] for p in folder_list] | |
92 |
|
97 |
@@ -18,8 +18,9 b' from os.path import join' | |||||
18 | import nose.tools as nt |
|
18 | import nose.tools as nt | |
19 | from nose import SkipTest |
|
19 | from nose import SkipTest | |
20 |
|
20 | |||
21 | from IPython.core.completerlib import magic_run_completer |
|
21 | from IPython.core.completerlib import magic_run_completer, module_completion | |
22 | from IPython.utils import py3compat |
|
22 | from IPython.utils import py3compat | |
|
23 | from IPython.utils.tempdir import TemporaryDirectory | |||
23 |
|
24 | |||
24 |
|
25 | |||
25 | class MockEvent(object): |
|
26 | class MockEvent(object): | |
@@ -65,3 +66,15 b' class Test_magic_run_completer(unittest.TestCase):' | |||||
65 | match = set(magic_run_completer(mockself, event)) |
|
66 | match = set(magic_run_completer(mockself, event)) | |
66 | self.assertEqual(match, set([u"a.py", u"aaø.py"])) |
|
67 | self.assertEqual(match, set([u"a.py", u"aaø.py"])) | |
67 |
|
68 | |||
|
69 | def test_import_invalid_module(self): | |||
|
70 | """Testing of issue https://github.com/ipython/ipython/issues/1107""" | |||
|
71 | invalid_module_names = set(['foo-bar', 'foo:bar', '10foo']) | |||
|
72 | with TemporaryDirectory() as tmpdir: | |||
|
73 | sys.path.insert( 0, tmpdir ) | |||
|
74 | for name in invalid_module_names: | |||
|
75 | filename = os.path.join(tmpdir, name + '.py') | |||
|
76 | open(filename, 'w').close() | |||
|
77 | ||||
|
78 | s = set( module_completion('import foo') ) | |||
|
79 | intersection = s.intersection(invalid_module_names) | |||
|
80 | self.assertFalse(intersection, intersection) |
General Comments 0
You need to be logged in to leave comments.
Login now