@@ -73,6 +73,30 @@ def test_eval_objects_proxy_proto():
7373 assert pm .null == pm .eval ("(o) => Object.getPrototypeOf(o)" )({})
7474 assert pm .null == pm .eval ("(o) => Object.getPrototypeOf(o)" )({ "abc" : 1 })
7575
76+ def test_eval_objects_proxy_iterate ():
77+ obj = pm .eval ("({ a: 123, b: 'test' })" )
78+ result = []
79+ for i in obj :
80+ result .append (i )
81+ assert result == [('a' , 123.0 ), ('b' , 'test' )]
82+
83+ def test_eval_objects_proxy_repr ():
84+ obj = pm .eval ("({ a: 123, b: 'test' , c: { d: 1 }})" )
85+ obj .e = obj # supporting circular references
86+ expected = "{'a': 123.0, 'b': 'test', 'c': {'d': 1.0}, 'e': [Circular]}"
87+ assert repr (obj ) == expected
88+ assert str (obj ) == expected
89+
90+ def test_eval_objects_proxy_dict_conversion ():
91+ obj = pm .eval ("({ a: 123, b: 'test' , c: { d: 1 }})" )
92+ d = dict (obj )
93+ assert type (obj ) is not dict # dict subclass
94+ assert type (d ) is dict # strict dict
95+ assert repr (d ) == "{'a': 123.0, 'b': 'test', 'c': {'d': 1.0}}"
96+ assert obj .keys () == ['a' , 'b' , 'c' ] # Conversion from a dict-subclass to a strict dict internally calls the .keys() method
97+ assert list (d .keys ()) == obj .keys ()
98+ assert obj == d
99+
76100def test_eval_objects_jsproxy_get ():
77101 proxy = pm .eval ("({a: 1})" )
78102 assert 1.0 == proxy ['a' ]
0 commit comments