Пример #1
0
def test_copy_same_values(d):
    keys = [rand_string() for _ in rand_len()]
    values = [rand_string() for _ in keys]
    d = PrehashedDict(zip(keys, values))
    g = d.copy()
    for k, v in zip(keys, values):
        assert g[k] == v
Пример #2
0
def test_copy_same_keys(d):
    keys = [rand_string() for _ in rand_len()]
    values = [rand_string() for _ in keys]
    d = PrehashedDict(zip(keys, values))
    g = d.copy()
    for k in keys:
        assert k in g
Пример #3
0
def test_copy_is_shallow(d):
    keys = [rand_string() for _ in rand_len()]
    values = [rand_string() for _ in keys]
    d = PrehashedDict(zip(keys, values))
    d['12'] = [1, 2, 3]
    g = d.copy()
    g['12'].append(4)
    assert d['12'] == [1, 2, 3, 4]
Пример #4
0
def test_copy_delete_one_old(d):
    keys = [rand_string() for _ in rand_len()]
    values = [rand_string() for _ in keys]
    d = PrehashedDict(zip(keys, values))
    g = d.copy()
    del_key = random.choice(keys)
    del d[del_key]
    assert del_key in g
    assert del_key not in d
Пример #5
0
def test_init_calls_process_args():
    d = PrehashedDict({rand_string(): rand_string()})
    with patch('prehashed.prehashed.PrehashedDict._process_args') as mock:
        arg = random.choice([{
            rand_string(): rand_string()
        }, ((rand_string(), rand_string())), (), d])
        kwargs = {rand_string(): rand_string() for _ in rand_len(0, 2)}
        d = PrehashedDict(arg, **kwargs)
        mock.assert_called_once_with(arg, **kwargs)
Пример #6
0
def test_copy_change_one_old(d):
    keys = [rand_string() for _ in rand_len()]
    values = [rand_string() for _ in keys]
    d = PrehashedDict(zip(keys, values))
    g = d.copy()
    new_val = rand_string()
    changed_key = random.choice(keys)
    d[changed_key] = new_val
    assert d[changed_key] == new_val
    assert g[changed_key] != new_val
Пример #7
0
def test_copy_add_one_old(d):
    keys = [rand_string() for _ in rand_len()]
    values = [rand_string() for _ in keys]
    d = PrehashedDict(zip(keys, values))
    g = d.copy()
    new_key = rand_string()
    new_val = rand_string()
    d[new_key] = new_val
    assert d[new_key] == new_val
    assert new_key in d
    assert new_key not in g
Пример #8
0
def test_pickle(file_cleanup):
    file_name = file_cleanup
    keys = [rand_string() for _ in rand_len()]
    vals = [rand_string() for _ in keys]
    d = PrehashedDict({k: v for k, v in zip(keys, vals)})
    pickle.dump(d, open(file_name, 'wb'))
    d1 = pickle.load(open(file_name, 'rb'))
    for k in keys:
        assert k in d
        assert k in d1
    for k, v in zip(keys, vals):
        assert d1[k] == v
    assert d == d1
Пример #9
0
def test_process_args_iterable_kwargs(d):
    kwargs = {rand_string(): rand_string() for _ in rand_len()}
    it = [(rand_string(), rand_string()) for _ in rand_len()]
    res = list(d._process_args(it, **kwargs))
    assert find(it, res)
    assert find(kwargs.items(), res)
Пример #10
0
def test_process_args_iterable(d):
    it = [(rand_string(), rand_string()) for _ in rand_len()]
    res = list(d._process_args(it))
    assert find(it, res)
Пример #11
0
def test_process_args_prehased_kwargs(d):
    d1 = PrehashedDict({rand_string(): rand_string() for _ in rand_len()})
    kwargs = {rand_string(): rand_string() for _ in rand_len()}
    res = list(d._process_args(d1, **kwargs))
    assert find(d1.items(), res, hash_me=False)
    assert find(kwargs.items(), res)
Пример #12
0
def test_process_args_dict_kwargs(d):
    dic = {rand_string(): rand_string() for _ in rand_len()}
    kwargs = {rand_string(): rand_string() for _ in rand_len()}
    res = list(d._process_args(dic, **kwargs))
    assert find(dic.items(), res)
    assert find(kwargs.items(), res)
Пример #13
0
def test_process_args_kwargs(d):
    kwargs = {rand_string(): rand_string() for _ in rand_len()}
    print(kwargs)
    res = list(d._process_args(**kwargs))
    assert find(kwargs.items(), res)
Пример #14
0
def test_from_keys_value(d):
    keys = [rand_string() for _ in rand_len()]
    value = rand_string()
    d = PrehashedDict.fromkeys(keys, value)
    for k in keys:
        assert d[k] == value
Пример #15
0
def test_from_keys():
    keys = [rand_string() for _ in rand_len()]
    d = PrehashedDict.fromkeys(keys)
    for k in keys:
        assert d[k] == None