Skip to content

Commit ed466dd

Browse files
committed
Include error message in exceptions raised from mocks
1 parent 2d1529a commit ed466dd

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

supervisor/tests/test_dispatchers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,8 @@ def test_handle_write_event_epipe_raised(self):
639639
dispatcher = self._makeOne(process)
640640
dispatcher.input_buffer = 'halloooo'
641641
import errno
642-
options.write_exception = OSError(errno.EPIPE)
642+
options.write_exception = OSError(errno.EPIPE,
643+
os.strerror(errno.EPIPE))
643644
dispatcher.handle_write_event()
644645
self.assertEqual(dispatcher.input_buffer, b'')
645646
self.assertTrue(options.logger.data[0].startswith(
@@ -653,7 +654,8 @@ def test_handle_write_event_uncaught_raised(self):
653654
dispatcher = self._makeOne(process)
654655
dispatcher.input_buffer = 'halloooo'
655656
import errno
656-
options.write_exception = OSError(errno.EBADF)
657+
options.write_exception = OSError(errno.EBADF,
658+
os.strerror(errno.EBADF))
657659
self.assertRaises(OSError, dispatcher.handle_write_event)
658660

659661
def test_handle_write_event_over_os_limit(self):

supervisor/tests/test_process.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ def test_spawn_fail_check_execv_args(self):
225225

226226
def test_spawn_fail_make_pipes_emfile(self):
227227
options = DummyOptions()
228-
options.make_pipes_exception = OSError(errno.EMFILE)
228+
options.make_pipes_exception = OSError(errno.EMFILE,
229+
os.strerror(errno.EMFILE))
229230
config = DummyPConfig(options, 'good', '/good/filename')
230231
instance = self._makeOne(config)
231232
from supervisor.states import ProcessStates
@@ -250,7 +251,8 @@ def test_spawn_fail_make_pipes_emfile(self):
250251

251252
def test_spawn_fail_make_pipes_other(self):
252253
options = DummyOptions()
253-
options.make_pipes_exception = OSError(errno.EPERM)
254+
options.make_pipes_exception = OSError(errno.EPERM,
255+
os.strerror(errno.EPERM))
254256
config = DummyPConfig(options, 'good', '/good/filename')
255257
instance = self._makeOne(config)
256258
from supervisor.states import ProcessStates
@@ -301,7 +303,8 @@ def raise_eisdir(envelope):
301303

302304
def test_spawn_fork_fail_eagain(self):
303305
options = DummyOptions()
304-
options.fork_exception = OSError(errno.EAGAIN)
306+
options.fork_exception = OSError(errno.EAGAIN,
307+
os.strerror(errno.EAGAIN))
305308
config = DummyPConfig(options, 'good', '/good/filename')
306309
instance = self._makeOne(config)
307310
from supervisor.states import ProcessStates
@@ -327,7 +330,8 @@ def test_spawn_fork_fail_eagain(self):
327330

328331
def test_spawn_fork_fail_other(self):
329332
options = DummyOptions()
330-
options.fork_exception = OSError(errno.EPERM)
333+
options.fork_exception = OSError(errno.EPERM,
334+
os.strerror(errno.EPERM))
331335
config = DummyPConfig(options, 'good', '/good/filename')
332336
instance = self._makeOne(config)
333337
from supervisor.states import ProcessStates
@@ -436,7 +440,8 @@ def test_spawn_as_child_sets_umask(self):
436440
def test_spawn_as_child_cwd_fail(self):
437441
options = DummyOptions()
438442
options.forkpid = 0
439-
options.chdir_exception = OSError(errno.ENOENT)
443+
options.chdir_exception = OSError(errno.ENOENT,
444+
os.strerror(errno.ENOENT))
440445
config = DummyPConfig(options, 'good', '/good/filename',
441446
directory='/tmp')
442447
instance = self._makeOne(config)
@@ -458,7 +463,8 @@ def test_spawn_as_child_cwd_fail(self):
458463
def test_spawn_as_child_execv_fail_oserror(self):
459464
options = DummyOptions()
460465
options.forkpid = 0
461-
options.execv_exception = OSError(errno.EPERM)
466+
options.execv_exception = OSError(errno.EPERM,
467+
os.strerror(errno.EPERM))
462468
config = DummyPConfig(options, 'good', '/good/filename')
463469
instance = self._makeOne(config)
464470
result = instance.spawn()
@@ -641,7 +647,8 @@ def test_write_dispatcher_flush_raises_epipe(self):
641647
options.forkpid = 1
642648
instance.spawn()
643649
stdin_fd = instance.pipes['stdin']
644-
instance.dispatchers[stdin_fd].flush_exception = OSError(errno.EPIPE)
650+
instance.dispatchers[stdin_fd].flush_exception = OSError(errno.EPIPE,
651+
os.strerror(errno.EPIPE))
645652
self.assertRaises(OSError, instance.write, sent)
646653

647654
def _dont_test_spawn_and_kill(self):
@@ -853,7 +860,8 @@ def test_kill_from_running(self):
853860
def test_kill_from_running_error(self):
854861
options = DummyOptions()
855862
config = DummyPConfig(options, 'test', '/test')
856-
options.kill_exception = OSError(errno.EPERM)
863+
options.kill_exception = OSError(errno.EPERM,
864+
os.strerror(errno.EPERM))
857865
instance = self._makeOne(config)
858866
L = []
859867
from supervisor.states import ProcessStates
@@ -1002,7 +1010,8 @@ def kill(pid, sig):
10021010
def test_signal_from_running_error(self):
10031011
options = DummyOptions()
10041012
config = DummyPConfig(options, 'test', '/test')
1005-
options.kill_exception = OSError(errno.EPERM)
1013+
options.kill_exception = OSError(errno.EPERM,
1014+
os.strerror(errno.EPERM))
10061015
instance = self._makeOne(config)
10071016
L = []
10081017
from supervisor.states import ProcessStates
@@ -2089,7 +2098,8 @@ def test_dispatch_pipe_error(self):
20892098
gconfig = DummyPGroupConfig(options, pconfigs=[pconfig1])
20902099
pool = self._makeOne(gconfig)
20912100
process1 = pool.processes['process1']
2092-
process1.write_exception = OSError(errno.EPIPE)
2101+
process1.write_exception = OSError(errno.EPIPE,
2102+
os.strerror(errno.EPIPE))
20932103
process1.listener_state = EventListenerStates.READY
20942104
event = DummyEvent()
20952105
pool._acceptEvent(event)

supervisor/tests/test_rpcinterfaces.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ def test_clearLog_unremoveable(self):
187187
from supervisor import xmlrpc
188188
options = DummyOptions()
189189
options.existing = [options.logfile]
190-
options.remove_exception = os.error(errno.EPERM)
190+
options.remove_exception = OSError(errno.EPERM,
191+
os.strerror(errno.EPERM))
191192
supervisord = DummySupervisor(options)
192193
interface = self._makeOne(supervisord)
193194
self.assertRaises(xmlrpc.RPCError, interface.clearLog)
@@ -1999,7 +2000,8 @@ def test_sendProcessStdin_raises_no_file_when_write_raises_epipe(self):
19992000
supervisord = PopulatedDummySupervisor(options, 'process1', pconfig1)
20002001
supervisord.set_procattr('process1', 'pid', 42)
20012002
supervisord.set_procattr('process1', 'killing', False)
2002-
supervisord.set_procattr('process1', 'write_exception', OSError(errno.EPIPE))
2003+
supervisord.set_procattr('process1', 'write_exception',
2004+
OSError(errno.EPIPE, os.strerror(errno.EPIPE)))
20032005
interface = self._makeOne(supervisord)
20042006
from supervisor import xmlrpc
20052007
self._assertRPCError(xmlrpc.Faults.NO_FILE,
@@ -2012,7 +2014,8 @@ def test_sendProcessStdin_reraises_other_oserrors(self):
20122014
supervisord = PopulatedDummySupervisor(options, 'process1', pconfig1)
20132015
supervisord.set_procattr('process1', 'pid', 42)
20142016
supervisord.set_procattr('process1', 'killing', False)
2015-
supervisord.set_procattr('process1', 'write_exception', OSError(errno.EINTR))
2017+
supervisord.set_procattr('process1', 'write_exception',
2018+
OSError(errno.EINTR, os.strerror(errno.EINTR)))
20162019
interface = self._makeOne(supervisord)
20172020
self.assertRaises(OSError,
20182021
interface.sendProcessStdin,

0 commit comments

Comments
 (0)