Пример #1
0
    assert type(v) == Dictionary


def test_equal():
    arr = Dictionary()
    other = Dictionary()
    for key, value in [("a", 1), ("b", "foo"), ("c", OS), ("d", Vector2())]:
        other[key] = arr[key] = value
    assert arr == other
    bad = Dictionary({"a": 1})
    assert not arr == bad  # Force use of __eq__


@pytest.mark.parametrize(
    "arg",
    [None, 0, "foo", Vector2(), {
        "a": 1
    }, Dictionary({"b": 2})])
def test_bad_equal(arg):
    arr = Dictionary({"a": 1})
    assert arr != arg


def test_repr():
    v = Dictionary()
    assert repr(v) == "<Dictionary({})>"
    v = Dictionary({"a": 1, 2: "foo", 0.5: Vector2()})
    assert repr(v).startswith("<Dictionary({")
    for item in ["'a': 1", "2: 'foo'", "0.5: <Vector2(x=0.0, y=0.0)>"]:
        assert item in repr(v)
Пример #2
0
def test_iter():
    v = Dictionary({"a": 1, 2: "foo", 0.5: Vector2()})
    items = [GDString("a"), 2, 0.5]
    items_from_v = [x for x in v]
    assert items_from_v == items
Пример #3
0
def test_repr():
    v = Array()
    assert repr(v) == "<Array([])>"
    v = Array([1, "foo", Vector2()])
    assert repr(v) == "<Array([1, <GDString('foo')>, <Vector2(x=0.0, y=0.0)>])>"
Пример #4
0

def test_equal(current_node):
    arr = Array()
    other = Array()
    for item in [1, "foo", current_node, OS, Vector2()]:
        arr.append(item)
        other.append(item)
    assert arr == other
    bad = Array([0, 0, 0])
    assert not arr == bad  # Force use of __eq__
    assert not arr == None  # Force use of __eq__


@pytest.mark.parametrize(
    "arg", [None, 0, "foo", Vector2(), [1], Array([1, 2]), PoolByteArray([1]), PoolIntArray([1])]
)
def test_bad_equal(arg):
    arr = Array([1])
    assert arr != arg


def test_add():
    arr = Array([None])
    arr += Array([1, "two"])  # __iadd__
    assert arr == Array([None, 1, "two"])
    arr2 = arr + Array([3])  # __add__
    assert arr2 == Array([None, 1, "two", 3])


def test_add_with_non_array():
Пример #5
0
def test_ro_end_property():
    v = Rect2()
    assert hasattr(v, "end")
    assert type(v.end) == Vector2
    with pytest.raises(AttributeError):
        v.end = Vector2()
Пример #6
0
    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()
    # Don't test methods' validity but bindings one
    assert hasattr(v, field)
    method = getattr(v, field)
    assert callable(method)
    ret = method(*params)
Пример #7
0
def test_keys():
    v = Dictionary({"a": 1, 2: "foo", 0.5: Vector2()})
    keys = v.keys()
    assert list(keys) == [GDString("a"), 2, 0.5]