Skip to content

Commit 7bcaf4c

Browse files
committed
Make more tests pass in a non utf-8 locale
Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
1 parent 42a253a commit 7bcaf4c

File tree

2 files changed

+37
-15
lines changed

2 files changed

+37
-15
lines changed

bpython/test/test_curtsies_painting.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,18 @@ def test_completion(self):
7474
self.repl.height, self.repl.width = (5, 32)
7575
self.repl.current_line = 'se'
7676
self.cursor_offset = 2
77-
screen = [u'>>> se',
78-
u'┌───────────────────────┐',
79-
u'│ set( setattr( │',
80-
u'└───────────────────────┘',
81-
u'Welcome to bpython! Press <F1> f']
77+
if config.supports_box_chars():
78+
screen = [u'>>> se',
79+
u'┌───────────────────────┐',
80+
u'│ set( setattr( │',
81+
u'└───────────────────────┘',
82+
u'Welcome to bpython! Press <F1> f']
83+
else:
84+
screen = [u'>>> se',
85+
u'+-----------------------+',
86+
u'| set( setattr( |',
87+
u'+-----------------------+',
88+
u'Welcome to bpython! Press <F1> f']
8289
self.assert_paint_ignoring_formatting(screen, (0, 4))
8390

8491
def test_argspec(self):
@@ -100,11 +107,19 @@ def test_formatted_docstring(self):
100107
self.assertFSArraysEqualIgnoringFormatting(actual, expected)
101108

102109
def test_paint_lasts_events(self):
103-
actual = replpainter.paint_last_events(4, 100, ['a', 'b', 'c'], config=setup_config())
104-
expected = fsarray(["┌─┐",
105-
"│c│",
106-
"│b│",
107-
"└─┘"])
110+
actual = replpainter.paint_last_events(4, 100, ['a', 'b', 'c'],
111+
config=setup_config())
112+
if config.supports_box_chars():
113+
expected = fsarray(["┌─┐",
114+
"│c│",
115+
"│b│",
116+
"└─┘"])
117+
else:
118+
expected = fsarray(["+-+",
119+
"|c|",
120+
"|b|",
121+
"+-+"])
122+
108123
self.assertFSArraysEqualIgnoringFormatting(actual, expected)
109124

110125
@contextmanager

bpython/test/test_curtsies_repl.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# coding: utf8
2+
from __future__ import unicode_literals
3+
24
import code
35
from contextlib import contextmanager
46
from mock import Mock, patch, MagicMock
@@ -53,13 +55,14 @@ def test_code_finished_will_parse(self):
5355
self.assertTrue(self.cfwp('\n'.join(self.repl.buffer)), (True, True))
5456

5557
def test_external_communication(self):
56-
self.assertEqual(type(self.repl.help_text()), type(b''))
5758
self.repl.send_current_block_to_external_editor()
5859
self.repl.send_session_to_external_editor()
5960

61+
@unittest.skipIf(not all(map(config.can_encode, 'å∂߃')),
62+
'Charset can not encode characters')
6063
def test_external_communication_encoding(self):
6164
with captured_output():
62-
self.repl.display_lines.append(u'>>> "åß∂ƒ"')
65+
self.repl.display_lines.append('>>> "åß∂ƒ"')
6366
self.repl.send_session_to_external_editor()
6467

6568
def test_get_last_word(self):
@@ -269,19 +272,23 @@ class TestCurtsiesPagerText(TestCase):
269272

270273
def setUp(self):
271274
self.repl = create_repl()
272-
self.repl.pager = self.assert_pager_gets_bytes
275+
self.repl.pager = self.assert_pager_gets_unicode
273276

274-
def assert_pager_gets_bytes(self, text):
275-
self.assertIsInstance(text, type(b''))
277+
def assert_pager_gets_unicode(self, text):
278+
self.assertIsInstance(text, type(''))
276279

277280
def test_help(self):
278281
self.repl.pager(self.repl.help_text())
279282

283+
@unittest.skipIf(not all(map(config.can_encode, 'å∂߃')),
284+
'Charset can not encode characters')
280285
def test_show_source_not_formatted(self):
281286
self.repl.config.highlight_show_source = False
282287
self.repl.get_source_of_current_name = lambda: 'source code å∂߃åß∂ƒ'
283288
self.repl.show_source()
284289

290+
@unittest.skipIf(not all(map(config.can_encode, 'å∂߃')),
291+
'Charset can not encode characters')
285292
def test_show_source_formatted(self):
286293
self.repl.config.highlight_show_source = True
287294
self.repl.get_source_of_current_name = lambda: 'source code å∂߃åß∂ƒ'

0 commit comments

Comments
 (0)