def test_badEncoding(self):
        """
        When a bad hostname is passed to L{HostnameEndpoint}, the string
        representation displays invalid characters in backslash-escaped form.
        """
        endpoint = endpoints.HostnameEndpoint(
            deterministicResolvingReactor(Clock(), []),
            b'\xff-garbage-\xff', 80
        )

        self.assertEqual(
            '<HostnameEndpoint \\xff-garbage-\\xff:80>',
            repr(endpoint),
        )

        When a bad hostname is passed to L{HostnameEndpoint}, the string
        representation displays invalid characters in backslash-escaped form.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/internet/test/test_endpoints.py