1515import unittest
1616from os .path import join
1717
18+ import nose .tools as nt
19+
1820from IPython .core .completerlib import magic_run_completer , module_completion
1921from IPython .utils import py3compat
2022from IPython .utils .tempdir import TemporaryDirectory
@@ -31,7 +33,7 @@ def __init__(self, line):
3133class Test_magic_run_completer (unittest .TestCase ):
3234 def setUp (self ):
3335 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" ]:
3537 with open (join (self .BASETESTDIR , fil ), "w" ) as sfile :
3638 sfile .write ("pass\n " )
3739 self .oldpath = py3compat .getcwd ()
@@ -64,21 +66,13 @@ def test_3(self):
6466 match = set (magic_run_completer (mockself , event ))
6567 self .assertEqual (match , set ([u"a.py" , u"aao.py" ]))
6668
67- def test_import_invalid_module (self ):
68- """Testing of issue https://github.com/ipython/ipython/issues/1107"""
69- invalid_module_names = set (['foo-bar' , 'foo:bar' , '10foo' ])
70- valid_module_names = set (['foobar' ])
71- with TemporaryDirectory () as tmpdir :
72- sys .path .insert ( 0 , tmpdir )
73- for name in invalid_module_names | valid_module_names :
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 )
69+ def test_completion_in_dir (self ):
70+ # Github issue #3459
71+ event = MockEvent (u'%run a.py {}' .format (join (self .BASETESTDIR , 'a' )))
72+ print (repr (event .line ))
73+ match = set (magic_run_completer (None , event ))
74+ self .assertEqual (match ,
75+ {join (self .BASETESTDIR , f ) for f in (u'a.py' , u'aao.py' , u'aao.txt' )})
8276
8377class Test_magic_run_completer_nonascii (unittest .TestCase ):
8478 @onlyif_unicode_paths
@@ -119,3 +113,21 @@ def test_3(self):
119113 mockself = None
120114 match = set (magic_run_completer (mockself , event ))
121115 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 )
0 commit comments