mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
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:
parent
30840706b0
commit
483d130e50
2 changed files with 16 additions and 12 deletions
|
@ -62,17 +62,17 @@ class TestAsdlParser(unittest.TestCase):
|
||||||
alias = self.types['alias']
|
alias = self.types['alias']
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
str(alias),
|
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, 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):
|
def test_attributes(self):
|
||||||
stmt = self.types['stmt']
|
stmt = self.types['stmt']
|
||||||
self.assertEqual(len(stmt.attributes), 4)
|
self.assertEqual(len(stmt.attributes), 4)
|
||||||
self.assertEqual(repr(stmt.attributes[0]), 'Field(int, lineno)')
|
self.assertEqual(repr(stmt.attributes[0]), 'Field(int, lineno)')
|
||||||
self.assertEqual(repr(stmt.attributes[1]), 'Field(int, col_offset)')
|
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[2]), 'Field(int, end_lineno, quantifiers=[OPTIONAL])')
|
||||||
self.assertEqual(repr(stmt.attributes[3]), 'Field(int, end_col_offset, opt=True)')
|
self.assertEqual(repr(stmt.attributes[3]), 'Field(int, end_col_offset, quantifiers=[OPTIONAL])')
|
||||||
|
|
||||||
def test_constructor_fields(self):
|
def test_constructor_fields(self):
|
||||||
ehandler = self.types['excepthandler']
|
ehandler = self.types['excepthandler']
|
||||||
|
|
|
@ -91,17 +91,21 @@ class Field(AST):
|
||||||
return "{}{} {}".format(self.type, extra, self.name)
|
return "{}{} {}".format(self.type, extra, self.name)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
extra = ""
|
if self.quantifiers:
|
||||||
for mod in self.quantifiers:
|
texts = []
|
||||||
if mod is Quantifier.SEQUENCE:
|
for mod in self.quantifiers:
|
||||||
extra += ", SEQUENCE"
|
if mod is Quantifier.SEQUENCE:
|
||||||
elif mod is Quantifier.OPTIONAL:
|
texts.append("SEQUENCE")
|
||||||
extra += ", OPTIONAL"
|
elif mod is Quantifier.OPTIONAL:
|
||||||
|
texts.append("OPTIONAL")
|
||||||
|
extra = ", quantifiers=[{}]".format(", ".join(texts))
|
||||||
|
else:
|
||||||
|
extra = ""
|
||||||
|
|
||||||
if self.name is None:
|
if self.name is None:
|
||||||
return 'Field({0.type}, quantifiers=[{1}])'.format(self, extra)
|
return 'Field({0.type}{1})'.format(self, extra)
|
||||||
else:
|
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):
|
class Sum(AST):
|
||||||
def __init__(self, types, attributes=None):
|
def __init__(self, types, attributes=None):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue