def test_unicode(self):
        """
        StdioOnnaStick converts unicode prints to byte strings on Python 2, in
        order to be compatible with the normal stdout/stderr objects.

        On Python 3, the prints are left unmodified.
        """
        unicodeString = u"Hello, \N{VULGAR FRACTION ONE HALF} world."
        stdio = log.StdioOnnaStick(encoding="utf-8")
        self.assertEqual(stdio.encoding, "utf-8")
        stdio.write(unicodeString + u"\n")
        stdio.writelines([u"Also, " + unicodeString])
        oldStdout = sys.stdout
        sys.stdout = stdio
        self.addCleanup(setattr, sys, "stdout", oldStdout)
        # This should go to the log, utf-8 encoded too:
        print(unicodeString)
        if _PY3:
            self.assertEqual(self.getLogMessages(),
                             [unicodeString,
                              u"Also, " + unicodeString,
                              unicodeString])
        else:
            self.assertEqual(self.getLogMessages(),
                             [unicodeString.encode("utf-8"),
                              (u"Also, " + unicodeString).encode("utf-8"),
                              unicodeString.encode("utf-8")])

        StdioOnnaStick converts unicode prints to byte strings on Python 2, in
        order to be compatible with the normal stdout/stderr objects.

        On Python 3, the prints are left unmodified.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_log.py