示例#1
0
def test_Scope_len_registered():
    scope = Scope()
    with scope.registered(str):
        assert len(scope) == 1
        assert scope.supports(str)
    assert not scope.supports(str)
    assert len(scope) == 0
示例#2
0
def test_Scope_registered(include_subclasses):
    scope = Scope()

    supported = [BaseA, DerBaseA, DerDerBaseA]
    if include_subclasses:
        included = [cls.__name__ for cls in supported]
    else:
        included = [BaseA.__name__]
    excluded = [cls.__name__ for cls in supported if not cls.__name__ in included]

    for cls in supported:
        assert not scope.supports(cls)
    for name in included + excluded:
        assert name not in scope
    
    with scope.registered(BaseA, subclasses=include_subclasses):
        for cls in supported:
            assert scope.supports(cls)
        for name in included:
            assert name in scope
        for name in excluded:
            assert name not in scope
    

    for cls in supported:
        assert not scope.supports(cls)
    for name in included + excluded:
        assert name not in scope
示例#3
0
def test_Scope_len_registered_with_name():
    scope = Scope()
    with scope.registered(string=str):
        assert len(scope) == 1
        assert str.__name__ not in scope
        assert "string" in scope
        assert scope["string"] == str
    assert len(scope) == 0
示例#4
0
def test_Scope_len_register_with_name():
    scope = Scope()
    scope.register(string=str)
    assert len(scope) == 1
    assert tuple(scope.keys()) == ("string", )
    assert tuple(scope.values()) == (str, )
    assert scope.supports(str)
    scope.unregister(string=str)
    assert len(scope) == 0
    assert not scope.supports(str)
示例#5
0
def test_Scope_len_register():
    scope = Scope()
    scope.register(str)
    assert len(scope) == 1
    assert tuple(scope.keys()) == (str.__name__, )
    assert tuple(scope.values()) == (str, )
    scope.unregister(str)
    assert len(scope) == 0
示例#6
0
def test_Scope_register_BaseA():
    scope = Scope()
    assert not scope.supports(BaseA)
    assert not scope.supports(DerBaseA)
    scope.register(BaseA)
    assert scope.supports(BaseA)
    assert BaseA.__name__ in scope
    assert scope.supports(DerBaseA)
    assert not DerBaseA.__name__ in scope
    scope.unregister(BaseA)
    assert not scope.supports(BaseA)
    assert not scope.supports(DerBaseA)
    assert not BaseA.__name__ in scope
    assert not DerBaseA.__name__ in scope
示例#7
0
def test_Scope_unregister_type_error():
    scope = Scope()
    with pytest.raises(TypeError):
        scope.unregister(10)
示例#8
0
def test_Scope_register_str():
    scope = Scope()
    assert not scope.supports(str)
    scope.register(str)
    assert scope.supports(str)
    assert scope.supports("10")
    assert not scope.supports(int)
    assert not scope.supports(10)
    scope.unregister(str)
    assert not scope.supports(str)
    assert 'str' not in scope.globals_d()
示例#9
0
def test_Scope():
    scope = Scope()
    assert not scope.globals_d()
示例#10
0
def test_Scope_register_objects():
    scope = Scope()
    a = 10
    b = BaseA()
    assert 'a' not in scope
    assert 'b' not in scope
    assert not scope.supports(a)
    assert not scope.supports(int)
    assert not scope.supports(b)
    assert not scope.supports(BaseA)
    scope.register(a=a, b=b)
    assert scope.supports(a)
    assert scope.supports(int)
    assert scope.supports(b)
    assert scope.supports(BaseA)
    assert 'a' in scope
    assert 'b' in scope
    scope.unregister(a=a, b=b)
    assert 'a' not in scope
    assert 'b' not in scope
    assert not scope.supports(a)
    assert not scope.supports(int)
    assert not scope.supports(b)
    assert not scope.supports(BaseA)