Пример #1
0
def test_close(connector: Any, key: Any, protocol: Any, loop: Any) -> None:
    conn = Connection(connector, key, protocol, loop)
    assert not conn.closed
    conn.close()
    assert conn._protocol is None
    connector._release.assert_called_with(key, protocol, should_close=True)
    assert conn.closed
Пример #2
0
 def test_close(self):
     conn = Connection(
         self.connector, self.key, self.request,
         self.transport, self.protocol, self.loop)
     conn.close()
     self.assertTrue(self.transport.close.called)
     self.assertIsNone(conn._transport)
Пример #3
0
def test_detach_closed(connector, key, protocol, loop):
    conn = Connection(connector, key, protocol, loop)
    conn.release()
    conn.detach()

    assert not connector._release_acquired.called
    assert conn._protocol is None
Пример #4
0
def test_detach(connector, key, request, transport, protocol, loop):
    conn = Connection(connector, key, request, transport, protocol, loop)
    assert not conn.closed
    conn.detach()
    assert conn._transport is None
    assert not connector._release.called
    assert conn.closed
Пример #5
0
 def test_detach(self):
     conn = Connection(self.connector, self.key, self.request,
                       self.transport, self.protocol, self.loop)
     self.assertFalse(conn.closed)
     conn.detach()
     self.assertIsNone(conn._transport)
     self.assertFalse(self.connector._release.called)
     self.assertTrue(conn.closed)
Пример #6
0
    def test_no_share_cookies(self):
        connector = aiohttp.BaseConnector(share_cookies=False, loop=self.loop)

        conn = Connection(connector, self.key, self.request, self.transport,
                          self.protocol, self.loop)
        self.assertEqual(connector.cookies, {})
        conn.share_cookies({'c1': 'cookie1'})
        self.assertEqual(connector.cookies, {})
def function546(function130, function1068, function214, function1949):
    var1045 = Connection(function130, function1068, function214, function1949)
    var1045.release()
    function130._release.reset_mock()
    var1045.release()
    assert (not function214.transport.close.called)
    assert (var1045._protocol is None)
    assert (not function130._release.called)
def function997(function130, function1068, function214, function1949):
    var4524 = Connection(function130, function1068, function214, function1949)
    assert (not var4524.closed)
    var4524.detach()
    assert (var4524._protocol is None)
    assert function130._release_acquired.called
    assert (not function130._release.called)
    assert var4524.closed
Пример #9
0
def test_release(connector, key, protocol, loop) -> None:
    conn = Connection(connector, key, protocol, loop)
    assert not conn.closed
    conn.release()
    assert not protocol.transport.close.called
    assert conn._protocol is None
    connector._release.assert_called_with(key, protocol, should_close=False)
    assert conn.closed
Пример #10
0
def test_release_released(connector, key, protocol, loop) -> None:
    conn = Connection(connector, key, protocol, loop)
    conn.release()
    connector._release.reset_mock()
    conn.release()
    assert not protocol.transport.close.called
    assert conn._protocol is None
    assert not connector._release.called
Пример #11
0
def test_detach(connector, key, protocol, loop) -> None:
    conn = Connection(connector, key, protocol, loop)
    assert not conn.closed
    conn.detach()
    assert conn._protocol is None
    assert connector._release_acquired.called
    assert not connector._release.called
    assert conn.closed
Пример #12
0
def test_release_released(connector, key, request, transport, protocol, loop):
    conn = Connection(connector, key, request, transport, protocol, loop)
    conn.release()
    connector._release.reset_mock()
    conn.release()
    assert not transport.close.called
    assert conn._transport is None
    assert not connector._release.called
def function173(function130, function1068, function214, function1949):
    var3170 = Connection(function130, function1068, function214, function1949)
    assert (not var3170.closed)
    var3170.close()
    assert (var3170._protocol is None)
    function130._release.assert_called_with(function1068,
                                            function214,
                                            should_close=True)
    assert var3170.closed
Пример #14
0
 def test_release(self):
     conn = Connection(self.connector, self.key, self.request,
                       self.transport, self.protocol)
     conn.release()
     self.assertFalse(self.transport.close.called)
     self.assertIsNone(conn._transport)
     self.connector._release.assert_called_with(self.key, self.request,
                                                self.transport,
                                                self.protocol)
Пример #15
0
 def test_close(self):
     conn = Connection(
         self.connector, self.key, self.request,
         self.transport, self.protocol, self.loop)
     conn.close()
     self.assertIsNone(conn._transport)
     self.connector._release.assert_called_with(
         self.key, self.request, self.transport, self.protocol,
         should_close=True)
Пример #16
0
 def test_release_released(self):
     conn = Connection(self.connector, self.key, self.request,
                       self.transport, self.protocol, self.loop)
     conn.release()
     self.connector._release.reset_mock()
     conn.release()
     self.assertFalse(self.transport.close.called)
     self.assertIsNone(conn._transport)
     self.assertFalse(self.connector._release.called)
Пример #17
0
def test_close(connector, key, request, transport, protocol, loop):
    conn = Connection(connector, key, request,
                      transport, protocol, loop)
    assert not conn.closed
    conn.close()
    assert conn._transport is None
    connector._release.assert_called_with(
        key, request, transport, protocol,
        should_close=True)
    assert conn.closed
