'Passing an argument of the wrong type to any of the constructor
arguments of L{URL} will raise a descriptive L{TypeError}.
L{URL} typechecks very aggressively to ensure that its constitutent
parts are all properly immutable and to prevent confusing errors when
bad data crops up in a method call long after the code that called the
constructor is off the stack.'

def test_invalidArguments(self):

    class Unexpected(object, ):
        def __str__(self):
            return u'wrong'
        def __repr__(self):
            return u'<unexpected>'
    defaultExpectation = (u'unicode' if (bytes is str) else u'str')
    def assertRaised(raised, expectation, name):
        self.assertEqual(str(raised.exception), u'expected    {}    for    {},    got    {}'.format(expectation, name, u'<unexpected>'))
    def check(param, expectation=defaultExpectation):
        with self.assertRaises(TypeError) as raised:
            URL(**{param: Unexpected()})
        assertRaised(raised, expectation, param)
    check(u'scheme')
    check(u'host')
    check(u'fragment')
    check(u'rooted', u'bool')
    check(u'userinfo')
    check(u'port', u'int    or    NoneType')
    with self.assertRaises(TypeError) as raised:
        URL(path=[Unexpected()])
    assertRaised(raised, defaultExpectation, u'path    segment')
    with self.assertRaises(TypeError) as raised:
        URL(query=[(u'name', Unexpected())])
    assertRaised(raised, (defaultExpectation + u'    or    NoneType'), u'query    parameter    value')
    with self.assertRaises(TypeError) as raised:
        URL(query=[(Unexpected(), u'value')])
    assertRaised(raised, defaultExpectation, u'query    parameter    name')
    with self.assertRaises(TypeError):
        URL(query=[Unexpected()])
    with self.assertRaises(ValueError):
        URL(query=[(u'k', u'v', u'vv')])
    with self.assertRaises(ValueError):
        URL(query=[(u'k',)])
    url = URL.fromText(u'https://valid.example.com/')
    with self.assertRaises(TypeError) as raised:
        url.child(Unexpected())
    assertRaised(raised, defaultExpectation, u'path    segment')
    with self.assertRaises(TypeError) as raised:
        url.sibling(Unexpected())
    assertRaised(raised, defaultExpectation, u'path    segment')
    with self.assertRaises(TypeError) as raised:
        url.click(Unexpected())
    assertRaised(raised, defaultExpectation, u'relative    URL')
