Пример #1
0
    def test_writeSequence(self):
        """
        L{twisted.internet.protocol.FileWrapper.writeSequence}
        """
        wrapper = FileWrapper(BytesIO())
        wrapper.writeSequence([b"test1", b"test2"])
        self.assertEqual(wrapper.file.getvalue(), b"test1test2")

        wrapper = FileWrapper(BytesIO())
        # In Python 3, b"".join([u"a", u"b"]) will raise a TypeError
        self.assertRaises(TypeError, wrapper.writeSequence, ["test3", "test4"])
Пример #2
0
    def test_writeSequence(self):
        """
        L{twisted.internet.protocol.FileWrapper.writeSequence}
        """
        wrapper = FileWrapper(BytesIO())
        wrapper.writeSequence([b"test1", b"test2"])
        self.assertEqual(wrapper.file.getvalue(), b"test1test2")

        wrapper = FileWrapper(BytesIO())
        if _PY3:
            # In Python 3, b"".join([u"a", u"b"]) will raise a TypeError
            self.assertRaises(TypeError, wrapper.writeSequence,
                              [u"test3", u"test4"])
        else:
            # In Python 2, b"".join([u"a", u"b"])
            # will give u"ab", but writing unicode to BytesIO
            # will throw an exception which will be caught
            # and ignored by FileWrapper.handle_exception()
            wrapper.writeSequence([u"test3", u"test4"])
            self.assertTrue(len(wrapper.file.getvalue()) == 0)
Пример #3
0
    def test_writeSequence(self):
        """
        L{twisted.internet.protocol.FileWrapper.writeSequence}
        """
        wrapper = FileWrapper(BytesIO())
        wrapper.writeSequence([b"test1", b"test2"])
        self.assertEqual(wrapper.file.getvalue(), b"test1test2")

        wrapper = FileWrapper(BytesIO())
        if _PY3:
            # In Python 3, b"".join([u"a", u"b"]) will raise a TypeError
            self.assertRaises(TypeError,
                              wrapper.writeSequence,
                              [u"test3", u"test4"])
        else:
            # In Python 2, b"".join([u"a", u"b"])
            # will give u"ab", but writing unicode to BytesIO
            # will throw an exception which will be caught
            # and ignored by FileWrapper.handle_exception()
            wrapper.writeSequence([u"test3", u"test4"])
            self.assertTrue(len(wrapper.file.getvalue()) == 0)