summaryrefslogtreecommitdiff
path: root/tests/test_py33_exceptions.py
blob: 42fb4e237af2980d353ad77fab00bed058124571 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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()