##// END OF EJS Templates
test_py_script_file_attribute_interactively: Coverage fix
Nikita Kniazev -
Show More
@@ -1,57 +1,53 b''
1 1 # -*- coding: utf-8 -*-
2 2 """Tests for shellapp module.
3 3
4 4 Authors
5 5 -------
6 6 * Bradley Froehle
7 7 """
8 8 #-----------------------------------------------------------------------------
9 9 # Copyright (C) 2012 The IPython Development Team
10 10 #
11 11 # Distributed under the terms of the BSD License. The full license is in
12 12 # the file COPYING, distributed as part of this software.
13 13 #-----------------------------------------------------------------------------
14 14
15 15 #-----------------------------------------------------------------------------
16 16 # Imports
17 17 #-----------------------------------------------------------------------------
18 18 import unittest
19 19
20 20 from IPython.testing import decorators as dec
21 21 from IPython.testing import tools as tt
22 22
23 23
24 24 class TestFileToRun(tt.TempFileMixin, unittest.TestCase):
25 25 """Test the behavior of the file_to_run parameter."""
26 26
27 27 def test_py_script_file_attribute(self):
28 28 """Test that `__file__` is set when running `ipython file.py`"""
29 29 src = "print(__file__)\n"
30 30 self.mktmp(src)
31 31
32 32 err = None
33 33 tt.ipexec_validate(self.fname, self.fname, err)
34 34
35 35 def test_ipy_script_file_attribute(self):
36 36 """Test that `__file__` is set when running `ipython file.ipy`"""
37 37 src = "print(__file__)\n"
38 38 self.mktmp(src, ext='.ipy')
39 39
40 40 err = None
41 41 tt.ipexec_validate(self.fname, self.fname, err)
42 42
43 43 # The commands option to ipexec_validate doesn't work on Windows, and it
44 44 # doesn't seem worth fixing
45 45 @dec.skip_win32
46 46 def test_py_script_file_attribute_interactively(self):
47 47 """Test that `__file__` is not set after `ipython -i file.py`"""
48 48 src = "True\n"
49 49 self.mktmp(src)
50 50
51 51 out, err = tt.ipexec(self.fname, options=['-i'],
52 52 commands=['"__file__" in globals()', 'print(123)', 'exit()'])
53 if 'False' not in out:
54 print("Subprocess stderr:")
55 print(err)
56 print('-----')
57 raise AssertionError("'False' not found in %r" % out)
53 assert "False" in out, f"Subprocess stderr:\n{err}\n-----"
General Comments 0
You need to be logged in to leave comments. Login now