gh-131421: Fix ASDL tests (#133408)

PR #131419 broke this, but we failed to run tests on the PR due to a bug
in our script.
This commit is contained in:
Jelle Zijlstra 2025-05-04 16:46:21 -07:00 committed by GitHub
parent 30840706b0
commit 483d130e50
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 12 deletions

View file

@ -62,17 +62,17 @@ class TestAsdlParser(unittest.TestCase):
alias = self.types['alias']
self.assertEqual(
str(alias),
'Product([Field(identifier, name), Field(identifier, asname, opt=True)], '
'Product([Field(identifier, name), Field(identifier, asname, quantifiers=[OPTIONAL])], '
'[Field(int, lineno), Field(int, col_offset), '
'Field(int, end_lineno, opt=True), Field(int, end_col_offset, opt=True)])')
'Field(int, end_lineno, quantifiers=[OPTIONAL]), Field(int, end_col_offset, quantifiers=[OPTIONAL])])')
def test_attributes(self):
stmt = self.types['stmt']
self.assertEqual(len(stmt.attributes), 4)
self.assertEqual(repr(stmt.attributes[0]), 'Field(int, lineno)')
self.assertEqual(repr(stmt.attributes[1]), 'Field(int, col_offset)')
self.assertEqual(repr(stmt.attributes[2]), 'Field(int, end_lineno, opt=True)')
self.assertEqual(repr(stmt.attributes[3]), 'Field(int, end_col_offset, opt=True)')
self.assertEqual(repr(stmt.attributes[2]), 'Field(int, end_lineno, quantifiers=[OPTIONAL])')
self.assertEqual(repr(stmt.attributes[3]), 'Field(int, end_col_offset, quantifiers=[OPTIONAL])')
def test_constructor_fields(self):
ehandler = self.types['excepthandler']

View file

@ -91,17 +91,21 @@ class Field(AST):
return "{}{} {}".format(self.type, extra, self.name)
def __repr__(self):
extra = ""
if self.quantifiers:
texts = []
for mod in self.quantifiers:
if mod is Quantifier.SEQUENCE:
extra += ", SEQUENCE"
texts.append("SEQUENCE")
elif mod is Quantifier.OPTIONAL:
extra += ", OPTIONAL"
texts.append("OPTIONAL")
extra = ", quantifiers=[{}]".format(", ".join(texts))
else:
extra = ""
if self.name is None:
return 'Field({0.type}, quantifiers=[{1}])'.format(self, extra)
return 'Field({0.type}{1})'.format(self, extra)
else:
return 'Field({0.type}, {0.name}, quantifiers=[{1}])'.format(self, extra)
return 'Field({0.type}, {0.name}{1})'.format(self, extra)
class Sum(AST):
def __init__(self, types, attributes=None):