|
3 | 3 | from collections import namedtuple |
4 | 4 | import inspect |
5 | 5 | import keyword |
6 | | -from bpython._py3compat import py3 |
| 6 | +import sys |
7 | 7 |
|
8 | 8 | try: |
9 | 9 | import unittest2 as unittest |
|
17 | 17 | has_jedi = False |
18 | 18 |
|
19 | 19 | from bpython import autocomplete |
| 20 | +from bpython._py3compat import py3 |
20 | 21 | from bpython.test import mock |
21 | 22 |
|
| 23 | +if sys.version_info[:2] >= (3, 4): |
| 24 | + glob_function = 'glob.iglob' |
| 25 | +else: |
| 26 | + glob_function = 'glob.glob' |
| 27 | + |
22 | 28 |
|
23 | 29 | class TestSafeEval(unittest.TestCase): |
24 | 30 | def test_catches_syntax_error(self): |
@@ -123,33 +129,31 @@ def test_locate_fails_when_not_in_string(self): |
123 | 129 | def test_locate_succeeds_when_in_string(self): |
124 | 130 | self.assertEqual(self.completer.locate(4, "a'bc'd"), (2, 4, 'bc')) |
125 | 131 |
|
126 | | - @mock.patch('glob.iglob', new=lambda text: []) |
| 132 | + @mock.patch(glob_function, new=lambda text: []) |
127 | 133 | def test_match_returns_none_if_not_in_string(self): |
128 | 134 | self.assertEqual(self.completer.matches(2, 'abcd'), None) |
129 | 135 |
|
130 | | - @mock.patch('glob.iglob', new=lambda text: []) |
| 136 | + @mock.patch(glob_function, new=lambda text: []) |
131 | 137 | def test_match_returns_empty_list_when_no_files(self): |
132 | 138 | self.assertEqual(self.completer.matches(2, '"a'), set()) |
133 | 139 |
|
134 | | - @mock.patch('glob.iglob', |
135 | | - new=lambda text: ['abcde', 'aaaaa']) |
| 140 | + @mock.patch(glob_function, new=lambda text: ['abcde', 'aaaaa']) |
136 | 141 | @mock.patch('os.path.expanduser', new=lambda text: text) |
137 | 142 | @mock.patch('os.path.isdir', new=lambda text: False) |
138 | 143 | @mock.patch('os.path.sep', new='/') |
139 | 144 | def test_match_returns_files_when_files_exist(self): |
140 | 145 | self.assertEqual(sorted(self.completer.matches(2, '"x')), |
141 | 146 | ['aaaaa', 'abcde']) |
142 | 147 |
|
143 | | - @mock.patch('glob.iglob', |
144 | | - new=lambda text: ['abcde', 'aaaaa']) |
| 148 | + @mock.patch(glob_function, new=lambda text: ['abcde', 'aaaaa']) |
145 | 149 | @mock.patch('os.path.expanduser', new=lambda text: text) |
146 | 150 | @mock.patch('os.path.isdir', new=lambda text: True) |
147 | 151 | @mock.patch('os.path.sep', new='/') |
148 | 152 | def test_match_returns_dirs_when_dirs_exist(self): |
149 | 153 | self.assertEqual(sorted(self.completer.matches(2, '"x')), |
150 | 154 | ['aaaaa/', 'abcde/']) |
151 | 155 |
|
152 | | - @mock.patch('glob.iglob', |
| 156 | + @mock.patch(glob_function, |
153 | 157 | new=lambda text: ['/expand/ed/abcde', '/expand/ed/aaaaa']) |
154 | 158 | @mock.patch('os.path.expanduser', |
155 | 159 | new=lambda text: text.replace('~', '/expand/ed')) |
|
0 commit comments