11from unittest import TestCase
22
3- from _pyrepl .utils import str_width , wlen
3+ from _pyrepl .utils import str_width , wlen , prev_next_window
44
55
66class TestUtils (TestCase ):
@@ -25,3 +25,38 @@ def test_wlen(self):
2525
2626 self .assertEqual (wlen ('hello' ), 5 )
2727 self .assertEqual (wlen ('hello' + '\x1a ' ), 7 )
28+
29+ def test_prev_next_window (self ):
30+ def gen_normal ():
31+ yield 1
32+ yield 2
33+ yield 3
34+ yield 4
35+
36+ pnw = prev_next_window (gen_normal ())
37+ self .assertEqual (next (pnw ), (None , 1 , 2 ))
38+ self .assertEqual (next (pnw ), (1 , 2 , 3 ))
39+ self .assertEqual (next (pnw ), (2 , 3 , 4 ))
40+ self .assertEqual (next (pnw ), (3 , 4 , None ))
41+ with self .assertRaises (StopIteration ):
42+ next (pnw )
43+
44+ def gen_short ():
45+ yield 1
46+
47+ pnw = prev_next_window (gen_short ())
48+ self .assertEqual (next (pnw ), (None , 1 , None ))
49+ with self .assertRaises (StopIteration ):
50+ next (pnw )
51+
52+ def gen_raise ():
53+ yield from gen_normal ()
54+ 1 / 0
55+
56+ pnw = prev_next_window (gen_raise ())
57+ self .assertEqual (next (pnw ), (None , 1 , 2 ))
58+ self .assertEqual (next (pnw ), (1 , 2 , 3 ))
59+ self .assertEqual (next (pnw ), (2 , 3 , 4 ))
60+ self .assertEqual (next (pnw ), (3 , 4 , None ))
61+ with self .assertRaises (ZeroDivisionError ):
62+ next (pnw )
0 commit comments