| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f555a1c commit 60c4c08
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -314,31 +314,27 @@ class TestCurtsiesStartup(TestCase): | |||
| 314 | 314 | ||
| 315 | 315 | def setUp(self): | |
| 316 | 316 | self.repl = create_repl() | |
| 317 | - self.startupfile = tempfile.NamedTemporaryFile() | ||
| 318 | - self.startupfile.__enter__() | ||
| 319 | - os.environ['PYTHONSTARTUP'] = self.startupfile.name | ||
| 320 | 317 | ||
| 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: | ||
| 328 | 320 | f.write('# coding: ') | |
| 329 | 321 | f.write(encoding) | |
| 330 | 322 | f.write('\n') | |
| 331 | 323 | f.write('from __future__ import unicode_literals\n') | |
| 332 | 324 | f.write('a = "äöü"\n') | |
| 333 | 325 | ||
| 334 | 326 | 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()) | ||
| 337 | 331 | self.assertIn('a', self.repl.interp.locals) | |
| 338 | 332 | ||
| 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()) | ||
| 342 | 338 | self.assertIn('a', self.repl.interp.locals) | |
| 343 | 339 | ||
| 344 | 340 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments