Exemplo n.º 1
0
class TestClientConnectorError:
    connection_key = client_reqrep.ConnectionKey(
        host="example.com",
        port=8080,
        is_ssl=False,
        ssl=None,
        proxy=None,
        proxy_auth=None,
        proxy_headers_hash=None,
    )

    def test_ctor(self) -> None:
        err = client.ClientConnectorError(
            connection_key=self.connection_key,
            os_error=OSError(errno.ENOENT, "No such file"),
        )
        assert err.errno == errno.ENOENT
        assert err.strerror == "No such file"
        assert err.os_error.errno == errno.ENOENT
        assert err.os_error.strerror == "No such file"
        assert err.host == "example.com"
        assert err.port == 8080
        assert err.ssl is None

    def test_pickle(self) -> None:
        err = client.ClientConnectorError(
            connection_key=self.connection_key,
            os_error=OSError(errno.ENOENT, "No such file"),
        )
        err.foo = "bar"
        for proto in range(pickle.HIGHEST_PROTOCOL + 1):
            pickled = pickle.dumps(err, proto)
            err2 = pickle.loads(pickled)
            assert err2.errno == errno.ENOENT
            assert err2.strerror == "No such file"
            assert err2.os_error.errno == errno.ENOENT
            assert err2.os_error.strerror == "No such file"
            assert err2.host == "example.com"
            assert err2.port == 8080
            assert err2.ssl is None
            assert err2.foo == "bar"

    def test_repr(self) -> None:
        os_error = OSError(errno.ENOENT, "No such file")
        err = client.ClientConnectorError(connection_key=self.connection_key,
                                          os_error=os_error)
        assert repr(err) == (
            f"ClientConnectorError({self.connection_key!r}, {os_error!r})")

    def test_str(self) -> None:
        err = client.ClientConnectorError(
            connection_key=self.connection_key,
            os_error=OSError(errno.ENOENT, "No such file"),
        )
        assert str(err) == ("Cannot connect to host example.com:8080 ssl:"
                            "default [No such file]")
Exemplo n.º 2
0
class TestClientConnectorCertificateError:
    connection_key = client_reqrep.ConnectionKey(
        host="example.com",
        port=8080,
        is_ssl=False,
        ssl=None,
        proxy=None,
        proxy_auth=None,
        proxy_headers_hash=None,
    )

    def test_ctor(self) -> None:
        certificate_error = Exception("Bad certificate")
        err = client.ClientConnectorCertificateError(
            connection_key=self.connection_key,
            certificate_error=certificate_error)
        assert err.certificate_error == certificate_error
        assert err.host == "example.com"
        assert err.port == 8080
        assert err.ssl is False

    def test_pickle(self) -> None:
        certificate_error = Exception("Bad certificate")
        err = client.ClientConnectorCertificateError(
            connection_key=self.connection_key,
            certificate_error=certificate_error)
        err.foo = "bar"
        for proto in range(pickle.HIGHEST_PROTOCOL + 1):
            pickled = pickle.dumps(err, proto)
            err2 = pickle.loads(pickled)
            assert err2.certificate_error.args == ("Bad certificate", )
            assert err2.host == "example.com"
            assert err2.port == 8080
            assert err2.ssl is False
            assert err2.foo == "bar"

    def test_repr(self) -> None:
        certificate_error = Exception("Bad certificate")
        err = client.ClientConnectorCertificateError(
            connection_key=self.connection_key,
            certificate_error=certificate_error)
        assert repr(err) == ("ClientConnectorCertificateError(%r, %r)" %
                             (self.connection_key, certificate_error))

    def test_str(self) -> None:
        certificate_error = Exception("Bad certificate")
        err = client.ClientConnectorCertificateError(
            connection_key=self.connection_key,
            certificate_error=certificate_error)
        assert str(err) == ("Cannot connect to host example.com:8080 ssl:False"
                            " [Exception: ('Bad certificate',)]")
Exemplo n.º 3
0
class TestClientConnectorError:
    connection_key = client_reqrep.ConnectionKey(host='example.com',
                                                 port=8080,
                                                 is_ssl=False,
                                                 ssl=None,
                                                 proxy=None,
                                                 proxy_auth=None,
                                                 proxy_headers_hash=None)

    def test_ctor(self) -> None:
        err = client.ClientConnectorError(connection_key=self.connection_key,
                                          os_error=OSError(
                                              errno.ENOENT, 'No such file'))
        assert err.errno == errno.ENOENT
        assert err.strerror == 'No such file'
        assert err.os_error.errno == errno.ENOENT
        assert err.os_error.strerror == 'No such file'
        assert err.host == 'example.com'
        assert err.port == 8080
        assert err.ssl is None

    def test_pickle(self) -> None:
        err = client.ClientConnectorError(connection_key=self.connection_key,
                                          os_error=OSError(
                                              errno.ENOENT, 'No such file'))
        err.foo = 'bar'
        for proto in range(pickle.HIGHEST_PROTOCOL + 1):
            pickled = pickle.dumps(err, proto)
            err2 = pickle.loads(pickled)
            assert err2.errno == errno.ENOENT
            assert err2.strerror == 'No such file'
            assert err2.os_error.errno == errno.ENOENT
            assert err2.os_error.strerror == 'No such file'
            assert err2.host == 'example.com'
            assert err2.port == 8080
            assert err2.ssl is None
            assert err2.foo == 'bar'

    def test_repr(self) -> None:
        os_error = OSError(errno.ENOENT, 'No such file')
        err = client.ClientConnectorError(connection_key=self.connection_key,
                                          os_error=os_error)
        assert repr(err) == ("ClientConnectorError(%r, %r)" %
                             (self.connection_key, os_error))

    def test_str(self) -> None:
        err = client.ClientConnectorError(connection_key=self.connection_key,
                                          os_error=OSError(
                                              errno.ENOENT, 'No such file'))
        assert str(err) == ("Cannot connect to host example.com:8080 ssl:None "
                            "[No such file]")