Пример #1
0
def test_mult():
    v1 = Transform2D()
    v2 = Transform2D()
    v3 = v1 * v2
    assert isinstance(v3, Transform2D)
    v2 *= v1
    assert v3 == v2
Пример #2
0
def test_init():
    v = Transform2D()
    assert type(v) == Transform2D
    args = (Vector2(1, 2), Vector2(3, 4), Vector2(5, 6))
    v2 = Transform2D(*args)
    assert type(v) == Transform2D
    assert v2 == Transform2D(*args)
    assert v != v2
Пример #3
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
Пример #4
0
def test_methods_call_with_none(field, params):
    v = Transform2D()
    method = getattr(v, field)
    with pytest.raises(TypeError):
        method(*params)
Пример #5
0
def test_bad_init_from_rot_pos(args):
    with pytest.raises(TypeError):
        Transform2D.from_rot_pos(*args)
Пример #6
0
def test_init_from_rot_pos():
    v = Transform2D.from_rot_pos(1, Vector2())
    assert isinstance(v, Transform2D)
Пример #7
0
def test_repr():
    v = Transform2D()
    assert repr(v).startswith("<Transform2D(")
Пример #8
0
def test_bad_init(args):
    with pytest.raises(TypeError):
        Transform2D(*args)
Пример #9
0
def test_not_equal(arg):
    arr = Transform2D(Vector2(1, 2), Vector2(3, 4), Vector2(5, 6))
    assert arr != arg
    assert not arr != arr  # Force use of __ne__
Пример #10
0
def test_equal():
    arr = Transform2D(Vector2(1, 2), Vector2(3, 4), Vector2(5, 6))
    other = Transform2D(Vector2(1, 2), Vector2(3, 4), Vector2(5, 6))
    assert arr == other
    bad = Transform2D(Vector2(0, 2), Vector2(3, 4), Vector2(5, 6))
    assert not arr == bad  # Force use of __eq__
Пример #11
0
def test_bad_mult(arg):
    with pytest.raises(TypeError):
        Transform2D(2, 3) * arg
Пример #12
0
        ["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


@pytest.mark.parametrize(
    "field,params",