Skip to content

Commit 79d55fa

Browse files
more tests, fix bpython#360
Bit of a cop out, but less tests are being skipped now
1 parent aea557a commit 79d55fa

File tree

3 files changed

+21
-47
lines changed

3 files changed

+21
-47
lines changed

bpython/autocomplete.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@
5757
"oct", "hex", "index", "coerce", "enter", "exit"]]
5858

5959

60+
def after_last_dot(name):
61+
return name.rstrip('.').rsplit('.')[-1]
62+
6063
def get_completer(cursor_offset, current_line, locals_, argspec, full_code, mode, complete_magic_methods):
6164
"""Returns a list of matches and a class for what kind of completion is happening
6265
@@ -132,9 +135,7 @@ class ImportCompletion(BaseCompletionType):
132135
def matches(cls, cursor_offset, current_line, **kwargs):
133136
return importcompletion.complete(cursor_offset, current_line)
134137
locate = staticmethod(lineparts.current_word)
135-
@classmethod
136-
def format(cls, name):
137-
return name.rstrip('.').rsplit('.')[-1]
138+
format = staticmethod(after_last_dot)
138139

139140
class FilenameCompletion(BaseCompletionType):
140141
shown_before_tab = False
@@ -193,9 +194,7 @@ def matches(cls, cursor_offset, line, locals_, mode, **kwargs):
193194
return matches
194195

195196
locate = staticmethod(lineparts.current_dotted_attribute)
196-
@classmethod
197-
def format(cls, name):
198-
return name.rstrip('.').rsplit('.')[-1]
197+
format = staticmethod(after_last_dot)
199198

200199
class DictKeyCompletion(BaseCompletionType):
201200
locate = staticmethod(lineparts.current_dict_key)

bpython/test/test_autocomplete.py

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,10 @@
99
def skip(f):
1010
return lambda self: None
1111

12-
13-
# Parts of autocompletion to test:
12+
#TODO: Parts of autocompletion to test:
1413
# Test that the right matches come back from find_matches (test that priority is correct)
1514
# Test the various complete methods (import, filename) to see if right matches
1615
# Test that MatchesIterator.substitute correctly subs given a match and a completer
17-
"""
18-
def test_cw(self):
19-
20-
self.repl.cpos = 2
21-
self.assertEqual(self.repl.cw(), None)
22-
self.repl.cpos = 0
23-
24-
self.repl.s = ''
25-
self.assertEqual(self.repl.cw(), None)
26-
27-
self.repl.s = "this.is.a.test\t"
28-
self.assertEqual(self.repl.cw(), None)
29-
30-
s = "this.is.a.test"
31-
self.repl.s = s
32-
self.assertEqual(self.repl.cw(), s)
33-
34-
s = "\t\tthis.is.a.test"
35-
self.repl.s = s
36-
self.assertEqual(self.repl.cw(), s.lstrip())
37-
38-
self.repl.s = "import datetime"
39-
self.assertEqual(self.repl.cw(), 'datetime')
40-
"""
4116

4217
class TestSafeEval(unittest.TestCase):
4318
def test_catches_syntax_error(self):
@@ -46,22 +21,16 @@ def test_catches_syntax_error(self):
4621
except:
4722
self.fail('safe_eval raises an error')
4823

49-
# make some fake files? Dependency inject? mock?
50-
class TestFilenameCompletion(unittest.TestCase):
51-
pass
52-
53-
5424
class TestFormatters(unittest.TestCase):
5525

56-
@skip('not done yet')
5726
def test_filename(self):
58-
self.assertEqual(autocomplete.last_part_of_filename('abc'), 'abc')
59-
self.assertEqual(autocomplete.last_part_of_filename('abc/'), 'abc/')
60-
self.assertEqual(autocomplete.last_part_of_filename('abc/efg'), 'efg')
61-
self.assertEqual(autocomplete.last_part_of_filename('abc/efg/'), 'efg/')
62-
self.assertEqual(autocomplete.last_part_of_filename('/abc'), 'abc')
63-
self.assertEqual(autocomplete.last_part_of_filename('ab.c/e.f.g/'), 'e.f.g/')
27+
last_part_of_filename = autocomplete.FilenameCompletion.format
28+
self.assertEqual(last_part_of_filename('abc'), 'abc')
29+
self.assertEqual(last_part_of_filename('abc/'), 'abc/')
30+
self.assertEqual(last_part_of_filename('abc/efg'), 'efg')
31+
self.assertEqual(last_part_of_filename('abc/efg/'), 'efg/')
32+
self.assertEqual(last_part_of_filename('/abc'), 'abc')
33+
self.assertEqual(last_part_of_filename('ab.c/e.f.g/'), 'e.f.g/')
6434

65-
@skip('not done yet')
6635
def test_attribute(self):
6736
self.assertEqual(autocomplete.after_last_dot('abc.edf'), 'edf')

bpython/test/test_manual_readline.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,16 @@ def test_seq(self):
230230
self.assertRaises(KeyError, self.edits.call, 'b')
231231

232232
def test_functions_with_bad_signatures(self):
233-
pass #TODO
233+
f = lambda something: (1, 2)
234+
self.assertRaises(TypeError, self.edits.add, 'a', f)
235+
g = lambda cursor_offset, line, something, something_else: (1, 2)
236+
self.assertRaises(TypeError, self.edits.add, 'a', g)
234237

235238
def test_functions_with_bad_return_values(self):
236-
pass #TODO
239+
f = lambda cursor_offset, line: ('hi',)
240+
self.assertRaises(ValueError, self.edits.add, 'a', f)
241+
g = lambda cursor_offset, line: ('hi', 1, 2, 3)
242+
self.assertRaises(ValueError, self.edits.add, 'b', g)
237243

238244
def test_config(self):
239245
f = lambda cursor_offset, line: ('hi', 2)

0 commit comments

Comments
 (0)