|
1 |
| -# coding: utf8 |
| 1 | +# coding: utf-8 |
2 | 2 | from __future__ import unicode_literals
|
3 | 3 |
|
4 | 4 | import code
|
5 | 5 | import os
|
6 | 6 | import sys
|
7 | 7 | import tempfile
|
| 8 | +import io |
8 | 9 | from contextlib import contextmanager
|
9 | 10 | from six.moves import StringIO
|
10 | 11 |
|
@@ -313,13 +314,31 @@ class TestCurtsiesStartup(TestCase):
|
313 | 314 |
|
314 | 315 | def setUp(self):
|
315 | 316 | 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 |
317 | 320 |
|
318 | 321 | def tearDown(self):
|
| 322 | + self.startupfile.__exit__(None, None, None) |
319 | 323 | del os.environ['PYTHONSTARTUP']
|
320 | 324 |
|
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') |
323 | 342 | self.repl.process_event(bpythonevents.RunStartupFileEvent())
|
324 | 343 | self.assertIn('a', self.repl.interp.locals)
|
325 | 344 |
|
|
0 commit comments