def test_dict_iteration_by_keys_using_explicit_call_to_keys_method(ut):
    '''
    Support the simplest case - one iteration over dictionary using explicit keys() call

    For(target=Name(id='k', ctx=Store()),
        iter=Call(func=Attribute(value=Name(id='dict_', ctx=Load()),
                  attr='keys', ctx=Load()), args=[], keywords=[], starargs=None, kwargs=None),
                  body=[...], orelse=[]) 
    '''
    s = '''
dict_ = {1: 2, 3: 4}

def iter_over_dict_keys():
    for k in dict_.keys():
        # which element returned is undefined
        # (actually, it is defined by the order in which keys are iterated,
        #  which in turn is defined by the hash function, but it's
        #  too complicated)
        # we'll assume that any value can be returned
        return dict_.get(k)

new_values = iter_over_dict_keys()
    '''

    ps.checkString(s)
    r = find_in_history('new_values', ps)
    ut.assertEqual(3, len(r))
    ut.assertNums([2, 4], r[0:2])
    ut.assertCont(r[2])  # represents implicitly returned None
def test_dict_default_value():
    # exercise
    ps.checkString('a = {"a": 1}; b = a.get("b", 2);')

    # verify
    r = find_in_history('b', ps)
    ut.assertEqual(2, len(r))
    ut.assertNums([1, 2], r)
def test_tuple_unpack():
    # exercise
    ps.checkString('''a = {1: 2, 3: 4}
for key, value in a.iteritems():
    b = key
    c = value''')

    # verify
    r = find_in_history('key', ps)
    ut.assertEqual(2, len(r))
    ut.assertNums([1, 3], r)

    r = find_in_history('value', ps)
    ut.assertEqual(2, len(r))
    ut.assertNums([2, 4], r)