Skip to content

Commit bd11ff7

Browse files
repl paint tests
1 parent 6154e73 commit bd11ff7

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

bpython/curtsiesfrontend/filewatch.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ def __init__(self, paths, on_change):
1818
self.modules_to_add_later = []
1919
self.observer = Observer()
2020
self.old_dirs = defaultdict(set)
21+
self.started = False
2122
for path in paths:
2223
self.add_module(path)
23-
self.observer.start()
2424

2525
def reset(self):
2626
self.dirs = defaultdict(set)
@@ -44,6 +44,9 @@ def add_module_later(self, path):
4444
self.modules_to_add_later.append(path)
4545

4646
def activate(self):
47+
if not self.started:
48+
self.started = True
49+
self.observer.start()
4750
self.dirs = self.old_dirs
4851
for dirname in self.dirs:
4952
self.observer.schedule(self, dirname, recursive=False)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# coding: utf8
2+
import unittest
3+
import sys
4+
import os
5+
6+
from curtsies.formatstringarray import FormatStringTest, fsarray
7+
8+
from curtsies.fmtfuncs import *
9+
10+
from bpython import config
11+
from bpython.curtsiesfrontend.repl import Repl
12+
from bpython.repl import History
13+
14+
def setup_config():
15+
config_struct = config.Struct()
16+
config.loadini(config_struct, os.devnull)
17+
return config_struct
18+
19+
class TestCurtsiesPainting(FormatStringTest):
20+
def setUp(self):
21+
self.refresh_requests = []
22+
self.repl = Repl(config=setup_config())
23+
self.repl.rl_history = History() # clear history
24+
self.repl.height, self.repl.width = (5, 10)
25+
26+
def assert_paint(self, screen, cursor_row_col):
27+
array, cursor_pos = self.repl.paint()
28+
self.assertFSArraysEqual(array, screen)
29+
self.assertEqual(cursor_pos, cursor_row_col)
30+
31+
def assert_paint_ignoring_formatting(self, screen, cursor_row_col):
32+
array, cursor_pos = self.repl.paint()
33+
self.assertFSArraysEqualIgnoringFormatting(array, screen)
34+
35+
def test_startup(self):
36+
screen = fsarray([cyan('>>> '), cyan('Welcome to')])
37+
self.assert_paint(screen, (0, 4))
38+
39+
def test_enter_text(self):
40+
[self.repl.add_normal_character(c) for c in '1 + 1']
41+
screen = fsarray([cyan('>>> ') + bold(green('1')+cyan(' ')+
42+
yellow('+') + cyan(' ') + green('1')), cyan('Welcome to')])
43+
self.assert_paint(screen, (0, 9))
44+
45+
def test_run_line(self):
46+
try:
47+
orig_stdout = sys.stdout
48+
sys.stdout = self.repl.stdout
49+
[self.repl.add_normal_character(c) for c in '1 + 1']
50+
self.repl.on_enter()
51+
screen = fsarray([u'>>> 1 + 1', '2', 'Welcome to'])
52+
self.assert_paint_ignoring_formatting(screen, (0, 9))
53+
finally:
54+
sys.stdout = orig_stdout
55+
56+
def test_completion(self):
57+
self.repl.height, self.repl.width = (5, 32)
58+
self.repl.current_line = 'se'
59+
self.cursor_offset = 2
60+
screen = [u'>>> se',
61+
u'┌───────────────────────┐',
62+
u'│ set( setattr( │',
63+
u'└───────────────────────┘',
64+
u'',
65+
u'Welcome to bpython! Press <F1> f']
66+
self.assert_paint_ignoring_formatting(screen, (0, 9))

0 commit comments

Comments
 (0)