Beispiel #1
0
def test_instantiate_from_copy(arg):
    v = Array(arg)
    assert list(v) == list(arg)
    original_len = len(arg)
    v.append(42)
    assert len(arg) == original_len
    assert len(v) == original_len + 1
Beispiel #2
0
def test_append():
    items = [1, "foo", OS]
    v = Array()
    for item in items:
        v.append(item)
    assert len(v) == 3
    assert v == Array(items)
Beispiel #3
0
def test_append_with_non_godot_data(recwarn):
    v = Array()
    v.append(object())
    assert list(v) == [None]
    assert [str(w.message) for w in recwarn.list] == [
        "Cannot convert `<class 'object'>` to Godot's Variant"
    ]
Beispiel #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__
Beispiel #5
0
def test_mix_add_duplicate():
    arr = Array([0])
    arr2 = arr.duplicate(True)
    arr.append(1)
    arr2.append(2)
    arr3 = arr + arr2
    arr.append(3)
    arr3 += arr

    assert list(arr) == [0, 1, 3]
    assert list(arr2) == [0, 2]
    assert list(arr3) == [0, 1, 0, 2, 0, 1, 3]
Beispiel #6
0
def test_len():
    v = Array()
    assert len(v) == 0
    v.append("foo")
    assert len(v) == 1
Beispiel #7
0
def test_append_with_non_godot_data(recwarn):
    v = Array()
    with pytest.raises(TypeError):
        v.append(object())