X Tutup
Skip to content

Commit 5a0524e

Browse files
committed
unittesting: TestRepl added
1 parent b1792b9 commit 5a0524e

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

bpython/test/test_repl.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,39 @@ def test_update(self):
129129
self.assertNotEqual(list(slice), self.matches)
130130
self.assertEqual(list(newslice), newmatches)
131131

132+
from bpython.args import parse
133+
134+
class TestRepl(unittest.TestCase):
135+
136+
def setUp(self):
137+
config = parse(args=[])[0]
138+
self.interp = repl.Interpreter()
139+
self.repl = repl.Repl(self.interp, config)
140+
141+
def test_attr_matches(self):
142+
# test with builtin object
143+
self.assertEqual(self.repl.attr_matches('str.s'),
144+
['str.%s' % x for x in dir(str) if x.startswith('s')])
145+
self.assertEqual(self.repl.attr_matches('int.de'),
146+
['int.%s' % x for x in dir(int) if x.startswith('de')])
147+
self.assertEqual(self.repl.attr_matches('tuple.foospamegg'), [])
148+
149+
# test with a new object
150+
class A(object):
151+
spam = 'egg'
152+
153+
@property
154+
def clone(self):
155+
return A()
156+
self.interp.locals['A'] = A
157+
158+
self.assertEqual(self.repl.attr_matches('A.spam'), ['A.spam'])
159+
# test nested attributes
160+
self.assertEqual(self.repl.attr_matches('A.spam.isdi'),
161+
['A.spam.isdigit'])
162+
self.assertEqual(self.repl.attr_matches('A.clone.s'), ['A.clone.spam'])
163+
164+
132165

133166
if __name__ == '__main__':
134167
unittest.main()

0 commit comments

Comments
 (0)
X Tutup