##// END OF EJS Templates
darker
Nikita Kniazev -
Show More
@@ -1,53 +1,56 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
22
23
23
24 class TestFileToRun(tt.TempFileMixin, unittest.TestCase):
24 class TestFileToRun(tt.TempFileMixin, unittest.TestCase):
25 """Test the behavior of the file_to_run parameter."""
25 """Test the behavior of the file_to_run parameter."""
26
26
27 def test_py_script_file_attribute(self):
27 def test_py_script_file_attribute(self):
28 """Test that `__file__` is set when running `ipython file.py`"""
28 """Test that `__file__` is set when running `ipython file.py`"""
29 src = "print(__file__)\n"
29 src = "print(__file__)\n"
30 self.mktmp(src)
30 self.mktmp(src)
31
31
32 err = None
32 err = None
33 tt.ipexec_validate(self.fname, self.fname, err)
33 tt.ipexec_validate(self.fname, self.fname, err)
34
34
35 def test_ipy_script_file_attribute(self):
35 def test_ipy_script_file_attribute(self):
36 """Test that `__file__` is set when running `ipython file.ipy`"""
36 """Test that `__file__` is set when running `ipython file.ipy`"""
37 src = "print(__file__)\n"
37 src = "print(__file__)\n"
38 self.mktmp(src, ext='.ipy')
38 self.mktmp(src, ext='.ipy')
39
39
40 err = None
40 err = None
41 tt.ipexec_validate(self.fname, self.fname, err)
41 tt.ipexec_validate(self.fname, self.fname, err)
42
42
43 # The commands option to ipexec_validate doesn't work on Windows, and it
43 # The commands option to ipexec_validate doesn't work on Windows, and it
44 # doesn't seem worth fixing
44 # doesn't seem worth fixing
45 @dec.skip_win32
45 @dec.skip_win32
46 def test_py_script_file_attribute_interactively(self):
46 def test_py_script_file_attribute_interactively(self):
47 """Test that `__file__` is not set after `ipython -i file.py`"""
47 """Test that `__file__` is not set after `ipython -i file.py`"""
48 src = "True\n"
48 src = "True\n"
49 self.mktmp(src)
49 self.mktmp(src)
50
50
51 out, err = tt.ipexec(self.fname, options=['-i'],
51 out, err = tt.ipexec(
52 commands=['"__file__" in globals()', 'print(123)', 'exit()'])
52 self.fname,
53 options=["-i"],
54 commands=['"__file__" in globals()', "print(123)", "exit()"],
55 )
53 assert "False" in out, f"Subprocess stderr:\n{err}\n-----"
56 assert "False" in out, f"Subprocess stderr:\n{err}\n-----"
General Comments 0
You need to be logged in to leave comments. Login now