Skip to content

Commit 9590635

Browse files
committed
[GR-23282] Make test_collections pass.
PullRequest: graalpython/1672
2 parents 7c4362e + 43a1a45 commit 9590635

File tree

6 files changed

+39
-8
lines changed

6 files changed

+39
-8
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_dict.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@ def test_init():
140140

141141
assert_raises(TypeError, dict.fromkeys, 10)
142142

143+
d = {'a':1, 'b':2}
144+
d.__init__()
145+
assert d == {'a':1, 'b':2}
146+
d.__init__({'c':3})
147+
assert d == {'a':1, 'b':2, 'c':3}
148+
d.__init__({'d':4})
149+
assert d == {'a':1, 'b':2, 'c':3, 'd':4}
143150

144151
def test_init1():
145152
try:

graalpython/com.oracle.graal.python.test/src/tests/test_set.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
# ankitv 10/10/13
4141
# Iterating by Sequence Index
4242

43+
from collections.abc import MutableSet
4344

4445
def assert_raises(err, fn, *args, **kwargs):
4546
raised = False
@@ -315,6 +316,12 @@ def test_same_id():
315316
empty_ids = set([id(frozenset()) for i in range(100)])
316317
assert len(empty_ids) == 1
317318

319+
def test_init():
320+
s = {1, 2, 3}
321+
s.__init__({4})
322+
assert s == {4}
323+
s.__init__()
324+
assert s == set()
318325

319326
def test_rich_compare():
320327
class TestRichSetCompare:

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_collections.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*graalpython.lib-python.3.test.test_collections.TestCollectionABCs.test_issue26915
2525
*graalpython.lib-python.3.test.test_collections.TestCollectionABCs.test_issue8750
2626
*graalpython.lib-python.3.test.test_collections.TestCollectionABCs.test_issue_5647
27+
*graalpython.lib-python.3.test.test_collections.TestCounter.test_basics
2728
*graalpython.lib-python.3.test.test_collections.TestCounter.test_conversions
2829
*graalpython.lib-python.3.test.test_collections.TestCounter.test_copy_subclass
2930
*graalpython.lib-python.3.test.test_collections.TestCounter.test_copying
@@ -54,6 +55,7 @@
5455
*graalpython.lib-python.3.test.test_collections.TestNamedTuple.test_readonly
5556
*graalpython.lib-python.3.test.test_collections.TestNamedTuple.test_repr
5657
*graalpython.lib-python.3.test.test_collections.TestNamedTuple.test_tupleness
58+
*graalpython.lib-python.3.test.test_collections.TestOneTrickPonyABCs.test_AsyncGenerator
5759
*graalpython.lib-python.3.test.test_collections.TestOneTrickPonyABCs.test_AsyncIterable
5860
*graalpython.lib-python.3.test.test_collections.TestOneTrickPonyABCs.test_AsyncIterator
5961
*graalpython.lib-python.3.test.test_collections.TestOneTrickPonyABCs.test_Callable

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictBuiltins.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,11 @@ private HashingStorage.InitNode getInitNode() {
136136
@Specialization(guards = {"args.length == 1", "firstArgIterable(args, lib)", "!firstArgString(args)"})
137137
Object doVarargs(VirtualFrame frame, PDict self, Object[] args, PKeyword[] kwargs,
138138
@Cached SetDictStorageNode setStorage,
139-
@SuppressWarnings("unused") @CachedLibrary(limit = "1") PythonObjectLibrary lib) {
140-
setStorage.execute(self, getInitNode().execute(frame, args[0], kwargs));
139+
@SuppressWarnings("unused") @CachedLibrary(limit = "1") PythonObjectLibrary lib,
140+
@CachedLibrary(limit = "1") HashingStorageLibrary storageLib) {
141+
HashingStorage storage = self.getDictStorage();
142+
storage = storageLib.addAllToOther(getInitNode().execute(frame, args[0], kwargs), storage);
143+
setStorage.execute(self, storage);
141144
return PNone.NONE;
142145
}
143146

@@ -155,10 +158,19 @@ static Object doString(Object self, Object[] args, PKeyword[] kwargs,
155158
throw raise.raise(ValueError, ErrorMessages.DICT_UPDATE_SEQ_ELEM_HAS_LENGTH_2_REQUIRED, 0, 1);
156159
}
157160

158-
@Specialization(guards = "args.length == 0")
161+
@Specialization(guards = {"args.length == 0", "kwargs.length > 0"})
159162
Object doKeywords(VirtualFrame frame, PDict self, @SuppressWarnings("unused") Object[] args, PKeyword[] kwargs,
160-
@Cached SetDictStorageNode setStorage) {
161-
setStorage.execute(self, getInitNode().execute(frame, NO_VALUE, kwargs));
163+
@Cached SetDictStorageNode setStorage,
164+
@CachedLibrary(limit = "1") HashingStorageLibrary storageLib) {
165+
HashingStorage storage = self.getDictStorage();
166+
storage = storageLib.addAllToOther(getInitNode().execute(frame, NO_VALUE, kwargs), storage);
167+
setStorage.execute(self, storage);
168+
return PNone.NONE;
169+
}
170+
171+
@SuppressWarnings("unused")
172+
@Specialization(guards = {"args.length == 0", "kwargs.length == 0"})
173+
Object doEmpty(PDict self, Object[] args, PKeyword[] kwargs) {
162174
return PNone.NONE;
163175
}
164176

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/SetBuiltins.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,11 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
8686
@ImportStatic(PGuards.class)
8787
public abstract static class InitNode extends PythonBuiltinNode {
8888

89-
@Specialization(guards = "isNoValue(iterable)")
90-
@SuppressWarnings("unused")
91-
static PNone doNoValue(VirtualFrame frame, PSet self, PNone iterable) {
89+
@Specialization(guards = "isNoValue(iterable)", limit = "1")
90+
static PNone doNoValue(PSet self, @SuppressWarnings("unused") PNone iterable,
91+
@CachedLibrary("self.getDictStorage()") HashingStorageLibrary lib) {
92+
HashingStorage newStorage = lib.clear(self.getDictStorage());
93+
self.setDictStorage(newStorage);
9294
return PNone.NONE;
9395
}
9496

graalpython/lib-python/3/test/test_collections.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,7 @@ def throw(self, *args): pass
11251125

11261126
self.assertRaises(RuntimeError, IgnoreGeneratorExit().close)
11271127

1128+
@support.impl_detail("async support", graalvm=False)
11281129
def test_AsyncGenerator(self):
11291130
class NonAGen1:
11301131
def __aiter__(self): return self

0 commit comments

Comments
 (0)