| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,7 +45,8 @@ def main(args=None, locals_=None, banner=None): | |||
| 45 | 45 | interp = None | |
| 46 | 46 | paste = None | |
| 47 | 47 | if exec_args: | |
| 48 | - assert options, "don't pass in exec_args without options" | ||
| 48 | + if not options: | ||
| 49 | + raise ValueError("don't pass in exec_args without options") | ||
| 49 | 50 | exit_value = 0 | |
| 50 | 51 | if options.type: | |
| 51 | 52 | paste = curtsies.events.PasteEvent() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,17 @@ | |||
| 1 | + import os | ||
| 2 | + import sys | ||
| 3 | + import unittest | ||
| 4 | + from mock import Mock, MagicMock | ||
| 5 | + try: | ||
| 6 | + from unittest import skip | ||
| 7 | + except ImportError: | ||
| 8 | + def skip(f): | ||
| 9 | + return lambda self: None | ||
| 10 | + | ||
| 11 | + from bpython import config, repl, cli, autocomplete | ||
| 12 | + | ||
| 13 | + class TestFutureImports(unittest.TestCase): | ||
| 14 | + | ||
| 15 | + def test_interactive(self): | ||
| 16 | + pass | ||
| 17 | + | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,7 +18,6 @@ def setup_config(): | |||
| 18 | 18 | ||
| 19 | 19 | class TestCurtsiesPainting(FormatStringTest): | |
| 20 | 20 | def setUp(self): | |
| 21 | - self.refresh_requests = [] | ||
| 22 | 21 | self.repl = Repl(config=setup_config()) | |
| 23 | 22 | self.repl.rl_history = History() # clear history | |
| 24 | 23 | self.repl.height, self.repl.width = (5, 10) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,10 +1,22 @@ | |||
| 1 | - import unittest | ||
| 2 | - import sys | ||
| 1 | + import code | ||
| 3 | 2 | import os | |
| 3 | + import sys | ||
| 4 | + import tempfile | ||
| 5 | + from contextlib import contextmanager | ||
| 6 | + from StringIO import StringIO | ||
| 7 | + | ||
| 8 | + import unittest | ||
| 9 | + try: | ||
| 10 | + from unittest import skip | ||
| 11 | + except ImportError: | ||
| 12 | + def skip(f): | ||
| 13 | + return lambda self: None | ||
| 14 | + | ||
| 4 | 15 | py3 = (sys.version_info[0] == 3) | |
| 5 | 16 | ||
| 6 | - from bpython.curtsiesfrontend import repl | ||
| 17 | + from bpython.curtsiesfrontend import repl as curtsiesrepl | ||
| 7 | 18 | from bpython import config | |
| 19 | + from bpython import args | ||
| 8 | 20 | ||
| 9 | 21 | def setup_config(conf): | |
| 10 | 22 | config_struct = config.Struct() | |
@@ -18,11 +30,7 @@ def setup_config(conf): | |||
| 18 | 30 | class TestCurtsiesRepl(unittest.TestCase): | |
| 19 | 31 | ||
| 20 | 32 | def setUp(self): | |
| 21 | - self.config = setup_config({'editor':'true'}) | ||
| 22 | - self.repl = repl.Repl(config=self.config) | ||
| 23 | - os.environ['PAGER'] = 'true' | ||
| 24 | - self.repl.width = 50 | ||
| 25 | - self.repl.height = 20 | ||
| 33 | + self.repl = create_repl() | ||
| 26 | 34 | ||
| 27 | 35 | def test_buffer_finished_will_parse(self): | |
| 28 | 36 | self.repl.buffer = ['1 + 1'] | |
@@ -43,6 +51,48 @@ def test_external_communication(self): | |||
| 43 | 51 | self.repl.send_current_block_to_external_editor() | |
| 44 | 52 | self.repl.send_session_to_external_editor() | |
| 45 | 53 | ||
| 54 | + @contextmanager # from http://stackoverflow.com/a/17981937/398212 - thanks @rkennedy | ||
| 55 | + def captured_output(): | ||
| 56 | + new_out, new_err = StringIO(), StringIO() | ||
| 57 | + old_out, old_err = sys.stdout, sys.stderr | ||
| 58 | + try: | ||
| 59 | + sys.stdout, sys.stderr = new_out, new_err | ||
| 60 | + yield sys.stdout, sys.stderr | ||
| 61 | + finally: | ||
| 62 | + sys.stdout, sys.stderr = old_out, old_err | ||
| 63 | + | ||
| 64 | + def create_repl(**kwargs): | ||
| 65 | + config = setup_config({'editor':'true'}) | ||
| 66 | + repl = curtsiesrepl.Repl(config=config, **kwargs) | ||
| 67 | + os.environ['PAGER'] = 'true' | ||
| 68 | + repl.width = 50 | ||
| 69 | + repl.height = 20 | ||
| 70 | + return repl | ||
| 71 | + | ||
| 72 | + class TestFutureImports(unittest.TestCase): | ||
| 73 | + | ||
| 74 | + def test_repl(self): | ||
| 75 | + repl = create_repl() | ||
| 76 | + with captured_output() as (out, err): | ||
| 77 | + repl.push('from __future__ import division') | ||
| 78 | + repl.push('1 / 2') | ||
| 79 | + self.assertEqual(out.getvalue(), '0.5\n') | ||
| 80 | + | ||
| 81 | + @skip('Failing - this is issue #369') | ||
| 82 | + def test_interactive(self): | ||
| 83 | + interp = code.InteractiveInterpreter(locals={}) | ||
| 84 | + with captured_output() as (out, err): | ||
| 85 | + with tempfile.NamedTemporaryFile(suffix='.py') as f: | ||
| 86 | + f.write('from __future__ import division\n') | ||
| 87 | + f.write('print 1/2\n') | ||
| 88 | + f.flush() | ||
| 89 | + args.exec_code(interp, [f.name]) | ||
| 90 | + | ||
| 91 | + repl = create_repl(interp=interp) | ||
| 92 | + repl.push('1 / 2') | ||
| 93 | + | ||
| 94 | + self.assertEqual(out.getvalue(), '0.5\n0.5\n') | ||
| 95 | + | ||
| 46 | 96 | ||
| 47 | 97 | if __name__ == '__main__': | |
| 48 | 98 | unittest.main() | |
| Back | FazBrowse Home | New Git URL |
0 commit comments