From eb668be30d2fe3235f8546affd7605338ec7ca80 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 5 Nov 2026 22:08:12 -0500 Subject: [PATCH] style: use `import command` in unittests Align with Google style guides and `import command` as a module rather than import symbols out of it in the tests tree. Change-Id: I5c151d22c9ed8f8c7ea762823c8b2e25225a2ac4 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/654819 Commit-Queue: Mike Frysinger Tested-by: Mike Frysinger Reviewed-by: Brian Gan --- .flake8 | 2 -- tests/test_command.py | 16 ++++++++-------- tests/test_subcmds.py | 8 ++++---- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/.flake8 b/.flake8 index de6701b87..151418804 100644 --- a/.flake8 +++ b/.flake8 @@ -44,10 +44,8 @@ per-file-ignores = tests/e2e/test_partial_clone.py: IMR241, tests/e2e/test_sync_modes.py: IMR241, tests/e2e/test_workflows.py: IMR241, - tests/test_command.py: IMR241, tests/test_error.py: IMR241, tests/test_main.py: IMR241, - tests/test_subcmds.py: IMR241, tests/test_subcmds_sync.py: IMR241, extend-ignore = # E203: Whitespace before ':' diff --git a/tests/test_command.py b/tests/test_command.py index 45bb09f2c..bd09ccd38 100644 --- a/tests/test_command.py +++ b/tests/test_command.py @@ -18,7 +18,7 @@ from typing import Iterable, List, Optional import pytest -from command import Command +import command class FakeProject: @@ -136,7 +136,7 @@ def test_get_projects_keeps_derived_subprojects_for_repeated_repo(): sync_s=True, ) manifest = FakeManifest([project_a, project_b]) - cmd = Command(manifest=manifest) + cmd = command.Command(manifest=manifest) projects = cmd.GetProjects([]) @@ -165,7 +165,7 @@ def test_get_projects_submodule_override( derived_subprojects=[submodule], sync_s=sync_s, ) - cmd = Command(manifest=FakeManifest([project])) + cmd = command.Command(manifest=FakeManifest([project])) projects = cmd.GetProjects([], submodules_ok=submodules_ok) @@ -214,7 +214,7 @@ def test_get_projects_uses_groups_from_each_manifest_unless_overridden( all_projects=[outer_project, *child_manifest.projects], effective_groups="outer-group", ) - cmd = Command(manifest=outer_manifest) + cmd = command.Command(manifest=outer_manifest) projects = cmd.GetProjects( [], @@ -248,7 +248,7 @@ def test_get_projects_by_name_uses_groups_from_each_manifest() -> None: all_projects=[outer_project, *child_manifest.projects], effective_groups="outer-group", ) - cmd = Command(manifest=outer_manifest) + cmd = command.Command(manifest=outer_manifest) projects = cmd.GetProjects( ["shared"], @@ -296,7 +296,7 @@ def test_find_projects_uses_groups_from_each_manifest() -> None: ) outer_manifest.outer_client = outer_manifest - cmd = Command(manifest=outer_manifest) + cmd = command.Command(manifest=outer_manifest) projects = cmd.FindProjects(["match"], all_manifests=True) @@ -322,7 +322,7 @@ def test_find_projects_uses_explicit_groups() -> None: [default_project, override_project], effective_groups="default-group", ) - cmd = Command(manifest=manifest) + cmd = command.Command(manifest=manifest) projects = cmd.FindProjects( ["override"], @@ -339,7 +339,7 @@ def test_find_projects_allows_missing_projects() -> None: "missing", exists=False, ) - cmd = Command(manifest=FakeManifest([project])) + cmd = command.Command(manifest=FakeManifest([project])) projects = cmd.FindProjects( ["missing"], diff --git a/tests/test_subcmds.py b/tests/test_subcmds.py index 3a52f2284..17661b97c 100644 --- a/tests/test_subcmds.py +++ b/tests/test_subcmds.py @@ -19,7 +19,7 @@ from typing import Type import pytest -from command import Command +import command import subcmds from subcmds import sync @@ -49,7 +49,7 @@ def test_naming(name: str) -> None: @pytest.mark.parametrize("name, cls", subcmds.all_commands.items()) -def test_help_desc_style(name: str, cls: Type[Command]) -> None: +def test_help_desc_style(name: str, cls: Type[command.Command]) -> None: """Force some consistency in option descriptions. Python's optparse & argparse has a few default options like --help. @@ -79,7 +79,7 @@ def test_help_desc_style(name: str, cls: Type[Command]) -> None: @pytest.mark.parametrize("name, cls", subcmds.all_commands.items()) -def test_cli_option_style(name: str, cls: Type[Command]) -> None: +def test_cli_option_style(name: str, cls: Type[command.Command]) -> None: """Force some consistency in option flags.""" cmd = cls() parser = cmd.OptionParser @@ -142,7 +142,7 @@ def test_cli_option_dest() -> None: @pytest.mark.parametrize("name, cls", subcmds.all_commands.items()) -def test_common_validate_options(name: str, cls: Type[Command]) -> None: +def test_common_validate_options(name: str, cls: Type[command.Command]) -> None: """Verify CommonValidateOptions sets up expected fields.""" cmd = cls() opts, args = cmd.OptionParser.parse_args([])