Skip to content

Commit cb90872

Browse files
author
llllllllll
committed
Adds tests to validate that __dict__ is in the autocomplete of an old
style class or instance.
1 parent 5cf6f52 commit cb90872

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

bpython/test/test_autocomplete.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,42 @@ def method(self, x):
215215
pass
216216

217217

218+
class OldStyleFoo:
219+
a = 10
220+
221+
def __init__(self):
222+
self.b = 20
223+
224+
def method(self, x):
225+
pass
226+
227+
228+
skip_old_style = unittest.skipIf(py3,
229+
'In Python 3 there are no old style classes')
230+
231+
218232
class TestAttrCompletion(unittest.TestCase):
233+
@classmethod
234+
def setUpClass(cls):
235+
cls.com = autocomplete.AttrCompletion()
219236

220237
def test_att_matches_found_on_instance(self):
221-
com = autocomplete.AttrCompletion()
222-
self.assertSetEqual(com.matches(2, 'a.', locals_={'a': Foo()}),
238+
self.assertSetEqual(self.com.matches(2, 'a.', locals_={'a': Foo()}),
223239
set(['a.method', 'a.a', 'a.b']))
224240

241+
@skip_old_style
242+
def test_att_matches_found_on_old_style_instance(self):
243+
self.assertSetEqual(self.com.matches(2, 'a.',
244+
locals_={'a': OldStyleFoo()}),
245+
{'a.method', 'a.a', 'a.b'})
246+
self.assertIn(u'a.__dict__',
247+
self.com.matches(3, 'a._', locals_={'a': OldStyleFoo()}))
248+
249+
@skip_old_style
250+
def test_att_matches_found_on_old_style_class_object(self):
251+
self.assertIn(u'A.__dict__',
252+
self.com.matches(3, 'A._', locals_={'A': OldStyleFoo}))
253+
225254

226255
class TestMagicMethodCompletion(unittest.TestCase):
227256

0 commit comments

Comments
 (0)