Example #1
0
    def testClose(self):
        class MockSocket:
            closed = False

            def flush(self):
                pass

            def close(self):
                self.closed = True

            def _drop(self):
                pass

            def _reuse(self):
                pass

        # must not close unless we request it: the original use of _fileobject
        # by module socket requires that the underlying socket not be closed until
        # the _socketobject that created the _fileobject is closed
        s = MockSocket()
        f = socket._fileobject(s)
        f.close()
        self.assert_(not s.closed)

        s = MockSocket()
        f = socket._fileobject(s, close=True)
        f.close()
        self.assert_(s.closed)
Example #2
0
    def testClose(self):
        class MockSocket:
            closed = False
            def flush(self): pass
            def close(self): self.closed = True

        # must not close unless we request it: the original use of _fileobject
        # by module socket requires that the underlying socket not be closed until
        # the _socketobject that created the _fileobject is closed
        s = MockSocket()
        f = socket._fileobject(s)
        f.close()
        self.assert_(not s.closed)

        s = MockSocket()
        f = socket._fileobject(s, close=True)
        f.close()
        self.assert_(s.closed)
Example #3
0
    def testClose(self):
        class MockSocket:
            closed = False

            def flush(self):
                pass

            def close(self):
                self.closed = True

        # must not close unless we request it: the original use of SocketIO
        # by module socket requires that the underlying socket not be closed until
        # the _socketobject that created the SocketIO is closed
        s = MockSocket()
        f = socket.SocketIO(s)
        f.close()
        self.assertTrue(not s.closed)

        s = MockSocket()
        f = socket.SocketIO(s, close=True)
        f.close()
        self.assertTrue(s.closed)