Skip to content

Commit 75f635f

Browse files
committed
Fix failing panda tests after CSV intrinsification.
- The first fix concerned a test testing for an exact error message, where CPython used quotes around an attribute name and Graalpython didn't. - The second fix was necessary because the CSV intrinsification was based on the most recent CSV implementation from CPython. A recent commit fixes that until 3.10 empty quotechars and escapechars were accepted from CPython. This lead to a different error message being displayed when the quotechar was set to "" and quoting was enabled. For compatability Graalpython now follows CPython 3.8 and allows empty quotechars and escapechars.
1 parent 577e02d commit 75f635f

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -41,7 +41,7 @@
4141
import csv
4242
from tempfile import TemporaryFile
4343

44-
class CsvTest(unittest.TestCase):
44+
class TestUnicodeCharacters(unittest.TestCase):
4545
def test_read_utf_32_delimiter(self):
4646
test_data = ['a\U0001F642b']
4747
reader = csv.reader(test_data, delimiter="\U0001F642")
@@ -74,6 +74,32 @@ def test_write_utf32_field_with_utf32_delimiter(self):
7474
self.assertEqual(fileobj.read(),
7575
expected + writer.dialect.lineterminator)
7676

77+
class TestDialectValidity(unittest.TestCase):
78+
# CPython supports empty quotechars and escapechars until 3.10.
79+
def test_quoting(self):
80+
class MyDialect(csv.Dialect):
81+
delimiter = ";"
82+
escapechar = '\\'
83+
doublequote = False
84+
skipinitialspace = True
85+
lineterminator = '\r\n'
86+
quoting = csv.QUOTE_NONE
87+
quotechar = ""
88+
d = MyDialect()
89+
self.assertEqual(d.quotechar, "")
90+
91+
def test_escapechar(self):
92+
class MyDialect(csv.Dialect):
93+
delimiter = ";"
94+
doublequote = False
95+
skipinitialspace = True
96+
lineterminator = '\r\n'
97+
quoting = csv.QUOTE_NONE
98+
escapechar = ""
99+
d = MyDialect()
100+
self.assertEqual(d.escapechar, "")
101+
102+
77103

78104

79105

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/csv/CSVModuleBuiltins.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -531,10 +531,15 @@ private String getChar(String name, Object valueObj, String defaultValue,
531531
throw raise(TypeError, ErrorMessages.S_MUST_BE_STRING_NOT_S, name, getType.execute(valueObj));
532532
}
533533

534-
if (charValue.length() != 1 && charValue.codePointCount(0, charValue.length()) != 1) {
534+
if (charValue.length() > 1 && charValue.codePointCount(0, charValue.length()) > 1) {
535535
throw raise(TypeError, ErrorMessages.MUST_BE_ONE_CHARACTER_STRING, name);
536536
}
537537

538+
// CPython supports empty quotechars and escapechars until 3.10.
539+
if (charValue.length() == 0) {
540+
return NOT_SET;
541+
}
542+
538543
return charValue;
539544
}
540545

@@ -592,7 +597,7 @@ private QuoteStyle getQuotingValue(VirtualFrame frame, String name, Object value
592597
}
593598

594599
if (!pyLongCheckExactNode.execute(valueObj)) {
595-
throw raise(TypeError, ErrorMessages.MUST_BE_INTEGER, name);
600+
throw raise(TypeError, ErrorMessages.MUST_BE_INTEGER_QUOTED_ATTR, name);
596601
}
597602

598603
int value = pyLongAsIntNode.execute(frame, valueObj);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/ErrorMessages.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -448,6 +448,7 @@ public abstract class ErrorMessages {
448448
public static final String MUST_BE_BYTE_STRING_LEGTH1_NOT_P = "must be a byte string of length 1, not %p";
449449
public static final String MUST_BE_EITHER_OR = "%s: '%s' must be either %s or %s";
450450
public static final String MUST_BE_INTEGER = "%s must be an integer";
451+
public static final String MUST_BE_INTEGER_QUOTED_ATTR = "\"%s\" must be an integer";
451452
public static final String MUST_BE_INTEGER_NOT_P = "%s must be an integer, not %p";
452453
public static final String MUST_BE_NON_NEGATIVE = "%s must be non-negative";
453454
public static final String MUST_BE_NON_NEGATIVE_INTEGER = "%s must be non-negative integer";

0 commit comments

Comments
 (0)