Merge pull request #1966 from jwilk-forks/errno

Tests: Don't hardcode errno constants
This commit is contained in:
Paul Beckingham 2018-02-17 10:00:47 -05:00 committed by GitHub
commit dc5514254a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 6 deletions

View file

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import division from __future__ import division
import errno
import os import os
from sys import stderr from sys import stderr
import shutil import shutil
@ -144,7 +145,7 @@ class Hooks(object):
shutil.rmtree(self.hookdir) shutil.rmtree(self.hookdir)
except OSError as e: except OSError as e:
# If the hookdir folder doesn't exist, no harm done and keep going # If the hookdir folder doesn't exist, no harm done and keep going
if e.errno != 2: if e.errno != errno.ENOENT:
raise raise
os.mkdir(self.hookdir) os.mkdir(self.hookdir)
@ -258,7 +259,7 @@ class Hook(object):
try: try:
os.remove(file) os.remove(file)
except OSError as e: except OSError as e:
if e.errno == 2: if e.errno == errno.ENOENT:
raise HookError("Hook with name {0} was not found on " raise HookError("Hook with name {0} was not found on "
"hooks/ folder".format(file)) "hooks/ folder".format(file))
else: else:

View file

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import atexit import atexit
import errno
import json import json
import os import os
import shlex import shlex
@ -274,7 +275,7 @@ class Task(object):
try: try:
shutil.rmtree(self.datadir) shutil.rmtree(self.datadir)
except OSError as e: except OSError as e:
if e.errno == 2: if e.errno == errno.ENOENT:
# Directory no longer exists # Directory no longer exists
pass pass
else: else:

View file

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import division, print_function from __future__ import division, print_function
import errno
import os import os
import tempfile import tempfile
import shutil import shutil
@ -310,7 +311,7 @@ class Taskd(object):
try: try:
shutil.rmtree(self.datadir) shutil.rmtree(self.datadir)
except OSError as e: except OSError as e:
if e.errno == 2: if e.errno == errno.ENOENT:
# Directory no longer exists # Directory no longer exists
pass pass
else: else:

View file

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import division from __future__ import division
import errno
import os import os
import sys import sys
import socket import socket
@ -212,8 +213,8 @@ def _get_output(arguments, timeout=None):
try: try:
os.kill(pid, signal.SIGABRT) os.kill(pid, signal.SIGABRT)
except OSError as e: except OSError as e:
# 3 means the process finished/died between last check and now # ESRCH means the process finished/died between last check and now
if e.errno != 3: if e.errno != errno.ESRCH:
raise raise
# Wait for process to finish (should die/exit after signal) # Wait for process to finish (should die/exit after signal)