mirror of
https://github.com/sqlalchemy/sqlalchemy.git
synced 2026-05-15 05:07:16 -04:00
25c2b7dd10
Create a new test file test_tm_future_annotations_sync.py that's obtained from test_tm_future_annotations.py by using the new script sync_test_files. This files includes the ``from __future__ import annotations`` It also turns out we had some bugs in there and we can also support some additional typing things Change-Id: Iac005df206d45a55345d9d88d67a80ce799d449f
61 lines
1.4 KiB
Python
61 lines
1.4 KiB
Python
"""Synchronizes test files that require the future annotation import.
|
|
|
|
.. versionadded:: 2.0
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from argparse import ArgumentParser
|
|
from pathlib import Path
|
|
|
|
header = '''\
|
|
"""This file is automatically generated from the file
|
|
{source!r}
|
|
by the {this_file!r} script.
|
|
|
|
Do not edit manually, any change will be lost.
|
|
""" # noqa: E501
|
|
|
|
from __future__ import annotations
|
|
|
|
'''
|
|
|
|
home = Path(__file__).parent.parent
|
|
this_file = Path(__file__).relative_to(home).as_posix()
|
|
remove_str = '# anno only: '
|
|
|
|
def run_operation(name: str, source: str, dest: str):
|
|
print("Running", name, "...", end="", flush=True)
|
|
|
|
source_data = Path(source).read_text().replace(remove_str, '')
|
|
dest_data = header.format(source=source, this_file=this_file) + source_data
|
|
|
|
Path(dest).write_text(dest_data)
|
|
|
|
print(".. done")
|
|
|
|
|
|
def main(file: str):
|
|
if file == "all":
|
|
operations = files.items()
|
|
else:
|
|
operations = [(file, files[file])]
|
|
|
|
for name, info in operations:
|
|
run_operation(name, info["source"], info["dest"])
|
|
|
|
|
|
files = {
|
|
"typed_annotation": {
|
|
"source": "test/orm/declarative/test_typed_mapping.py",
|
|
"dest": "test/orm/declarative/test_tm_future_annotations_sync.py",
|
|
}
|
|
}
|
|
|
|
if __name__ == "__main__":
|
|
parser = ArgumentParser()
|
|
parser.add_argument("--file", choices=list(files) + ["all"], default="all")
|
|
|
|
args = parser.parse_args()
|
|
main(args.file)
|