示例#1
0
def test_LambdaDictionary1():
    fred = LambdaDictionary()
    fred.lamb = lambda x: x.upper()
    assert len(fred) == 0
    
    fred["hello"] = 1
    assert len(fred) == 1
    assert fred["HEllo"] == 1
    assert "heLLo" in fred
    assert " hello " not in fred
    assert "HELLO" not in fred.keys()
    assert "HELLO" in fred._keys()
    assert fred.items()[0][0] == "hello"
    fred["hello "] = 2
    assert len(fred) == 2
示例#2
0
def copyClosure(closure, context=None):
    oc_map = LambdaDictionary(id)
    for original in closure:
        creator = getattr(original, "_ccCreate", Missing)
        if not creator is Missing:
            copy = creator(context)
            assert isinstance(copy, type(original)), "copy is not type(original)"
            assert copy is not original, "copy is not type(original)"
            oc_map[original] = creator(context)
        else:
            oc_map[original] = GodCopy(original)
    for original, copy in oc_map.items():
        gluer = getattr(original, "_ccGlue", Missing)
        if not gluer is Missing:
            copy._ccGlue(original, oc_map, context)
    return oc_map
示例#3
0
def test_LambdaDictionary2():
    fred = LambdaDictionary()
    fred.lamb = lambda x: x.replace(" ","").upper()
    assert len(fred) == 0
    
    fred["h ello "] = 1
    assert len(fred) == 1
    assert fred.keys() == ["h ello "], fred.keys()
    assert fred._keys() == ["HELLO"], fred._keys()
    assert fred["HEllo"] == 1
    assert fred.has_key(" h e L l O ")
    assert "heLLo" in fred
    assert " hello " in fred
    assert "HELLO" not in fred.keys()
    assert fred.items()[0][0] == "h ello "
    
    fred["Hello"] = 2
    assert len(fred) == 1
    assert "h ello " not in fred.keys()