def function766(function130, function1068, function214, function1949):
    var1036 = Connection(function130, function1068, function214, function1949)
    assert (not var1036.closed)
    var1036.release()
    assert (not function214.transport.close.called)
    assert (var1036._protocol is None)
    function130._release.assert_called_with(function1068,
                                            function214,
                                            should_close=False)
    assert var1036.closed
Пример #19
0
def test_callbacks_on_release(connector, key, protocol, loop) -> None:
    conn = Connection(connector, key, protocol, loop)
    notified = False

    def cb():
        nonlocal notified
        notified = True

    conn.add_callback(cb)
    conn.release()
    assert notified
def function1918(function130, function1068, function214, function1949):
    function214.should_close = True
    var3825 = Connection(function130, function1068, function214, function1949)
    assert (not var3825.closed)
    var3825.release()
    assert (not function214.transport.close.called)
    assert (var3825._protocol is None)
    function130._release.assert_called_with(function1068,
                                            function214,
                                            should_close=True)
    assert var3825.closed
Пример #21
0
def test_callbacks_on_detach(connector, key, protocol, loop):
    conn = Connection(connector, key, protocol, loop)
    notified = False

    def cb():
        nonlocal notified
        notified = True

    conn.add_callback(cb)
    conn.detach()
    assert notified
def function1525(function130, function1068, function214, function1949):
    var263 = Connection(function130, function1068, function214, function1949)
    var1921 = False

    def function806():
        nonlocal notified
        var1921 = True

    var263.add_callback(function806)
    var263.close()
    assert notified
def function2437(function130, function1068, function214, function1949):
    var374 = Connection(function130, function1068, function214, function1949)
    var1711 = False

    def function806():
        nonlocal notified
        var1711 = True

    var374.add_callback(function806)
    var374.release()
    assert notified
def function1717(function130, function1068, function214, function1949):
    var950 = Connection(function130, function1068, function214, function1949)
    var1691 = False

    def function806():
        nonlocal notified
        var1691 = True

    var950.add_callback(function806)
    var950.detach()
    assert notified
Пример #25
0
def test_callbacks_on_close(connector: Any, key: Any, protocol: Any,
                            loop: Any) -> None:
    conn = Connection(connector, key, protocol, loop)
    notified = False

    def cb() -> None:
        nonlocal notified
        notified = True

    conn.add_callback(cb)
    conn.close()
    assert notified
def function2169(function130, function1068, function214, function1949):
    var2360 = Connection(function130, function1068, function214, function1949)
    var380 = False

    def function1565():
        raise Exception

    def function787():
        nonlocal notified
        var380 = True

    var2360.add_callback(function1565)
    var2360.add_callback(function787)
    var2360.close()
    assert notified
Пример #27
0
def test_callbacks_exception(connector, key, protocol, loop) -> None:
    conn = Connection(connector, key, protocol, loop)
    notified = False

    def cb1():
        raise Exception

    def cb2():
        nonlocal notified
        notified = True

    conn.add_callback(cb1)
    conn.add_callback(cb2)
    conn.close()
    assert notified
Пример #28
0
def test_del(connector, key, protocol, loop) -> None:
    loop.is_closed.return_value = False
    conn = Connection(connector, key, protocol, loop)
    exc_handler = mock.Mock()
    loop.set_exception_handler(exc_handler)

    with pytest.warns(ResourceWarning):
        del conn
        gc.collect()

    connector._release.assert_called_with(key, protocol, should_close=True)
    msg = {'client_connection': mock.ANY,  # conn was deleted
           'message': 'Unclosed connection'}
    if loop.get_debug():
        msg['source_traceback'] = mock.ANY
    loop.call_exception_handler.assert_called_with(msg)
def function543(function130, function1068, function214, function1949):
    function1949.is_closed.return_value = False
    var309 = Connection(function130, function1068, function214, function1949)
    var570 = mock.Mock()
    function1949.set_exception_handler(var570)
    with pytest.warns(ResourceWarning):
        del conn
        gc.collect()
    function130._release.assert_called_with(function1068,
                                            function214,
                                            should_close=True)
    var4015 = {
        'client_connection': mock.ANY,
        'message': 'Unclosed connection',
    }
    if function1949.get_debug():
        var4015['source_traceback'] = mock.ANY
    function1949.call_exception_handler.assert_called_with(var4015)
Пример #30
0
def test_del(connector, key, request, transport, protocol, loop, warning):
    conn = Connection(connector, key, request,
                      transport, protocol, loop)
    exc_handler = mock.Mock()
    loop.set_exception_handler(exc_handler)

    with warning(ResourceWarning):
        del conn
        gc.collect()

    connector._release.assert_called_with(key,
                                          request,
                                          transport,
                                          protocol,
                                          should_close=True)
    msg = {'client_connection': mock.ANY,  # conn was deleted
           'message': 'Unclosed connection'}
    if loop.get_debug():
        msg['source_traceback'] = mock.ANY
    exc_handler.assert_called_with(loop, msg)