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