##// END OF EJS Templates
raise an error when user tries to open a standard stream...
Osher De Paz -
Show More
@@ -1255,6 +1255,15 b' class InteractiveShell(SingletonConfigurable):'
1255 1255 if user_ns is None:
1256 1256 user_ns = user_module.__dict__
1257 1257
1258 @functools.wraps(io_open)
1259 def modified_open(file, *args, **kwargs):
1260 if file in {0, 1, 2}:
1261 raise ValueError(f"IPython won't let you open fd={file} by default")
1262
1263 return io_open(file, *args, **kwargs)
1264
1265 user_ns["open"] = modified_open
1266
1258 1267 return user_module, user_ns
1259 1268
1260 1269 def init_sys_modules(self):
@@ -103,6 +103,21 b' class InteractiveShellTestCase(unittest.TestCase):'
103 103 res = ip.run_cell("raise = 3")
104 104 self.assertIsInstance(res.error_before_exec, SyntaxError)
105 105
106 def test_open_standard_input_stream(self):
107 ip.init_create_namespaces()
108 res = ip.run_cell("open(0)")
109 self.assertIsInstance(res.error_in_exec, ValueError)
110
111 def test_open_standard_output_stream(self):
112 ip.init_create_namespaces()
113 res = ip.run_cell("open(1)")
114 self.assertIsInstance(res.error_in_exec, ValueError)
115
116 def test_open_standard_error_stream(self):
117 ip.init_create_namespaces()
118 res = ip.run_cell("open(2)")
119 self.assertIsInstance(res.error_in_exec, ValueError)
120
106 121 def test_In_variable(self):
107 122 "Verify that In variable grows with user input (GH-284)"
108 123 oldlen = len(ip.user_ns['In'])
General Comments 0
You need to be logged in to leave comments. Login now