Skip to content

Commit a8cdf67

Browse files
committed
Skipping one test in old version of CPython.
Fixing style.
1 parent a963c16 commit a8cdf67

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@
2121
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
2222
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
2323
# OF THE POSSIBILITY OF SUCH DAMAGE.
24-
# Qunaibit 02/05/2014
25-
# With Statement
2624

2725
import unittest
2826
import zlib
2927
import binascii
3028
import re
29+
import sys
3130

3231
pintNumber = 98765432109876543210
3332
longNumber = 9876543210
@@ -165,14 +164,16 @@ def test_speech(self):
165164
self.assertEqual(zlib.decompress(x), HAMLET_SCENE)
166165

167166
def test_keywords(self):
168-
x = zlib.compress(HAMLET_SCENE, level=3)
169-
self.assertEqual(zlib.decompress(x), HAMLET_SCENE)
170-
with self.assertRaises(TypeError):
171-
zlib.compress(data=HAMLET_SCENE, level=3)
172-
self.assertEqual(zlib.decompress(x,
167+
if (sys.version_info.major >= 3 and sys.version_info.minor >= 6):
168+
# the keywords were added later
169+
x = zlib.compress(HAMLET_SCENE, level=3)
170+
self.assertEqual(zlib.decompress(x), HAMLET_SCENE)
171+
with self.assertRaises(TypeError):
172+
zlib.compress(data=HAMLET_SCENE, level=3)
173+
self.assertEqual(zlib.decompress(x,
173174
wbits=zlib.MAX_WBITS,
174175
bufsize=zlib.DEF_BUF_SIZE),
175-
HAMLET_SCENE)
176+
HAMLET_SCENE)
176177

177178
def test_speech128(self):
178179
# compress more data

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ZLibModuleBuiltins.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ private CastToIntegerFromIntNode getCastToIntNode() {
238238

239239
@Specialization
240240
@TruffleBoundary
241-
public long doit(PIBytesLike data, PNone value) {
241+
public long doit(PIBytesLike data, @SuppressWarnings("unused") PNone value) {
242242
CRC32 crc32 = new CRC32();
243243
crc32.update(getToArrayNode().execute(data.getSequenceStorage()));
244244
return crc32.getValue();
@@ -249,15 +249,15 @@ public long doit(PIBytesLike data, long value) {
249249
// lost magnitude is ok here.
250250
int initValue = (int) value;
251251
byte[] array = getToArrayNode().execute(data.getSequenceStorage());
252-
return ((long) computeCRC32(array, initValue) & 0xFFFFFFFFL);
252+
return computeCRC32(array, initValue) & 0xFFFFFFFFL;
253253
}
254254

255255
@Specialization
256256
public long doPInt(PIBytesLike data, PInt value) {
257257
// lost magnitude is ok here.
258258
int initValue = value.intValue();
259259
byte[] array = getToArrayNode().execute(data.getSequenceStorage());
260-
return ((long) computeCRC32(array, initValue) & 0xFFFFFFFFL);
260+
return computeCRC32(array, initValue) & 0xFFFFFFFFL;
261261
}
262262

263263
@Specialization
@@ -267,7 +267,7 @@ public long doObject(PIBytesLike data, Object value,
267267
}
268268

269269
@Fallback
270-
public long doObject(Object data, Object value) {
270+
public long doObject(Object data, @SuppressWarnings("unused") Object value) {
271271
throw raise(TypeError, "a bytes-like object is required, not '%p'", data);
272272
}
273273

@@ -329,7 +329,7 @@ private CastToIntegerFromIntNode getCastToIntNode() {
329329

330330
@Specialization
331331
@TruffleBoundary
332-
public long doit(PIBytesLike data, PNone value) {
332+
public long doit(PIBytesLike data, @SuppressWarnings("unused") PNone value) {
333333
Adler32 adler32 = new Adler32();
334334
adler32.update(getToArrayNode().execute(data.getSequenceStorage()));
335335
return adler32.getValue();
@@ -340,15 +340,15 @@ public long doit(PIBytesLike data, long value) {
340340
// lost magnitude is ok here.
341341
int initValue = (int) value;
342342
byte[] array = getToArrayNode().execute(data.getSequenceStorage());
343-
return ((long) computeAdler32(array, initValue) & 0xFFFFFFFFL);
343+
return computeAdler32(array, initValue) & 0xFFFFFFFFL;
344344
}
345345

346346
@Specialization
347347
public long doPInt(PIBytesLike data, PInt value) {
348348
// lost magnitude is ok here.
349349
int initValue = value.intValue();
350350
byte[] array = getToArrayNode().execute(data.getSequenceStorage());
351-
return ((long) computeAdler32(array, initValue) & 0xFFFFFFFFL);
351+
return computeAdler32(array, initValue) & 0xFFFFFFFFL;
352352
}
353353

354354
@Specialization
@@ -358,7 +358,7 @@ public long doObject(PIBytesLike data, Object value,
358358
}
359359

360360
@Fallback
361-
public long doObject(Object data, Object value) {
361+
public long doObject(Object data, @SuppressWarnings("unused") Object value) {
362362
throw raise(TypeError, "a bytes-like object is required, not '%p'", data);
363363
}
364364

@@ -399,7 +399,7 @@ private static byte[] compress(byte[] input, int level) {
399399
}
400400

401401
@Specialization
402-
public PBytes doit(PIBytesLike data, PNone level) {
402+
public PBytes doit(PIBytesLike data, @SuppressWarnings("unused") PNone level) {
403403
byte[] array = getToArrayNode().execute(data.getSequenceStorage());
404404
return factory().createBytes(compress(array, -1));
405405
}
@@ -470,7 +470,7 @@ private byte[] decompress(byte[] input, @SuppressWarnings("unused") int wbits, i
470470

471471
@Specialization
472472
@TruffleBoundary
473-
public PBytes doit(PIBytesLike data, PNone wbits, PNone bufsize) {
473+
public PBytes doit(PIBytesLike data, @SuppressWarnings("unused") PNone wbits, @SuppressWarnings("unused") PNone bufsize) {
474474
byte[] array = getToArrayNode().execute(data.getSequenceStorage());
475475
return factory().createBytes(decompress(array, MAX_WBITS, DEF_BUF_SIZE));
476476
}
@@ -485,11 +485,9 @@ public PBytes decompress(PIBytesLike data, long wbits, int bufsize) {
485485
// checking bufsize
486486
if (bufSizeProfile.profile(bufsize < 0)) {
487487
throw raise(ZLibError, "bufsize must be non-negative");
488-
} else if (bufsize == 0) {
489-
bufsize = 1;
490488
}
491489
byte[] array = getToArrayNode().execute(data.getSequenceStorage());
492-
return factory().createBytes(decompress(array, (int) wbits, bufsize));
490+
return factory().createBytes(decompress(array, (int) wbits, bufsize == 0 ? 1 : bufsize));
493491
}
494492

495493
@Specialization

0 commit comments

Comments
 (0)