11import os
22import unittest
3+ import sys
34from itertools import islice
4-
5- from bpython import config , repl
5+ from mock import Mock
6+ from bpython import config , repl , cli
67
78
89class TestHistory (unittest .TestCase ):
@@ -130,6 +131,13 @@ def test_update(self):
130131 self .assertNotEqual (list (slice ), self .matches )
131132 self .assertEqual (list (newslice ), newmatches )
132133
134+ class FakeHistory (repl .History ):
135+
136+ def __init__ (self ):
137+ pass
138+
139+ def reset (self ):
140+ pass
133141
134142class FakeRepl (repl .Repl ):
135143 def __init__ (self , conf = {}):
@@ -150,6 +158,11 @@ def current_line(self):
150158 def cw (self ):
151159 return self .current_word
152160
161+ class FakeCliRepl (cli .CLIRepl , FakeRepl ):
162+ def __init__ (self ):
163+ self .s = ''
164+ self .cpos = 0
165+ self .rl_history = FakeHistory ()
153166
154167class TestArgspec (unittest .TestCase ):
155168 def setUp (self ):
@@ -229,8 +242,55 @@ def test_alternate_complete(self):
229242 self .assertEqual (self .repl .completer .matches ,
230243 ['UnboundLocalError(' , '__doc__' ])
231244
245+ class TestCliRepl (unittest .TestCase ):
246+
247+ def setUp (self ):
248+ self .repl = FakeCliRepl ()
249+
250+ def test_atbol (self ):
251+ self .assertTrue (self .repl .atbol ())
252+ self .repl .s = "\t \t "
253+ self .assertTrue (self .repl .atbol ())
254+ self .repl .s = "\t \t not an empty line"
255+ self .assertFalse (self .repl .atbol ())
256+
257+ def test_addstr (self ):
258+ self .repl .complete = Mock (True )
259+
260+ self .repl .s = "foo"
261+ self .repl .addstr ("bar" )
262+ self .assertEqual (self .repl .s , "foobar" )
263+
264+ self .repl .cpos = 3
265+ self .repl .addstr ('buzz' )
266+ self .assertEqual (self .repl .s , "foobuzzbar" )
267+
268+ def test_cw (self ):
269+
270+ self .repl .cpos = 2
271+ self .assertEqual (self .repl .cw (), None )
272+ self .repl .cpos = 0
273+
274+ self .repl .s = ''
275+ self .assertEqual (self .repl .cw (), None )
276+
277+ self .repl .s = "this.is.a.test\t "
278+ self .assertEqual (self .repl .cw (), None )
279+
280+ s = "this.is.a.test"
281+ self .repl .s = s
282+ self .assertEqual (self .repl .cw (), s )
283+
284+ s = "\t \t this.is.a.test"
285+ self .repl .s = s
286+ self .assertEqual (self .repl .cw (), s .lstrip ())
232287
288+ self .repl .s = "this.is.\t a.test"
289+ self .assertEqual (self .repl .cw (), 'a.test' )
233290
291+ def test_tab (self ):
292+ pass
293+ # self.repl.tab()
234294
235295if __name__ == '__main__' :
236296 unittest .main ()
0 commit comments