Skip to content

Commit 3fb8441

Browse files
test running startup file
1 parent 50d2b21 commit 3fb8441

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

bpython/test/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from bpython.translations import init
1414
from bpython._py3compat import py3
15+
from six.moves import builtins
1516

1617

1718
class FixLanguageTestCase(unittest.TestCase):
@@ -27,3 +28,8 @@ class MagicIterMock(mock.MagicMock):
2728
__next__ = mock.Mock(return_value=None)
2829
else:
2930
next = mock.Mock(return_value=None)
31+
32+
33+
def builtin_target(obj):
34+
"""Returns mock target string of a builtin"""
35+
return '%s.%s' % (builtins.__name__, obj.__name__)

bpython/test/test_curtsies_repl.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515

1616
from bpython.curtsiesfrontend import repl as curtsiesrepl
1717
from bpython.curtsiesfrontend import interpreter
18+
from bpython.curtsiesfrontend import events as bpythonevents
1819
from bpython import autocomplete
1920
from bpython import config
2021
from bpython import args
2122
from bpython._py3compat import py3
22-
from bpython.test import FixLanguageTestCase as TestCase, MagicIterMock, mock
23+
from bpython.test import (FixLanguageTestCase as TestCase, MagicIterMock, mock,
24+
builtin_target)
2325

2426

2527
def setup_config(conf):
@@ -307,5 +309,20 @@ def test_show_source_formatted(self):
307309
self.repl.show_source()
308310

309311

312+
class TestCurtsiesStartup(TestCase):
313+
314+
def setUp(self):
315+
self.repl = create_repl()
316+
os.environ['PYTHONSTARTUP'] = 'file'
317+
318+
def tearDown(self):
319+
del os.environ['PYTHONSTARTUP']
320+
321+
@mock.patch(builtin_target(open), mock.mock_open(read_data='a = 1\n'))
322+
def test_startup_event(self):
323+
self.repl.process_event(bpythonevents.RunStartupFileEvent())
324+
self.assertIn('a', self.repl.interp.locals)
325+
326+
310327
if __name__ == '__main__':
311328
unittest.main()

0 commit comments

Comments
 (0)