summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Madden <jason+github@nextthought.com>2021-04-28 12:15:43 -0500
committerGitHub <noreply@github.com>2021-04-28 12:15:43 -0500
commitc6af10788779c6a7293d91a09661c6451abf8b60 (patch)
tree10022a60d0aba72b4f964f916ea120c1d2fe433f
parent44ce7ec3fb28a30cc9bc076083460325f9ebb92b (diff)
parenta74449ad5e7de34ca6cadedd062d9ee4307db911 (diff)
downloadtrollius-git-c6af10788779c6a7293d91a09661c6451abf8b60.tar.gz
Merge pull request #18 from jamadden/issue17
Make socket.error with errno EBADF get raised as OSError.
-rw-r--r--CHANGES.rst8
-rw-r--r--MANIFEST.in2
-rwxr-xr-xruntests.py4
-rw-r--r--setup.py5
-rw-r--r--tests/test_py33_exceptions.py35
-rw-r--r--trollius/py33_exceptions.py3
6 files changed, 54 insertions, 3 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
new file mode 100644
index 0000000..5082340
--- /dev/null
+++ b/CHANGES.rst
@@ -0,0 +1,8 @@
+=========
+ Changes
+=========
+
+2.2.1 (unreleased)
+==================
+
+- Properly reraise socket.error with an errno of EBADF as an OSError.
diff --git a/MANIFEST.in b/MANIFEST.in
index 5d4033f..017fcfb 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -14,3 +14,5 @@ include examples/*.py
include tests/*.crt tests/*.pem tests/*.key
include tests/*.py
+
+include *.rst
diff --git a/runtests.py b/runtests.py
index 541a47e..7eea28c 100755
--- a/runtests.py
+++ b/runtests.py
@@ -151,7 +151,7 @@ def randomize_tests(tests, seed):
random.shuffle(tests._tests)
-class TestsFinder:
+class TestsFinder(object):
def __init__(self, testsdir, includes=(), excludes=()):
self._testsdir = testsdir
@@ -167,7 +167,7 @@ class TestsFinder:
mods = [mod for mod, _ in load_modules(self._testsdir)]
for mod in mods:
for name in set(dir(mod)):
- if name.endswith('Tests'):
+ if name.endswith('Tests') or name.startswith('Test'):
self._test_factories.append(getattr(mod, name))
def load_tests(self):
diff --git a/setup.py b/setup.py
index 7abc9f9..20c654b 100644
--- a/setup.py
+++ b/setup.py
@@ -5,6 +5,9 @@ from setuptools import setup, Extension
with open("README.rst") as fp:
long_description = fp.read()
+with open('CHANGES.rst') as fp:
+ long_description += '\n\n' + fp.read()
+
extensions = []
if os.name == 'nt':
ext = Extension(
@@ -18,7 +21,7 @@ if sys.version_info < (3,):
setup(
name="trollius",
- version="2.2.post1",
+ version="2.2.1",
license="Apache License 2.0",
author='Victor Stinner',
author_email='victor.stinner@gmail.com',
diff --git a/tests/test_py33_exceptions.py b/tests/test_py33_exceptions.py
new file mode 100644
index 0000000..42fb4e2
--- /dev/null
+++ b/tests/test_py33_exceptions.py
@@ -0,0 +1,35 @@
+# -*- coding: utf-8 -*-
+"""
+Tests for py33_exceptions.
+
+"""
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import print_function
+
+
+import unittest
+from trollius import py33_exceptions
+
+class TestWrapErrors(unittest.TestCase):
+
+ def test_ebadf_wrapped_to_OSError(self):
+ # https://github.com/jamadden/trollius/issues/17
+ import socket
+ import os
+ import errno
+ s = socket.socket()
+ os.close(s.fileno())
+
+ with self.assertRaises(socket.error) as exc:
+ s.send(b'abc')
+
+ self.assertEqual(exc.exception.errno, errno.EBADF)
+
+ with self.assertRaises(OSError) as exc:
+ py33_exceptions.wrap_error(s.send, b'abc')
+
+ self.assertEqual(exc.exception.errno, errno.EBADF)
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/trollius/py33_exceptions.py b/trollius/py33_exceptions.py
index f10dfe9..477aadd 100644
--- a/trollius/py33_exceptions.py
+++ b/trollius/py33_exceptions.py
@@ -79,6 +79,9 @@ _MAP_ERRNO = {
errno.ESRCH: ProcessLookupError,
}
+if hasattr(errno, 'EBADF') and errno.EBADF not in _MAP_ERRNO:
+ _MAP_ERRNO[errno.EBADF] = OSError
+
if sys.platform == 'win32':
from trollius import _overlapped
_MAP_ERRNO.update({