def dict_constructor():
    if verbose:
        print "Testing dict constructor ..."
    d = dict()
    vereq(d, {})
    d = dict({})
    vereq(d, {})
    d = dict({1: 2, 'a': 'b'})
    vereq(d, {1: 2, 'a': 'b'})
    vereq(d, dict(d.items()))
    vereq(d, dict(d.iteritems()))
    d = dict({'one':1, 'two':2})
    vereq(d, dict(one=1, two=2))
    vereq(d, dict(**d))
    vereq(d, dict({"one": 1}, two=2))
    vereq(d, dict([("two", 2)], one=1))
    vereq(d, dict([("one", 100), ("two", 200)], **d))
    verify(d is not dict(**d))
    for badarg in 0, 0L, 0j, "0", [0], (0,):
        try:
            dict(badarg)
        except TypeError:
            pass
        except __HOLE__:
            if badarg == "0":
                # It's a sequence, and its elements are also sequences (gotta
                # love strings <wink>), but they aren't of length 2, so this
                # one seemed better as a ValueError than a TypeError.
                pass
            else:
                raise TestFailed("no TypeError from dict(%r)" % badarg)
        else:
            raise TestFailed("no TypeError from dict(%r)" % badarg)

    try:
        dict({}, {})
    except TypeError:
        pass
    else:
        raise TestFailed("no TypeError from dict({}, {})")

    class Mapping:
        # Lacks a .keys() method; will be added later.
        dict = {1:2, 3:4, 'a':1j}

    try:
        dict(Mapping())
    except TypeError:
        pass
    else:
        raise TestFailed("no TypeError from dict(incomplete mapping)")

    Mapping.keys = lambda self: self.dict.keys()
    Mapping.__getitem__ = lambda self, i: self.dict[i]
    d = dict(Mapping())
    vereq(d, Mapping.dict)

    # Init from sequence of iterable objects, each producing a 2-sequence.
    class AddressBookEntry:
        def __init__(self, first, last):
            self.first = first
            self.last = last
        def __iter__(self):
            return iter([self.first, self.last])

    d = dict([AddressBookEntry('Tim', 'Warsaw'),
              AddressBookEntry('Barry', 'Peters'),
              AddressBookEntry('Tim', 'Peters'),
              AddressBookEntry('Barry', 'Warsaw')])
    vereq(d, {'Barry': 'Warsaw', 'Tim': 'Peters'})

    d = dict(zip(range(4), range(1, 5)))
    vereq(d, dict([(i, i+1) for i in range(4)]))

    # Bad sequence lengths.
    for bad in [('tooshort',)], [('too', 'long', 'by 1')]:
        try:
            dict(bad)
        except ValueError:
            pass
        else:
            raise TestFailed("no ValueError from dict(%r)" % bad)
dataset/ETHPy150Open azoft-dev-team/imagrium/env/Lib/test/test_descr.py/dict_constructor