Show More
@@ -165,7 +165,7 b' def try_import(mod: str, only_modules=False) -> List[str]:' | |||||
165 | except: |
|
165 | except: | |
166 | return [] |
|
166 | return [] | |
167 |
|
167 | |||
168 | m_is_init = hasattr(m, '__file__') and '__init__' in m.__file__ |
|
168 | m_is_init = '__init__' in (getattr(m, '__file__', '') or '') | |
169 |
|
169 | |||
170 | completions = [] |
|
170 | completions = [] | |
171 | if (not hasattr(m, '__file__')) or (not only_modules) or m_is_init: |
|
171 | if (not hasattr(m, '__file__')) or (not only_modules) or m_is_init: |
@@ -16,7 +16,7 b' from os.path import join' | |||||
16 |
|
16 | |||
17 | import nose.tools as nt |
|
17 | import nose.tools as nt | |
18 |
|
18 | |||
19 | from IPython.core.completerlib import magic_run_completer, module_completion |
|
19 | from IPython.core.completerlib import magic_run_completer, module_completion, try_import | |
20 | from IPython.utils.tempdir import TemporaryDirectory |
|
20 | from IPython.utils.tempdir import TemporaryDirectory | |
21 | from IPython.testing.decorators import onlyif_unicode_paths |
|
21 | from IPython.testing.decorators import onlyif_unicode_paths | |
22 |
|
22 | |||
@@ -159,3 +159,20 b' def test_bad_module_all():' | |||||
159 | nt.assert_is_instance(r, str) |
|
159 | nt.assert_is_instance(r, str) | |
160 | finally: |
|
160 | finally: | |
161 | sys.path.remove(testsdir) |
|
161 | sys.path.remove(testsdir) | |
|
162 | ||||
|
163 | ||||
|
164 | def test_module_without_init(): | |||
|
165 | """ | |||
|
166 | Test module without __init__.py. | |||
|
167 | ||||
|
168 | https://github.com/ipython/ipython/issues/11226 | |||
|
169 | """ | |||
|
170 | fake_module_name = "foo" | |||
|
171 | with TemporaryDirectory() as tmpdir: | |||
|
172 | sys.path.insert(0, tmpdir) | |||
|
173 | try: | |||
|
174 | os.makedirs(os.path.join(tmpdir, fake_module_name)) | |||
|
175 | s = try_import(mod=fake_module_name) | |||
|
176 | assert s == [] | |||
|
177 | finally: | |||
|
178 | sys.path.remove(tmpdir) |
General Comments 0
You need to be logged in to leave comments.
Login now