コード例 #1
0
def mcify(obj):
    if isinstance(obj,dict):
        return Dict({k: mcify(obj[k]) for k in obj})
    if isinstance(obj, set):
        
        return Set({mcify(k) for k in obj})
    if isinstance(obj, list):
        
        return List([mcify(k) for k in obj])
    return obj
コード例 #2
0
 def f(arg):
     result = Dict({})
     for c in kwcallables:
         result[c] = kwcallables[c](arg)
     return result
コード例 #3
0
def test_dict_adding_dict_to_list():
    assert_that(
        Dict(dict(key=10)) + List([("hello", "world")]),
        equal_to(Dict(dict(key=10, hello="world"))))
コード例 #4
0
def test_dict_map_vals():
    eq_(Dict({1: 5, 2: 6}).map_vals(lambda x, y: x + y), {1: 6, 2: 8})
コード例 #5
0
def test_dict_get_optional_should_return_value_in_some():
    assert_that(Dict({"key": 10}).get_optional("key"), Some(10))
コード例 #6
0
def test_dict_adding_dicts():
    assert_that(
        Dict(dict(key=10)) + Dict(dict(key2=11)),
        equal_to(Dict(dict(key=10, key2=11))))
コード例 #7
0
def test_dict_get_optional_should_return_nothing_if_no_such_key():
    assert_that(Dict({"key": 10}).get_optional("other"), instance_of(Nothing))
コード例 #8
0
def test_dict_map_keys():
    eq_(Dict({1: 5, 2: 6}).map_keys(lambda x, y: x * y), {5: 5, 12: 6})
コード例 #9
0
def test_dict_get_should_throw_if_no_such_key():
    assert_that(calling(lambda: Dict({}).get("key")), raises(AssertionError))
コード例 #10
0
def test_dict_get_should_fetch_value():
    assert_that(Dict({"key": 10}).get("key"), equal_to(10))
コード例 #11
0
def test_dict_mk_string():
    eq_(Dict({1: 2, 3: 4}).mk_string(" b ", "a", "<", ">"), "<1a2 b 3a4>")
コード例 #12
0
def test_dict_with_dic():
    dictionary = Dict({1: 2, 3: 4})
    eq_(dictionary.with_dic({4: 5, 6: 7}), Dict({1: 2, 3: 4, 4: 5, 6: 7}))
    eq_(dictionary, Dict({1: 2, 3: 4}))
コード例 #13
0
def test_dict_with_kv():
    dictionary = Dict({1: 2, 3: 4})
    eq_(dictionary.with_kv(4, 5), Dict({1: 2, 3: 4, 4: 5}))
    eq_(dictionary, Dict({1: 2, 3: 4}))
コード例 #14
0
def test_dict_get_or_else():
    dictionary = Dict({1: 2, 3: 4})
    eq_(dictionary.get_or_else(1, 0), 2)
    eq_(dictionary.get_or_else(2, 10), 10)
コード例 #15
0
def test_dict_filter():
    eq_(Dict({1: 5, 2: 6, 4: 4}).filter(lambda x, y: y < 6 and x < 2), {1: 5})