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