def test_beginLoggingToPreservesEncoding(self):
        """
        When L{LogBeginner.beginLoggingTo} redirects stdout/stderr streams, the
        replacement streams will preserve the encoding of the replaced streams,
        to minimally disrupt any application relying on a specific encoding.
        """

        weird = io.TextIOWrapper(io.BytesIO(), "shift-JIS")
        weirderr = io.TextIOWrapper(io.BytesIO(), "big5")

        self.sysModule.stdout = weird
        self.sysModule.stderr = weirderr

        x = []
        self.beginner.beginLoggingTo([x.append])
        self.assertEqual(self.sysModule.stdout.encoding, "shift-JIS")
        self.assertEqual(self.sysModule.stderr.encoding, "big5")

        self.sysModule.stdout.write(b"\x97\x9B\n")
        self.sysModule.stderr.write(b"\xBC\xFC\n")
        compareEvents(
            self, x, [dict(log_io=u"\u674e"), dict(log_io=u"\u7469")]
        )

        When L{LogBeginner.beginLoggingTo} redirects stdout/stderr streams, the
        replacement streams will preserve the encoding of the replaced streams,
        to minimally disrupt any application relying on a specific encoding.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/logger/test/test_global.py