##// END OF EJS Templates
Merge pull request #4789 from ivanov/fix-embed...
Thomas Kluyver -
r14803:ae17b42b merge
parent child Browse files
Show More
@@ -0,0 +1,54 b''
1 """Test embedding of IPython"""
2
3 #-----------------------------------------------------------------------------
4 # Copyright (C) 2013 The IPython Development Team
5 #
6 # Distributed under the terms of the BSD License. The full license is in
7 # the file COPYING, distributed as part of this software.
8 #-----------------------------------------------------------------------------
9
10 #-----------------------------------------------------------------------------
11 # Imports
12 #-----------------------------------------------------------------------------
13
14 import sys
15 import nose.tools as nt
16 from IPython.utils.process import process_handler
17 from IPython.utils.tempdir import NamedFileInTemporaryDirectory
18
19 #-----------------------------------------------------------------------------
20 # Tests
21 #-----------------------------------------------------------------------------
22
23 _sample_embed = b"""
24 from __future__ import print_function
25 import IPython
26
27 a = 3
28 b = 14
29 print(a, '.', b)
30
31 IPython.embed()
32
33 print('bye!')
34 """
35
36 _exit = b"exit\r"
37
38 def test_ipython_embed():
39 """test that `IPython.embed()` works"""
40 with NamedFileInTemporaryDirectory('file_with_embed.py') as f:
41 f.write(_sample_embed)
42 f.flush()
43 f.close() # otherwise msft won't be able to read the file
44
45 # run `python file_with_embed.py`
46 cmd = [sys.executable, f.name]
47
48 out, p = process_handler(cmd, lambda p: (p.communicate(_exit), p))
49 std = out[0].decode('UTF-8')
50 nt.assert_equal(p.returncode, 0)
51 nt.assert_in('3 . 14', std)
52 nt.assert_in('IPython', std)
53 nt.assert_in('bye!', std)
54
@@ -505,31 +505,28 b' class Application(SingletonConfigurable):'
505
505
506 yield each config object in turn.
506 yield each config object in turn.
507 """
507 """
508
509 pyloader = PyFileConfigLoader(basefilename+'.py', path=path, log=log)
508 pyloader = PyFileConfigLoader(basefilename+'.py', path=path, log=log)
510 jsonloader = JSONFileConfigLoader(basefilename+'.json', path=path, log=log)
509 jsonloader = JSONFileConfigLoader(basefilename+'.json', path=path, log=log)
511 config_found = False
512 config = None
510 config = None
513 for loader in [pyloader, jsonloader]:
511 for loader in [pyloader, jsonloader]:
514 try:
512 try:
515 config = loader.load_config()
513 config = loader.load_config()
516 config_found = True
517 except ConfigFileNotFound:
514 except ConfigFileNotFound:
518 pass
515 pass
519 except Exception:
516 except Exception:
520 # try to get the full filename, but it will be empty in the
517 # try to get the full filename, but it will be empty in the
521 # unlikely event that the error raised before filefind finished
518 # unlikely event that the error raised before filefind finished
522 filename = loader.full_filename or filename
519 filename = loader.full_filename or basefilename
523 # problem while running the file
520 # problem while running the file
524 log.error("Exception while loading config file %s",
521 if log:
525 filename, exc_info=True)
522 log.error("Exception while loading config file %s",
523 filename, exc_info=True)
526 else:
524 else:
527 log.debug("Loaded config file: %s", loader.full_filename)
525 if log:
526 log.debug("Loaded config file: %s", loader.full_filename)
528 if config:
527 if config:
529 yield config
528 yield config
530
529
531 if not config_found:
532 raise ConfigFileNotFound('Neither .json, nor .py config file found.')
533 raise StopIteration
530 raise StopIteration
534
531
535
532
@@ -27,7 +27,7 b' else:'
27 from ._process_posix import _find_cmd, system, getoutput, arg_split
27 from ._process_posix import _find_cmd, system, getoutput, arg_split
28
28
29
29
30 from ._process_common import getoutputerror, get_output_error_code
30 from ._process_common import getoutputerror, get_output_error_code, process_handler
31 from . import py3compat
31 from . import py3compat
32
32
33 #-----------------------------------------------------------------------------
33 #-----------------------------------------------------------------------------
General Comments 0
You need to be logged in to leave comments. Login now