def test_repr(self): 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)
def test_equal(self): arr = Dictionary() other = Dictionary() for key, value in [("a", 1), ("b", "foo"), ("c", Node()), ("d", Vector2())]: other[key] = arr[key] = value assert arr == other bad = Dictionary({"a": 1}) assert not arr == bad # Force use of __eq__
def test_equal(self): arr = Dictionary() other = Dictionary() for key, value in [('a', 1), ('b', 'foo'), ('c', Node()), ('d', Vector2())]: other[key] = arr[key] = value assert arr == other bad = Dictionary({'a': 1}) assert not arr == bad # Force use of __eq__
def pybind_profiling_get_accumulated_data(handle, info, info_max): print('get_frame_accumulated_data') info = Dictionary.build_from_gdobj(info, steal=True) # Sort function to make sure we can display the most consuming ones sorted_and_limited = sorted(profiler.per_meth_profiling.items(), key=lambda x: -x[1].self_time)[:info_max] for signature, profile in sorted_and_limited: info[signature] = Dictionary(call_count=profile.call_count, total_time=int(profile.total_time * 1e6), self_time=int(profile.self_time * 1e6)) return len(sorted_and_limited)
def test_getitem(self): v = Dictionary({"a": 1, 2: "foo", 0.5: Vector2()}) assert v["a"] == 1 assert v[0.5] == Vector2() # Missing items are stored as None assert v["dummy"] is None # Cannot store non Godot types with pytest.raises(TypeError): v[object()]
def _build_signal_info(signal): methinfo = Dictionary() methinfo["name"] = signal.name # Dummy data, only name is important here methinfo["args"] = Array() methinfo["default_args"] = Array() methinfo["return"] = None methinfo["flags"] = lib.METHOD_FLAG_FROM_SCRIPT return methinfo
def test_getitem(self): v = Dictionary({'a': 1, 2: 'foo', 0.5: Vector2()}) assert v['a'] == 1 assert v[0.5] == Vector2() # Missing items are stored as None assert v['dummy'] is None # Cannot store non Godot types with pytest.raises(TypeError): v[object()]
def _ready(self): """ Called every time the node is added to the scene. Initialization here. """ #self.execute_command(self.command_test) self.response = Array() self.response2 = Dictionary() print("Python3-Godot Loaded")
def _build_property_info(prop): propinfo = Dictionary() propinfo["name"] = prop.name propinfo["type"] = py_to_gd_type(prop.type) propinfo["hint"] = prop.hint propinfo["hint_string"] = prop.hint_string propinfo["usage"] = prop.usage propinfo["default_value"] = prop.default propinfo["rset_mode"] = prop.rpc return propinfo
def _build_property_info(prop): propinfo = Dictionary() propinfo['name'] = prop.name propinfo['type'] = py_to_gd_type(prop.type) propinfo['hint'] = prop.hint propinfo['hint_string'] = prop.hint_string propinfo['usage'] = prop.usage propinfo['default_value'] = prop.default propinfo['rset_mode'] = prop.rpc return propinfo
def test_delitem(self): v = Dictionary({"a": 1, 2: "foo", 0.5: Vector2()}) del v["a"] assert len(v) == 2 del v[0.5] assert len(v) == 1 v[2] == "foo" # Missing items can be deleted without error del v["missing"] # Cannot store non Godot types with pytest.raises(TypeError): del v[object()]
def test_delitem(self): v = Dictionary({'a': 1, 2: 'foo', 0.5: Vector2()}) del v['a'] assert len(v) == 2 del v[0.5] assert len(v) == 1 v[2] == 'foo' # Missing items can be deleted without error del v['missing'] # Cannot store non Godot types with pytest.raises(TypeError): del v[object()]
def _build_method_info(meth, methname): spec = inspect.getfullargspec(meth) methinfo = Dictionary() methinfo["name"] = methname # TODO: Handle classmethod/staticmethod methinfo["args"] = Array(spec.args) methinfo["default_args"] = Array() # TODO # TODO: use annotation to determine return type ? methinfo["return"] = None methinfo["flags"] = lib.METHOD_FLAG_FROM_SCRIPT methinfo["rpc_mode"] = getattr(meth, "__rpc", lib.GODOT_METHOD_RPC_MODE_DISABLED) return methinfo
def test_setitem(self): v = Dictionary({'a': 1, 2: 'foo', 0.5: Vector2()}) v[0] = 'bar' assert len(v) == 4 assert v[0] == 'bar' v['a'] = 4 assert len(v) == 4 assert v['a'] == 4 # Cannot store non Godot types with pytest.raises(TypeError): v[object()] = 4 with pytest.raises(TypeError): v[4] = object()
def test_setitem(self): v = Dictionary({"a": 1, 2: "foo", 0.5: Vector2()}) v[0] = "bar" assert len(v) == 4 assert v[0] == "bar" v["a"] = 4 assert len(v) == 4 assert v["a"] == 4 # Cannot store non Godot types with pytest.raises(TypeError): v[object()] = 4 with pytest.raises(TypeError): v[4] = object()
def test_iter(self): v = Dictionary({"a": 1, 2: "foo", 0.5: Vector2()}) items = ["a", 2, 0.5] items_from_v = [x for x in v] assert set(items_from_v) == set(items)
def test_items(self): v = Dictionary({"a": 1, 2: "foo"}) items = v.items() assert set(items) == set([("a", 1), (2, "foo")])
def test_instantiate_from_copy(self, arg): arr = Dictionary(arg) if hasattr(arg, "_gd_ptr"): assert arr._gd_ptr != arg._gd_ptr
def test_len(self): v = Dictionary() assert len(v) == 0 v["foo"] = "bar" assert len(v) == 1
class TestDictionary: def test_base(self): v = Dictionary() assert type(v) == Dictionary @pytest.mark.xfail( reason="Godot Dictionary equal does lame comparison by pointer so far..." ) def test_equal(self): arr = Dictionary() other = Dictionary() for key, value in [("a", 1), ("b", "foo"), ("c", Node()), ("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(), Node(), { "a": 1 }, Dictionary({"b": 2})]) def test_bad_equal(self, arg): arr = Dictionary({"a": 1}) assert arr != arg def test_repr(self): 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) @pytest.mark.parametrize( "arg", [ 42, "dummy", Node(), Vector2(), [object()], { object(): 1 }, { 1: object() } ], ) def test_bad_instantiate(self, arg): with pytest.raises(TypeError): Dictionary(arg) @pytest.mark.parametrize( "arg", [ Dictionary(), {}, { "a": 1, 2: "foo", 0.5: Vector2() }, Dictionary({ "a": 1, 2: "foo", 0.5: Vector2() }), ], ) def test_instantiate_from_copy(self, arg): arr = Dictionary(arg) if hasattr(arg, "_gd_ptr"): assert arr._gd_ptr != arg._gd_ptr def test_len(self): v = Dictionary() assert len(v) == 0 v["foo"] = "bar" assert len(v) == 1 def test_getitem(self): v = Dictionary({"a": 1, 2: "foo", 0.5: Vector2()}) assert v["a"] == 1 assert v[0.5] == Vector2() # Missing items are stored as None assert v["dummy"] is None # Cannot store non Godot types with pytest.raises(TypeError): v[object()] def test_setitem(self): v = Dictionary({"a": 1, 2: "foo", 0.5: Vector2()}) v[0] = "bar" assert len(v) == 4 assert v[0] == "bar" v["a"] = 4 assert len(v) == 4 assert v["a"] == 4 # Cannot store non Godot types with pytest.raises(TypeError): v[object()] = 4 with pytest.raises(TypeError): v[4] = object() def test_delitem(self): v = Dictionary({"a": 1, 2: "foo", 0.5: Vector2()}) del v["a"] assert len(v) == 2 del v[0.5] assert len(v) == 1 v[2] == "foo" # Missing items can be deleted without error del v["missing"] # Cannot store non Godot types with pytest.raises(TypeError): del v[object()] def test_update(self): v = Dictionary({'a': 1, 'b': 2, 'c': 3}) v.update({'a': 'one', 'd': 'four'}) v.update(Dictionary({'b': 'two', 'e': 'five'})) assert set(v.keys()) == {'a', 'b', 'c', 'd', 'e'} assert set(v.values()) == {'one', 'two', 3, 'four', 'five'} def test_contains(self): v = Dictionary({"a": 1, 2: "foo", 0.5: Vector2()}) assert "a" in v assert "dummy" not in v def test_iter(self): v = Dictionary({"a": 1, 2: "foo", 0.5: Vector2()}) items = ["a", 2, 0.5] items_from_v = [x for x in v] assert set(items_from_v) == set(items) def test_keys(self): v = Dictionary({"a": 1, 2: "foo", 0.5: Vector2()}) keys = v.keys() assert set(keys) == set(["a", 2, 0.5]) def test_values(self): v = Dictionary({"a": 1, 2: "foo"}) values = v.values() assert set(values) == set([1, "foo"]) def test_items(self): v = Dictionary({"a": 1, 2: "foo"}) items = v.items() assert set(items) == set([("a", 1), (2, "foo")]) def test_empty_and_clear(self): v = Dictionary({"a": 1, 2: "foo"}) assert not v.empty() v.clear() assert len(v) == 0 assert v.empty() def test_in(self): v = Dictionary({"a": 1, 2: "foo"}) assert "a" in v assert "dummy" not in v def test_hash(self): v = Dictionary({"a": 1, 2: "foo"}) v.hash() def test_has_all(self): 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) def test_to_json(self): v = Dictionary({"a": 1, "b": "foo"}) jsoned = v.to_json() v2 = json.loads(jsoned) assert v2 == {"a": 1, "b": "foo"} assert json
def test_base(self): v = Dictionary() assert type(v) == Dictionary
def test_keys(self): v = Dictionary({"a": 1, 2: "foo", 0.5: Vector2()}) keys = v.keys() assert set(keys) == set(["a", 2, 0.5])
def test_bad_instantiate(self, arg): with pytest.raises(TypeError): Dictionary(arg)
def test_to_json(self): v = Dictionary({"a": 1, "b": "foo"}) jsoned = v.to_json() v2 = json.loads(jsoned) assert v2 == {"a": 1, "b": "foo"} assert json
def test_bad_equal(self, arg): arr = Dictionary({"a": 1}) assert arr != arg
def test_has_all(self): 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)
def test_hash(self): v = Dictionary({"a": 1, 2: "foo"}) v.hash()
def test_in(self): v = Dictionary({"a": 1, 2: "foo"}) assert "a" in v assert "dummy" not in v
def test_empty_and_clear(self): v = Dictionary({"a": 1, 2: "foo"}) assert not v.empty() v.clear() assert len(v) == 0 assert v.empty()
def test_values(self): v = Dictionary({"a": 1, 2: "foo"}) values = v.values() assert set(values) == set([1, "foo"])