示例#1
0
def test_bad_equal(arg):
    arr = Array([1])
    assert arr != arg
示例#2
0
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])
示例#3
0
def test_outofrange_delitem():
    v = Array(["foo", 0])
    with pytest.raises(IndexError):
        del v[2]
示例#4
0
def test_iter():
    items = [GDString("foo"), 0, OS]
    v = Array(items)
    items_from_v = [x for x in v]
    assert items_from_v == items
示例#5
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)>])>"
示例#6
0
def test_instantiate_with_non_godot_data(recwarn):
    v = Array([object()])
    assert list(v) == [None]
    assert [str(w.message) for w in recwarn.list] == [
        "Cannot convert `<class 'object'>` to Godot's Variant"
    ]
示例#7
0
def test_base():
    v = Array()
    assert type(v) == Array
示例#8
0
    pool = pool_x_array.cls(vals)
    other = other_type(vals)

    # Test __eq__ operator
    assert not pool == other

    # Test __ne__ operator
    assert pool != other


@pytest.mark.parametrize(
    "arg",
    [
        None,
        0,
        Array(),
        [],
        (),
        "",
        Vector2(),
        NODE,
        lambda s: s.generate_value(),
        lambda s: s.cls(s.generate_values(2)),
    ],
)
def test_bad_equal(pool_x_array, arg):
    pool = pool_x_array.cls()
    other = pool_x_array.expand_arg(arg)

    # Test __ne__ operator
    assert not pool == other
示例#9
0
def test_append_with_non_godot_data(recwarn):
    v = Array()
    with pytest.raises(TypeError):
        v.append(object())
示例#10
0
def test_add_with_non_godot_data(recwarn):
    v = Array()
    with pytest.raises(TypeError):
        v += [object()]
示例#11
0
def test_instantiate_with_non_godot_data(recwarn):
    with pytest.raises(TypeError):
        Array([object()])
示例#12
0
def test_has_all():
    v = Dictionary({"a": 1, 2: "foo", None: None})
    elems = Array(["a", None])
    assert v.has_all(elems)
    bad_elems = Array(["a", 42])
    assert not v.has_all(bad_elems)
示例#13
0
    assert json


def test_update():
    v1 = Dictionary({"a": 1, "b": 2})
    v2 = Dictionary({"b": 3, "c": 4})
    v1.update(v2)
    assert v1 == Dictionary({"a": 1, "b": 3, "c": 4})
    assert v2 == Dictionary({"b": 3, "c": 4})

    v2.update({"d": 5, "e": 6})
    assert v1 == Dictionary({"a": 1, "b": 3, "c": 4})
    assert v2 == Dictionary({"b": 3, "c": 4, "d": 5, "e": 6})


@pytest.mark.parametrize("arg", [None, 0, Vector2(), OS, Array([1, 2])])
def test_bad_update(arg):
    v = Dictionary()
    with pytest.raises(TypeError):
        v.update(arg)


@pytest.mark.parametrize("deep", [False, True])
def test_duplicate(deep):
    inner = Dictionary({0: 0})
    d1 = Dictionary({0: inner})
    d2 = d1.duplicate(deep)
    d1[0][1] = 1
    d2[0][2] = 2

    if deep:
示例#14
0
def test_bad_add(arg):
    v = Array()
    with pytest.raises(TypeError):
        v + arg  # __add__
    with pytest.raises(TypeError):
        v += arg  # __iadd__
示例#15
0
def test_len():
    v = Array()
    assert len(v) == 0
    v.append("foo")
    assert len(v) == 1
示例#16
0
    pool = pool_x_array.cls(vals)
    other = other_type(vals)

    # Test __eq__ operator
    assert not pool == other

    # Test __ne__ operator
    assert pool != other


@pytest.mark.parametrize(
    "arg",
    [
        None,
        0,
        Array(),
        [],
        (),
        "",
        Vector2(),
        NODE,
        lambda s: s.generate_value(),
        lambda s: s.cls(s.generate_values(2)),
    ],
)
def test_bad_equal(pool_x_array, arg):
    pool = pool_x_array.cls()
    other = pool_x_array.expand_arg(arg)

    # Test __ne__ operator
    assert not pool == other
示例#17
0
def test_getitem():
    v = Array(["foo", 0, OS, 0.42])
    assert v[0] == GDString("foo")
    assert v[1] == 0
    assert v[-1] == 0.42
示例#18
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__


@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])
示例#19
0
def test_outofrange_setitem():
    v = Array(["foo", 0])
    with pytest.raises(IndexError):
        v[2] = 42
示例#20
0
def test_bad_instantiate(arg):
    with pytest.raises(TypeError):
        Array(arg)
示例#21
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():