1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
from pathlib import Path
from pytest_snapshot.plugin import Snapshot
from typer import Typer
from typer.testing import CliRunner
HERE = Path(__file__).parent
def test_upgrade_returns_error_code_if_codemod_does_not_exist(
cli_app: Typer, cli_runner: CliRunner
):
result = cli_runner.invoke(
cli_app,
["upgrade", "a_random_codemod", "."],
)
assert result.exit_code == 2
assert 'Upgrade named "a_random_codemod" does not exist' in result.stdout
def test_upgrade_works_annotated_unions(
cli_app: Typer, cli_runner: CliRunner, tmp_path: Path, snapshot: Snapshot
):
source = HERE / "fixtures/unions.py"
target = tmp_path / "unions.py"
target.write_text(source.read_text())
result = cli_runner.invoke(
cli_app,
["upgrade", "--python-target", "3.11", "annotated-union", str(target)],
)
assert result.exit_code == 1
assert "1 files changed\n - 0 files skipped" in result.stdout
snapshot.snapshot_dir = HERE / "snapshots"
snapshot.assert_match(target.read_text(), "unions.py")
def test_upgrade_works_annotated_unions_typing_extensions(
cli_app: Typer, cli_runner: CliRunner, tmp_path: Path, snapshot: Snapshot
):
source = HERE / "fixtures/unions.py"
target = tmp_path / "unions.py"
target.write_text(source.read_text())
result = cli_runner.invoke(
cli_app,
[
"upgrade",
"--use-typing-extensions",
"--python-target",
"3.11",
"annotated-union",
str(target),
],
)
assert result.exit_code == 1
assert "1 files changed\n - 0 files skipped" in result.stdout
snapshot.snapshot_dir = HERE / "snapshots"
snapshot.assert_match(target.read_text(), "unions_typing_extension.py")
|