'Check handling of invalid ports.'

def test_attributes_bad_port(self):

    for bytes in (False, True):
        for parse in (urllib.parse.urlsplit, urllib.parse.urlparse):
            for port in ('foo', '1.5', '-1', '0x10'):
                with self.subTest(bytes=bytes, parse=parse, port=port):
                    netloc = ('www.example.net:' + port)
                    url = ('http://' + netloc)
                    if bytes:
                        netloc = netloc.encode('ascii')
                        url = url.encode('ascii')
                    p = parse(url)
                    self.assertEqual(p.netloc, netloc)
                    with self.assertRaises(ValueError):
                        p.port
