gh-105540: Convert pytest tests of cases_generator to regular tests (#106713)

This commit is contained in:
Nikita Sobolev 2023-07-17 02:05:24 +03:00 committed by GitHub
parent 4dc593477a
commit c41320701b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 211 additions and 156 deletions

View file

@ -156,16 +156,9 @@ class Formatter:
self.emit_line_directives = emit_line_directives
self.comment = comment
self.lineno = 1
filename = os.path.relpath(self.stream.name, ROOT)
# Make filename more user-friendly and less platform-specific
filename = filename.replace("\\", "/")
if filename.startswith("./"):
filename = filename[2:]
if filename.endswith(".new"):
filename = filename[:-4]
self.filename = filename
self.filename = prettify_filename(self.stream.name)
self.nominal_lineno = 1
self.nominal_filename = filename
self.nominal_filename = self.filename
def write_raw(self, s: str) -> None:
self.stream.write(s)
@ -737,12 +730,8 @@ class Analyzer:
with open(filename) as file:
src = file.read()
filename = os.path.relpath(filename, ROOT)
# Make filename more user-friendly and less platform-specific
filename = filename.replace("\\", "/")
if filename.startswith("./"):
filename = filename[2:]
psr = parser.Parser(src, filename=filename)
psr = parser.Parser(src, filename=prettify_filename(filename))
# Skip until begin marker
while tkn := psr.next(raw=True):
@ -1149,7 +1138,7 @@ class Analyzer:
def from_source_files(self) -> str:
paths = f"\n{self.out.comment} ".join(
os.path.relpath(filename, ROOT).replace(os.path.sep, posixpath.sep)
prettify_filename(filename)
for filename in self.input_filenames
)
return f"{self.out.comment} from:\n{self.out.comment} {paths}\n"
@ -1597,6 +1586,17 @@ class Analyzer:
self.out.emit(f"DISPATCH();")
def prettify_filename(filename: str) -> str:
# Make filename more user-friendly and less platform-specific,
# it is only used for error reporting at this point.
filename = filename.replace("\\", "/")
if filename.startswith("./"):
filename = filename[2:]
if filename.endswith(".new"):
filename = filename[:-4]
return filename
def extract_block_text(block: parser.Block) -> tuple[list[str], bool, int]:
# Get lines of text with proper dedent
blocklines = block.text.splitlines(True)