##// END OF EJS Templates
Add test for `__file__` behavior in `ipython <file>`
Bradley M. Froehle -
Show More
@@ -0,0 +1,51 b''
1 # -*- coding: utf-8 -*-
2 """Tests for shellapp module.
3
4 Authors
5 -------
6 * Bradley Froehle
7 """
8 #-----------------------------------------------------------------------------
9 # Copyright (C) 2012 The IPython Development Team
10 #
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
13 #-----------------------------------------------------------------------------
14
15 #-----------------------------------------------------------------------------
16 # Imports
17 #-----------------------------------------------------------------------------
18 import unittest
19
20 import nose.tools as nt
21
22 from IPython.testing import decorators as dec
23 from IPython.testing import tools as tt
24
25 class TestFileToRun(unittest.TestCase, tt.TempFileMixin):
26 """Test the behavior of the file_to_run parameter."""
27
28 def test_py_script_file_attribute(self):
29 """Test that `__file__` is set when running `ipython file.py`"""
30 src = "print(__file__)\n"
31 self.mktmp(src)
32
33 if dec.module_not_available('sqlite3'):
34 err = 'WARNING: IPython History requires SQLite, your history will not be saved\n'
35 else:
36 err = None
37 tt.ipexec_validate(self.fname, self.fname, err)
38
39 def test_ipy_script_file_attribute(self):
40 """Test that `__file__` is set when running `ipython file.ipy`"""
41 src = "print(__file__)\n"
42 self.mktmp(src, ext='.ipy')
43
44 if dec.module_not_available('sqlite3'):
45 err = 'WARNING: IPython History requires SQLite, your history will not be saved\n'
46 else:
47 err = None
48 tt.ipexec_validate(self.fname, self.fname, err)
49
50 # Ideally we would also test that `__file__` is not set in the
51 # interactive namespace after running `ipython -i <file>`.
General Comments 0
You need to be logged in to leave comments. Login now