Skip to content

Commit 75fe346

Browse files
committed
Replace magic numbers with errno constants
1 parent 23e4b8e commit 75fe346

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

supervisor/tests/base.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
_NOW = 1151365354
22
_TIMEFORMAT = '%b %d %I:%M %p'
33

4-
from functools import total_ordering
4+
import errno
5+
import functools
6+
import os
57

68
from supervisor.compat import Fault
79
from supervisor.compat import as_bytes
@@ -215,7 +217,7 @@ def _exit(self, code):
215217
def execve(self, filename, argv, environment):
216218
self.execve_called = True
217219
if self.execv_error:
218-
if self.execv_error == 1:
220+
if self.execv_error == errno.EPERM:
219221
raise OSError(self.execv_error)
220222
else:
221223
raise RuntimeError(self.execv_error)
@@ -374,7 +376,7 @@ def config(self):
374376
def get_socket(self):
375377
return DummySocket(self._config.fd)
376378

377-
@total_ordering
379+
@functools.total_ordering
378380
class DummyProcess(object):
379381
# Initial state; overridden by instance variables
380382
pid = 0 # Subprocess pid; 0 when not running
@@ -1040,7 +1042,7 @@ def __init__(self, options, name='whatever', priority=999, pconfigs=None, socket
10401042
DummyPGroupConfig.__init__(self, options, name, priority, pconfigs)
10411043
self.socket_config = socket_config
10421044

1043-
@total_ordering
1045+
@functools.total_ordering
10441046
class DummyProcessGroup(object):
10451047
def __init__(self, config):
10461048
self.config = config

supervisor/tests/test_process.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def test_spawn_fail_make_pipes_emfile(self):
250250

251251
def test_spawn_fail_make_pipes_other(self):
252252
options = DummyOptions()
253-
options.make_pipes_error = 1
253+
options.make_pipes_error = errno.EPERM
254254
config = DummyPConfig(options, 'good', '/good/filename')
255255
instance = self._makeOne(config)
256256
from supervisor.states import ProcessStates
@@ -327,7 +327,7 @@ def test_spawn_fork_fail_eagain(self):
327327

328328
def test_spawn_fork_fail_other(self):
329329
options = DummyOptions()
330-
options.fork_error = 1
330+
options.fork_error = errno.EPERM
331331
config = DummyPConfig(options, 'good', '/good/filename')
332332
instance = self._makeOne(config)
333333
from supervisor.states import ProcessStates
@@ -436,7 +436,7 @@ def test_spawn_as_child_sets_umask(self):
436436
def test_spawn_as_child_cwd_fail(self):
437437
options = DummyOptions()
438438
options.forkpid = 0
439-
options.chdir_error = 2
439+
options.chdir_error = errno.ENOENT
440440
config = DummyPConfig(options, 'good', '/good/filename',
441441
directory='/tmp')
442442
instance = self._makeOne(config)
@@ -458,7 +458,7 @@ def test_spawn_as_child_cwd_fail(self):
458458
def test_spawn_as_child_execv_fail_oserror(self):
459459
options = DummyOptions()
460460
options.forkpid = 0
461-
options.execv_error = 1
461+
options.execv_error = errno.EPERM
462462
config = DummyPConfig(options, 'good', '/good/filename')
463463
instance = self._makeOne(config)
464464
result = instance.spawn()
@@ -477,7 +477,7 @@ def test_spawn_as_child_execv_fail_oserror(self):
477477
def test_spawn_as_child_execv_fail_runtime_error(self):
478478
options = DummyOptions()
479479
options.forkpid = 0
480-
options.execv_error = 2
480+
options.execv_error = errno.ENOENT
481481
config = DummyPConfig(options, 'good', '/good/filename')
482482
instance = self._makeOne(config)
483483
result = instance.spawn()
@@ -815,7 +815,7 @@ def test_kill_nopid(self):
815815
def test_kill_error(self):
816816
options = DummyOptions()
817817
config = DummyPConfig(options, 'test', '/test')
818-
options.kill_error = 1
818+
options.kill_error = errno.EPERM
819819
instance = self._makeOne(config)
820820
L = []
821821
from supervisor.states import ProcessStates
@@ -1000,7 +1000,7 @@ def kill(pid, sig):
10001000
def test_signal_error(self):
10011001
options = DummyOptions()
10021002
config = DummyPConfig(options, 'test', '/test')
1003-
options.kill_error = 1
1003+
options.kill_error = errno.EPERM
10041004
instance = self._makeOne(config)
10051005
L = []
10061006
from supervisor.states import ProcessStates

0 commit comments

Comments
 (0)