Ejemplo n.º 1
0
def test_base():
    v = Rect2(4, 3, 2, 1)
    assert type(v) == Rect2
    v2 = Rect2(1, 2, 3, 4)
    assert type(v) == Rect2
    assert v2 == Rect2(1, 2, 3, 4)
    assert v != v2
Ejemplo n.º 2
0
def test_methods(field, ret_type, params):
    v = Rect2()
    # Don't test methods' validity but bindings one
    assert hasattr(v, field)
    method = getattr(v, field)
    assert callable(method)
    ret = method(*params)
    assert type(ret) == ret_type
Ejemplo n.º 3
0
def test_rw_properties(field, ret_type):
    v = Rect2()
    assert hasattr(v, field)
    field_val = getattr(v, field)
    assert type(field_val) == ret_type
    for val in (Vector2(), Vector2(0.1, -0.1)):
        setattr(v, field, val)
        field_val = getattr(v, field)
        assert field_val == val
Ejemplo n.º 4
0
def test_instantiate():
    # Can build it with int or float or nothing
    msg_tmpl = "%s vs (expected) %s (args=%s)"
    for args, expected_pos, expected_size in (
        [(), Vector2(0, 0), Vector2(0, 0)],
        [(0.5, 0.5), Vector2(0.5, 0.5),
         Vector2(0, 0)],
        [(1, 2, 1, 2), Vector2(1, 2),
         Vector2(1, 2)],
    ):
        v = Rect2(*args)
        assert v.position == expected_pos, msg_tmpl % (v.position,
                                                       expected_pos, args)
        assert v.size == expected_size, msg_tmpl % (v.size, expected_size,
                                                    args)
    with pytest.raises(TypeError):
        Rect2("a", 2, 3, 4)
    with pytest.raises(TypeError):
        Rect2(1, "b", 3, 4)
    with pytest.raises(TypeError):
        Rect2(1, 2, "c", 4)
    with pytest.raises(TypeError):
        Rect2(1, 2, 3, "d")
    with pytest.raises(TypeError):
        Rect2(None, 2)
Ejemplo n.º 5
0
@pytest.mark.parametrize(
    "field,ret_type,params",
    [
        ["inverse", Transform2D, ()],
        ["affine_inverse", Transform2D, ()],
        ["get_rotation", float, ()],
        # ["get_origin", Vector2, ()],
        ["get_scale", Vector2, ()],
        ["orthonormalized", Transform2D, ()],
        ["rotated", Transform2D, (1.0,)],
        ["scaled", Transform2D, (Vector2(),)],
        ["translated", Transform2D, (Vector2(),)],
        ["xform", Vector2, (Vector2(),)],
        ["xform_inv", Vector2, (Vector2(),)],
        ["xform", Rect2, (Rect2(),)],
        ["xform_inv", Rect2, (Rect2(),)],
        ["basis_xform", Vector2, (Vector2(),)],
        ["basis_xform_inv", Vector2, (Vector2(),)],
        ["interpolate_with", Transform2D, (Transform2D(), 1.0)],
    ],
    ids=lambda x: x[0],
)
def test_methods(field, ret_type, params):
    v = Transform2D()
    # Don't test methods' validity but bindings one
    assert hasattr(v, field)
    method = getattr(v, field)
    assert callable(method)
    ret = method(*params)
    assert type(ret) == ret_type
Ejemplo n.º 6
0
def test_ro_end_property():
    v = Rect2()
    assert hasattr(v, "end")
    assert type(v.end) == Vector2
    with pytest.raises(AttributeError):
        v.end = Vector2()
Ejemplo n.º 7
0
def test_repr():
    v = Rect2(1, 2)
    assert repr(v) == "<Rect2(1, 2, 0, 0)>"
Ejemplo n.º 8
0
def test_bad_equal(arg):
    arr = Rect2(0.1, 1, 2, 3)
    assert arr != arg
Ejemplo n.º 9
0
def test_equal():
    arr = Rect2(0.1, 1, 2, 3)
    other = Rect2(0.1, 1, 2, 3)
    assert arr == other
    bad = Rect2(0.1, 1, 2, 4)
    assert not arr == bad  # Force use of __eq__
Ejemplo n.º 10
0
def test_bad_rw_properties(field, bad_value):
    v = Rect2()
    with pytest.raises(TypeError):
        setattr(v, field, bad_value)
Ejemplo n.º 11
0
        Rect2("a", 2, 3, 4)
    with pytest.raises(TypeError):
        Rect2(1, "b", 3, 4)
    with pytest.raises(TypeError):
        Rect2(1, 2, "c", 4)
    with pytest.raises(TypeError):
        Rect2(1, 2, 3, "d")
    with pytest.raises(TypeError):
        Rect2(None, 2)


@pytest.mark.parametrize(
    "field,ret_type,params",
    [
        ["get_area", float, ()],
        ["intersects", bool, (Rect2(), )],
        ["encloses", bool, (Rect2(), )],
        ["has_no_area", bool, ()],
        ["clip", Rect2, (Rect2(), )],
        ["merge", Rect2, (Rect2(), )],
        ["has_point", bool, (Vector2(), )],
        ["grow", Rect2, (0.5, )],
        ["grow_individual", Rect2, (0.1, 0.2, 0.3, 0.4)],
        ["grow_margin", Rect2, (42, 0.5)],
        ["abs", Rect2, ()],
        ["expand", Rect2, (Vector2(), )],
    ],
    ids=lambda x: x[0],
)
def test_methods(field, ret_type, params):
    v = Rect2()