##// END OF EJS Templates
Ross Jones -
Show More
@@ -1,67 +1,79 b''
1 1 # -*- coding: utf-8 -*-
2 2 """Tests for completerlib.
3 3
4 4 """
5 5 from __future__ import absolute_import
6 6
7 7 #-----------------------------------------------------------------------------
8 8 # Imports
9 9 #-----------------------------------------------------------------------------
10 10
11 11 import os
12 12 import shutil
13 13 import sys
14 14 import tempfile
15 15 import unittest
16 16 from os.path import join
17 17
18 18 import nose.tools as nt
19 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 22 from IPython.utils import py3compat
23 from IPython.utils.tempdir import TemporaryDirectory
23 24
24 25
25 26 class MockEvent(object):
26 27 def __init__(self, line):
27 28 self.line = line
28 29
29 30 #-----------------------------------------------------------------------------
30 31 # Test functions begin
31 32 #-----------------------------------------------------------------------------
32 33 class Test_magic_run_completer(unittest.TestCase):
33 34 def setUp(self):
34 35 self.BASETESTDIR = tempfile.mkdtemp()
35 36 for fil in [u"aaø.py", u"a.py", u"b.py"]:
36 37 with open(join(self.BASETESTDIR, fil), "w") as sfile:
37 38 sfile.write("pass\n")
38 39 self.oldpath = os.getcwdu()
39 40 os.chdir(self.BASETESTDIR)
40 41
41 42 def tearDown(self):
42 43 os.chdir(self.oldpath)
43 44 shutil.rmtree(self.BASETESTDIR)
44 45
45 46 def test_1(self):
46 47 """Test magic_run_completer, should match two alterntives
47 48 """
48 49 event = MockEvent(u"%run a")
49 50 mockself = None
50 51 match = set(magic_run_completer(mockself, event))
51 52 self.assertEqual(match, set([u"a.py", u"aaø.py"]))
52 53
53 54 def test_2(self):
54 55 """Test magic_run_completer, should match one alterntive
55 56 """
56 57 event = MockEvent(u"%run aa")
57 58 mockself = None
58 59 match = set(magic_run_completer(mockself, event))
59 60 self.assertEqual(match, set([u"aaø.py"]))
60 61
61 62 def test_3(self):
62 63 """Test magic_run_completer with unterminated " """
63 64 event = MockEvent(u'%run "a')
64 65 mockself = None
65 66 match = set(magic_run_completer(mockself, event))
66 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 self.assertFalse( s.intersection(invalid_module_names) )
General Comments 0
You need to be logged in to leave comments. Login now