Skip to content

Commit 60c4c08

Browse files
committed
Fix test name and use mock.patch.dict
Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
1 parent f555a1c commit 60c4c08

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

bpython/test/test_curtsies_repl.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -314,31 +314,27 @@ class TestCurtsiesStartup(TestCase):
314314

315315
def setUp(self):
316316
self.repl = create_repl()
317-
self.startupfile = tempfile.NamedTemporaryFile()
318-
self.startupfile.__enter__()
319-
os.environ['PYTHONSTARTUP'] = self.startupfile.name
320317

321-
def tearDown(self):
322-
self.startupfile.__exit__(None, None, None)
323-
del os.environ['PYTHONSTARTUP']
324-
325-
def write_startup_file(self, encoding):
326-
with io.open(self.startupfile.name, mode='wt',
327-
encoding=encoding) as f:
318+
def write_startup_file(self, fname, encoding):
319+
with io.open(fname, mode='wt', encoding=encoding) as f:
328320
f.write('# coding: ')
329321
f.write(encoding)
330322
f.write('\n')
331323
f.write('from __future__ import unicode_literals\n')
332324
f.write('a = "äöü"\n')
333325

334326
def test_startup_event_utf8(self):
335-
self.write_startup_file('utf-8')
336-
self.repl.process_event(bpythonevents.RunStartupFileEvent())
327+
with tempfile.NamedTemporaryFile() as temp:
328+
self.write_startup_file(temp.name, 'utf-8')
329+
with mock.patch.dict('os.environ', {'PYTHONSTARTUP': temp.name}):
330+
self.repl.process_event(bpythonevents.RunStartupFileEvent())
337331
self.assertIn('a', self.repl.interp.locals)
338332

339-
def test_startup_event_utf8(self):
340-
self.write_startup_file('latin-1')
341-
self.repl.process_event(bpythonevents.RunStartupFileEvent())
333+
def test_startup_event_latin1(self):
334+
with tempfile.NamedTemporaryFile() as temp:
335+
self.write_startup_file(temp.name, 'latin-1')
336+
with mock.patch.dict('os.environ', {'PYTHONSTARTUP': temp.name}):
337+
self.repl.process_event(bpythonevents.RunStartupFileEvent())
342338
self.assertIn('a', self.repl.interp.locals)
343339

344340

0 commit comments

Comments
 (0)