Skip to content

Commit b5d7790

Browse files
committed
Test differently encoded startup files
Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
1 parent d0bc25d commit b5d7790

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

bpython/test/test_curtsies_repl.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
# coding: utf8
1+
# coding: utf-8
22
from __future__ import unicode_literals
33

44
import code
55
import os
66
import sys
77
import tempfile
8+
import io
89
from contextlib import contextmanager
910
from six.moves import StringIO
1011

@@ -313,13 +314,31 @@ class TestCurtsiesStartup(TestCase):
313314

314315
def setUp(self):
315316
self.repl = create_repl()
316-
os.environ['PYTHONSTARTUP'] = 'file'
317+
self.startupfile = tempfile.NamedTemporaryFile()
318+
self.startupfile.__enter__()
319+
os.environ['PYTHONSTARTUP'] = self.startupfile.name
317320

318321
def tearDown(self):
322+
self.startupfile.__exit__(None, None, None)
319323
del os.environ['PYTHONSTARTUP']
320324

321-
@mock.patch(builtin_target(open), mock.mock_open(read_data='a = 1\n'))
322-
def test_startup_event(self):
325+
def write_startup_file(self, encoding, write_encoding=True):
326+
with io.open(self.startupfile.name, mode='wt',
327+
encoding=encoding) as f:
328+
if write_encoding:
329+
f.write('# coding: ')
330+
f.write(encoding)
331+
f.write('\n')
332+
f.write('from __future__ import unicode_literals\n')
333+
f.write('a = "äöü"\n')
334+
335+
def test_startup_event_utf8(self):
336+
self.write_startup_file('utf-8')
337+
self.repl.process_event(bpythonevents.RunStartupFileEvent())
338+
self.assertIn('a', self.repl.interp.locals)
339+
340+
def test_startup_event_utf8(self):
341+
self.write_startup_file('latin-1')
323342
self.repl.process_event(bpythonevents.RunStartupFileEvent())
324343
self.assertIn('a', self.repl.interp.locals)
325344

0 commit comments

Comments
 (0)