forked from bpython/bpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_curtsies_painting.py
More file actions
65 lines (54 loc) · 2.34 KB
/
test_curtsies_painting.py
File metadata and controls
65 lines (54 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# coding: utf8
import unittest
import sys
import os
from curtsies.formatstringarray import FormatStringTest, fsarray
from curtsies.fmtfuncs import *
from bpython import config
from bpython.curtsiesfrontend.repl import Repl
from bpython.repl import History
def setup_config():
config_struct = config.Struct()
config.loadini(config_struct, os.devnull)
return config_struct
class TestCurtsiesPainting(FormatStringTest):
def setUp(self):
self.repl = Repl(config=setup_config())
self.repl.rl_history = History() # clear history
self.repl.height, self.repl.width = (5, 10)
def assert_paint(self, screen, cursor_row_col):
array, cursor_pos = self.repl.paint()
self.assertFSArraysEqual(array, screen)
self.assertEqual(cursor_pos, cursor_row_col)
def assert_paint_ignoring_formatting(self, screen, cursor_row_col):
array, cursor_pos = self.repl.paint()
self.assertFSArraysEqualIgnoringFormatting(array, screen)
def test_startup(self):
screen = fsarray([cyan('>>> '), cyan('Welcome to')])
self.assert_paint(screen, (0, 4))
def test_enter_text(self):
[self.repl.add_normal_character(c) for c in '1 + 1']
screen = fsarray([cyan('>>> ') + bold(green('1')+cyan(' ')+
yellow('+') + cyan(' ') + green('1')), cyan('Welcome to')])
self.assert_paint(screen, (0, 9))
def test_run_line(self):
try:
orig_stdout = sys.stdout
sys.stdout = self.repl.stdout
[self.repl.add_normal_character(c) for c in '1 + 1']
self.repl.on_enter()
screen = fsarray([u'>>> 1 + 1', '2', 'Welcome to'])
self.assert_paint_ignoring_formatting(screen, (0, 9))
finally:
sys.stdout = orig_stdout
def test_completion(self):
self.repl.height, self.repl.width = (5, 32)
self.repl.current_line = 'se'
self.cursor_offset = 2
screen = [u'>>> se',
u'┌───────────────────────┐',
u'│ set( setattr( │',
u'└───────────────────────┘',
u'',
u'Welcome to bpython! Press <F1> f']
self.assert_paint_ignoring_formatting(screen, (0, 9))