Show More
@@ -1,64 +1,68 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | """Tests for shellapp module. |
|
2 | """Tests for shellapp module. | |
3 |
|
3 | |||
4 | Authors |
|
4 | Authors | |
5 | ------- |
|
5 | ------- | |
6 | * Bradley Froehle |
|
6 | * Bradley Froehle | |
7 | """ |
|
7 | """ | |
8 | #----------------------------------------------------------------------------- |
|
8 | #----------------------------------------------------------------------------- | |
9 | # Copyright (C) 2012 The IPython Development Team |
|
9 | # Copyright (C) 2012 The IPython Development Team | |
10 | # |
|
10 | # | |
11 | # Distributed under the terms of the BSD License. The full license is in |
|
11 | # Distributed under the terms of the BSD License. The full license is in | |
12 | # the file COPYING, distributed as part of this software. |
|
12 | # the file COPYING, distributed as part of this software. | |
13 | #----------------------------------------------------------------------------- |
|
13 | #----------------------------------------------------------------------------- | |
14 |
|
14 | |||
15 | #----------------------------------------------------------------------------- |
|
15 | #----------------------------------------------------------------------------- | |
16 | # Imports |
|
16 | # Imports | |
17 | #----------------------------------------------------------------------------- |
|
17 | #----------------------------------------------------------------------------- | |
18 | import unittest |
|
18 | import unittest | |
19 |
|
19 | |||
20 | from IPython.testing import decorators as dec |
|
20 | from IPython.testing import decorators as dec | |
21 | from IPython.testing import tools as tt |
|
21 | from IPython.testing import tools as tt | |
22 | from IPython.utils.py3compat import PY3 |
|
22 | from IPython.utils.py3compat import PY3 | |
23 |
|
23 | |||
24 | sqlite_err_maybe = dec.module_not_available('sqlite3') |
|
24 | sqlite_err_maybe = dec.module_not_available('sqlite3') | |
25 | SQLITE_NOT_AVAILABLE_ERROR = ('WARNING: IPython History requires SQLite,' |
|
25 | SQLITE_NOT_AVAILABLE_ERROR = ('WARNING: IPython History requires SQLite,' | |
26 | ' your history will not be saved\n') |
|
26 | ' your history will not be saved\n') | |
27 |
|
27 | |||
28 | class TestFileToRun(unittest.TestCase, tt.TempFileMixin): |
|
28 | class TestFileToRun(unittest.TestCase, tt.TempFileMixin): | |
29 | """Test the behavior of the file_to_run parameter.""" |
|
29 | """Test the behavior of the file_to_run parameter.""" | |
30 |
|
30 | |||
31 | def test_py_script_file_attribute(self): |
|
31 | def test_py_script_file_attribute(self): | |
32 | """Test that `__file__` is set when running `ipython file.py`""" |
|
32 | """Test that `__file__` is set when running `ipython file.py`""" | |
33 | src = "print(__file__)\n" |
|
33 | src = "print(__file__)\n" | |
34 | self.mktmp(src) |
|
34 | self.mktmp(src) | |
35 |
|
35 | |||
36 | err = SQLITE_NOT_AVAILABLE_ERROR if sqlite_err_maybe else None |
|
36 | err = SQLITE_NOT_AVAILABLE_ERROR if sqlite_err_maybe else None | |
37 | tt.ipexec_validate(self.fname, self.fname, err) |
|
37 | tt.ipexec_validate(self.fname, self.fname, err) | |
38 |
|
38 | |||
39 | def test_ipy_script_file_attribute(self): |
|
39 | def test_ipy_script_file_attribute(self): | |
40 | """Test that `__file__` is set when running `ipython file.ipy`""" |
|
40 | """Test that `__file__` is set when running `ipython file.ipy`""" | |
41 | src = "print(__file__)\n" |
|
41 | src = "print(__file__)\n" | |
42 | self.mktmp(src, ext='.ipy') |
|
42 | self.mktmp(src, ext='.ipy') | |
43 |
|
43 | |||
44 | err = SQLITE_NOT_AVAILABLE_ERROR if sqlite_err_maybe else None |
|
44 | err = SQLITE_NOT_AVAILABLE_ERROR if sqlite_err_maybe else None | |
45 | tt.ipexec_validate(self.fname, self.fname, err) |
|
45 | tt.ipexec_validate(self.fname, self.fname, err) | |
46 |
|
46 | |||
|
47 | # The commands option to ipexec_validate doesn't work on Windows, and it | |||
|
48 | # doesn't seem worth fixing | |||
|
49 | @dec.skip_win32 | |||
47 | def test_py_script_file_attribute_interactively(self): |
|
50 | def test_py_script_file_attribute_interactively(self): | |
48 | """Test that `__file__` is not set after `ipython -i file.py`""" |
|
51 | """Test that `__file__` is not set after `ipython -i file.py`""" | |
49 | src = "True\n" |
|
52 | src = "True\n" | |
50 | self.mktmp(src) |
|
53 | self.mktmp(src) | |
51 |
|
54 | |||
52 | err = SQLITE_NOT_AVAILABLE_ERROR if sqlite_err_maybe else None |
|
55 | err = SQLITE_NOT_AVAILABLE_ERROR if sqlite_err_maybe else None | |
53 | tt.ipexec_validate(self.fname, 'False', err, options=['-i'], |
|
56 | tt.ipexec_validate(self.fname, 'False', err, options=['-i'], | |
54 | commands=['"__file__" in globals()', 'exit()']) |
|
57 | commands=['"__file__" in globals()', 'exit()']) | |
55 |
|
58 | |||
|
59 | @dec.skip_win32 | |||
56 | @dec.skipif(PY3) |
|
60 | @dec.skipif(PY3) | |
57 | def test_py_script_file_compiler_directive(self): |
|
61 | def test_py_script_file_compiler_directive(self): | |
58 | """Test `__future__` compiler directives with `ipython -i file.py`""" |
|
62 | """Test `__future__` compiler directives with `ipython -i file.py`""" | |
59 | src = "from __future__ import division\n" |
|
63 | src = "from __future__ import division\n" | |
60 | self.mktmp(src) |
|
64 | self.mktmp(src) | |
61 |
|
65 | |||
62 | err = SQLITE_NOT_AVAILABLE_ERROR if sqlite_err_maybe else None |
|
66 | err = SQLITE_NOT_AVAILABLE_ERROR if sqlite_err_maybe else None | |
63 | tt.ipexec_validate(self.fname, 'float', err, options=['-i'], |
|
67 | tt.ipexec_validate(self.fname, 'float', err, options=['-i'], | |
64 | commands=['type(1/2)', 'exit()']) |
|
68 | commands=['type(1/2)', 'exit()']) |
General Comments 0
You need to be logged in to leave comments.
Login now