Пример #1
0
def test_bad_equal_with_rid(environment_factory):
    # Doing `RID(Environment())` will cause garbage collection of enclosed
    # Environment object and possible reuse of it id
    env1 = environment_factory()
    env2 = environment_factory()
    rid1 = RID(env1)
    rid2 = RID(env2)
    assert rid1 != rid2
Пример #2
0
def test_bad_equal_with_rid(generate_obj):
    # Doing `RID(Environment())` will cause garbage collection of enclosed
    # Environment object and possible reuse of it id
    env1 = generate_obj(Environment)
    env2 = generate_obj(Environment)
    rid1 = RID(env1)
    rid2 = RID(env2)
    assert rid1 != rid2
Пример #3
0
def test_lt(generate_obj):
    env1 = generate_obj(Environment)
    env2 = generate_obj(Environment)
    rid1 = RID(env1)
    rid2 = RID(env2)
    # Ordered is based on resource pointer, so cannot know the order ahead of time
    small, big = sorted([rid1, rid2])
    assert small < big
    assert big > small
    assert not small > big
    assert not big < small
Пример #4
0
def test_lt(environment_factory):
    env1 = environment_factory()
    env2 = environment_factory()
    rid1 = RID(env1)
    rid2 = RID(env2)
    # Ordered is based on resource pointer, so cannot know the order ahead of time
    small, big = sorted([rid1, rid2])
    assert small < big
    assert big > small
    assert not small > big
    assert not big < small
Пример #5
0
def test_equal(generate_obj):
    v1 = RID()
    v2 = RID()
    assert v1 == v2
    # Environment is a Ressource which provides unique rid per instance
    res_a = generate_obj(Environment)
    v_a_1 = RID(res_a)
    assert v_a_1 != v1
    v_a_2 = RID(res_a)
    assert v_a_1 == v_a_2
    res_b = generate_obj(Environment)
    v_b = RID(res_b)
    assert not v_a_1 == v_b  # Force use of __eq__
Пример #6
0
def test_equal(environment_factory):
    v1 = RID()
    v2 = RID()
    assert v1 == v2
    # Environment is a Ressource which provides unique rid per instance
    res_a = environment_factory()
    v_a_1 = RID(res_a)
    assert v_a_1 != v1
    v_a_2 = RID(res_a)
    assert v_a_1 == v_a_2
    res_b = environment_factory()
    v_b = RID(res_b)
    assert not v_a_1 == v_b  # Force use of __eq__
Пример #7
0
def test_methods(args):
    v = RID()
    # Don't test methods' validity but bindings one
    field, ret_type, params = args
    assert hasattr(v, field)
    method = getattr(v, field)
    assert callable(method)
    ret = method(*params)
    assert type(ret) == ret_type
Пример #8
0
def test_bad_instantiate_with_not_resource(generate_obj):
    # Node doesn't inherit from Resource
    node = generate_obj(Node)
    with pytest.raises(TypeError):
        RID(node)
Пример #9
0
def test_bad_instantiate(arg):
    with pytest.raises(TypeError):
        RID(arg)
Пример #10
0
def test_repr():
    v = RID()
    assert repr(v) == "<RID(id=0)>"
Пример #11
0
def test_bad_equal(generate_obj, arg):
    arr = RID(generate_obj(Environment))
    assert arr != arg
Пример #12
0
def test_base():
    v = RID()
    assert type(v) == RID
Пример #13
0
    rid1 = RID(env1)
    rid2 = RID(env2)
    # Ordered is based on resource pointer, so cannot know the order ahead of time
    small, big = sorted([rid1, rid2])
    assert small < big
    assert big > small
    assert not small > big
    assert not big < small


def test_repr():
    v = RID()
    assert repr(v) == "<RID(id=0)>"


@pytest.mark.parametrize("arg", [42, "dummy", RID()])
def test_bad_instantiate(arg):
    with pytest.raises(TypeError):
        RID(arg)


def test_bad_instantiate_with_not_resource(generate_obj):
    # Node doesn't inherit from Resource
    node = generate_obj(Node)
    with pytest.raises(TypeError):
        RID(node)


@pytest.mark.parametrize("args", [["get_id", int, ()]], ids=lambda x: x[0])
def test_methods(args):
    v = RID()
Пример #14
0
def test_bad_equal(arg):
    arr = RID(Environment())
    assert arr != arg