Show More
@@ -19,6 +19,7 b' import os' | |||||
19 | import time |
|
19 | import time | |
20 | from _thread import interrupt_main # Py 3 |
|
20 | from _thread import interrupt_main # Py 3 | |
21 | import threading |
|
21 | import threading | |
|
22 | from unittest import SkipTest | |||
22 |
|
23 | |||
23 | import nose.tools as nt |
|
24 | import nose.tools as nt | |
24 |
|
25 | |||
@@ -110,10 +111,9 b' class SubProcessTestCase(tt.TempFileMixin):' | |||||
110 | status = system('%s -c "import sys"' % python) |
|
111 | status = system('%s -c "import sys"' % python) | |
111 | self.assertEqual(status, 0) |
|
112 | self.assertEqual(status, 0) | |
112 |
|
113 | |||
113 |
def |
|
114 | def assert_interrupts(self, command): | |
114 | """ |
|
115 | """ | |
115 | When interrupted in the way ipykernel interrupts IPython, the |
|
116 | Interrupt a subprocess after a second. | |
116 | subprocess is interrupted. |
|
|||
117 | """ |
|
117 | """ | |
118 | if threading.main_thread() != threading.current_thread(): |
|
118 | if threading.main_thread() != threading.current_thread(): | |
119 | raise nt.SkipTest("Can't run this test if not in main thread.") |
|
119 | raise nt.SkipTest("Can't run this test if not in main thread.") | |
@@ -126,17 +126,28 b' class SubProcessTestCase(tt.TempFileMixin):' | |||||
126 | threading.Thread(target=interrupt).start() |
|
126 | threading.Thread(target=interrupt).start() | |
127 | start = time.time() |
|
127 | start = time.time() | |
128 | try: |
|
128 | try: | |
129 | status = system('%s -c "import time; time.sleep(5)"' % python) |
|
129 | result = command() | |
130 | except KeyboardInterrupt: |
|
130 | except KeyboardInterrupt: | |
131 | # Success! |
|
131 | # Success! | |
132 | return |
|
132 | return | |
133 | end = time.time() |
|
133 | end = time.time() | |
134 | self.assertNotEqual( |
|
|||
135 | status, 0, "The process wasn't interrupted. Status: %s" % (status,) |
|
|||
136 | ) |
|
|||
137 | self.assertTrue( |
|
134 | self.assertTrue( | |
138 | end - start < 2, "Process didn't die quickly: %s" % (end - start) |
|
135 | end - start < 2, "Process didn't die quickly: %s" % (end - start) | |
139 | ) |
|
136 | ) | |
|
137 | return result | |||
|
138 | ||||
|
139 | def test_system_interrupt(self): | |||
|
140 | """ | |||
|
141 | When interrupted in the way ipykernel interrupts IPython, the | |||
|
142 | subprocess is interrupted. | |||
|
143 | """ | |||
|
144 | def command(): | |||
|
145 | return system('%s -c "import time; time.sleep(5)"' % python) | |||
|
146 | ||||
|
147 | status = self.assert_interrupts(command) | |||
|
148 | self.assertNotEqual( | |||
|
149 | status, 0, "The process wasn't interrupted. Status: %s" % (status,) | |||
|
150 | ) | |||
140 |
|
151 | |||
141 | def test_getoutput(self): |
|
152 | def test_getoutput(self): | |
142 | out = getoutput('%s "%s"' % (python, self.fname)) |
|
153 | out = getoutput('%s "%s"' % (python, self.fname)) | |
@@ -146,6 +157,17 b' class SubProcessTestCase(tt.TempFileMixin):' | |||||
146 | except AssertionError: |
|
157 | except AssertionError: | |
147 | self.assertEqual(out, 'on stdouton stderr') |
|
158 | self.assertEqual(out, 'on stdouton stderr') | |
148 |
|
159 | |||
|
160 | def test_getoutput_interrupt(self): | |||
|
161 | """ | |||
|
162 | When interrupted in the way ipykernel interrupts IPython, the | |||
|
163 | subprocess is interrupted. | |||
|
164 | """ | |||
|
165 | raise SkipTest("This fails on POSIX too, revisit in future.") | |||
|
166 | def command(): | |||
|
167 | return getoutput('%s -c "import time; time.sleep(5)"' % (python, )) | |||
|
168 | ||||
|
169 | self.assert_interrupts(command) | |||
|
170 | ||||
149 | def test_getoutput_quoted(self): |
|
171 | def test_getoutput_quoted(self): | |
150 | out = getoutput('%s -c "print (1)"' % python) |
|
172 | out = getoutput('%s -c "print (1)"' % python) | |
151 | self.assertEqual(out.strip(), '1') |
|
173 | self.assertEqual(out.strip(), '1') |
General Comments 0
You need to be logged in to leave comments.
Login now