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_outofrange_delitem(): v = Array(["foo", 0]) with pytest.raises(IndexError): del v[2]
def test_iter(): items = [GDString("foo"), 0, OS] v = Array(items) items_from_v = [x for x in v] assert items_from_v == items
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)>])>"
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" ]
def test_base(): v = Array() assert type(v) == Array
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
def test_append_with_non_godot_data(recwarn): v = Array() with pytest.raises(TypeError): v.append(object())
def test_add_with_non_godot_data(recwarn): v = Array() with pytest.raises(TypeError): v += [object()]
def test_instantiate_with_non_godot_data(recwarn): with pytest.raises(TypeError): Array([object()])
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)
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:
def test_bad_add(arg): v = Array() with pytest.raises(TypeError): v + arg # __add__ with pytest.raises(TypeError): v += arg # __iadd__
def test_len(): v = Array() assert len(v) == 0 v.append("foo") assert len(v) == 1
def test_getitem(): v = Array(["foo", 0, OS, 0.42]) assert v[0] == GDString("foo") assert v[1] == 0 assert v[-1] == 0.42
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])
def test_outofrange_setitem(): v = Array(["foo", 0]) with pytest.raises(IndexError): v[2] = 42
def test_bad_instantiate(arg): with pytest.raises(TypeError): Array(arg)
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():