Show More
@@ -1,53 +1,54 b'' | |||||
1 | """Test embedding of IPython""" |
|
1 | """Test embedding of IPython""" | |
2 |
|
2 | |||
3 | #----------------------------------------------------------------------------- |
|
3 | #----------------------------------------------------------------------------- | |
4 | # Copyright (C) 2013 The IPython Development Team |
|
4 | # Copyright (C) 2013 The IPython Development Team | |
5 | # |
|
5 | # | |
6 | # Distributed under the terms of the BSD License. The full license is in |
|
6 | # Distributed under the terms of the BSD License. The full license is in | |
7 | # the file COPYING, distributed as part of this software. |
|
7 | # the file COPYING, distributed as part of this software. | |
8 | #----------------------------------------------------------------------------- |
|
8 | #----------------------------------------------------------------------------- | |
9 |
|
9 | |||
10 | #----------------------------------------------------------------------------- |
|
10 | #----------------------------------------------------------------------------- | |
11 | # Imports |
|
11 | # Imports | |
12 | #----------------------------------------------------------------------------- |
|
12 | #----------------------------------------------------------------------------- | |
13 |
|
13 | |||
14 | import sys |
|
14 | import sys | |
15 | import nose.tools as nt |
|
15 | import nose.tools as nt | |
16 | from IPython.utils.process import process_handler |
|
16 | from IPython.utils.process import process_handler | |
17 | from IPython.utils.tempdir import NamedFileInTemporaryDirectory |
|
17 | from IPython.utils.tempdir import NamedFileInTemporaryDirectory | |
18 |
|
18 | |||
19 | #----------------------------------------------------------------------------- |
|
19 | #----------------------------------------------------------------------------- | |
20 | # Tests |
|
20 | # Tests | |
21 | #----------------------------------------------------------------------------- |
|
21 | #----------------------------------------------------------------------------- | |
22 |
|
22 | |||
23 | _sample_embed = b""" |
|
23 | _sample_embed = b""" | |
24 | from __future__ import print_function |
|
24 | from __future__ import print_function | |
25 | import IPython |
|
25 | import IPython | |
26 |
|
26 | |||
27 | a = 3 |
|
27 | a = 3 | |
28 | b = 14 |
|
28 | b = 14 | |
29 | print(a, '.', b) |
|
29 | print(a, '.', b) | |
30 |
|
30 | |||
31 | IPython.embed() |
|
31 | IPython.embed() | |
32 |
|
32 | |||
33 | print('bye!') |
|
33 | print('bye!') | |
34 | """ |
|
34 | """ | |
35 |
|
35 | |||
36 | _exit = b"exit\r" |
|
36 | _exit = b"exit\r" | |
37 |
|
37 | |||
38 | def test_ipython_embed(): |
|
38 | def test_ipython_embed(): | |
39 | """test that `IPython.embed()` works""" |
|
39 | """test that `IPython.embed()` works""" | |
40 | with NamedFileInTemporaryDirectory('file_with_embed.py') as f: |
|
40 | with NamedFileInTemporaryDirectory('file_with_embed.py') as f: | |
41 | f.write(_sample_embed) |
|
41 | f.write(_sample_embed) | |
42 | f.flush() |
|
42 | f.flush() | |
|
43 | f.close() # otherwise msft won't be able to read the file | |||
43 |
|
44 | |||
44 | # run `python file_with_embed.py` |
|
45 | # run `python file_with_embed.py` | |
45 | cmd = [sys.executable, f.name] |
|
46 | cmd = [sys.executable, f.name] | |
46 |
|
47 | |||
47 | out, p = process_handler(cmd, lambda p: (p.communicate(_exit), p)) |
|
48 | out, p = process_handler(cmd, lambda p: (p.communicate(_exit), p)) | |
48 | std = out[0].decode('UTF-8') |
|
49 | std = out[0].decode('UTF-8') | |
49 | nt.assert_equal(p.returncode, 0) |
|
50 | nt.assert_equal(p.returncode, 0) | |
50 | nt.assert_in('3 . 14', std) |
|
51 | nt.assert_in('3 . 14', std) | |
51 | nt.assert_in('IPython', std) |
|
52 | nt.assert_in('IPython', std) | |
52 | nt.assert_in('bye!', std) |
|
53 | nt.assert_in('bye!', std) | |
53 |
|
54 |
General Comments 0
You need to be logged in to leave comments.
Login now