From f5243773a441a844ec69783907bfcf794f9c289d Mon Sep 17 00:00:00 2001 From: Alexander Saprykin Date: Fri, 25 Oct 2024 15:57:32 +0200 Subject: [PATCH] Enable flake8-pie plugin for ruff (#2339) --- dev/common/tdd.py | 2 +- galaxy_ng/tests/integration/api/test_repositories.py | 4 ++-- galaxy_ng/tests/integration/api/test_repository_labels.py | 2 +- .../tests/integration/api/test_ui_namespace_owners.py | 2 +- galaxy_ng/tests/integration/api/test_ui_paths.py | 8 ++++---- galaxy_ng/tests/integration/api/test_ui_paths_gateway.py | 2 +- .../tests/integration/api/test_upload_concurrency.py | 4 ++-- .../integration/cli/test_legacy_role_download_counts.py | 6 +++--- .../tests/integration/community/test_community_api.py | 4 ++-- .../community/test_community_namespace_rbac.py | 4 ++-- .../integration/community/test_v1_user_github_ids.py | 2 +- .../tests/integration/utils/client_ansible_galaxy_cli.py | 2 +- galaxy_ng/tests/integration/utils/client_ansible_lib.py | 2 +- galaxy_ng/tests/integration/utils/collections.py | 1 - galaxy_ng/tests/integration/utils/legacy.py | 2 +- galaxy_ng/tests/integration/utils/namespaces.py | 2 +- galaxy_ng/tests/integration/utils/users.py | 2 +- galaxy_ng/tests/unit/app/utils/test_galaxy.py | 2 +- profiles/community/github_mock/flaskapp.py | 4 ++-- pyproject.toml | 2 ++ 20 files changed, 30 insertions(+), 29 deletions(-) diff --git a/dev/common/tdd.py b/dev/common/tdd.py index d65f26da28..71343f9046 100644 --- a/dev/common/tdd.py +++ b/dev/common/tdd.py @@ -30,7 +30,7 @@ def get_changed_files(pr_branch, target_branch="master"): with open('/tmp/pr.diff') as f: raw = f.read() filenames = raw.split('\n') - filenames = [x for x in filenames if x.startswith('---') or x.startswith('+++')] + filenames = [x for x in filenames if x.startswith(('---', '+++'))] filenames = [x.split(None, 1)[1] for x in filenames if len(x.split(None, 1)) > 1] filenames = [x for x in filenames if not x.startswith('/dev/null')] filenames = [x.lstrip('a/') for x in filenames] diff --git a/galaxy_ng/tests/integration/api/test_repositories.py b/galaxy_ng/tests/integration/api/test_repositories.py index f085a09b74..68f6e7412c 100644 --- a/galaxy_ng/tests/integration/api/test_repositories.py +++ b/galaxy_ng/tests/integration/api/test_repositories.py @@ -121,7 +121,7 @@ def test_move_cv_endpoint(self, galaxy_client): # read tcp 172.18.0.2:47338->172.18.0.3:55001: read: connection reset by peer repo_pulp_href_2 = None retries = 10 - for _ in range(0, retries): + for _ in range(retries): try: repo_pulp_href_2 = create_repo_and_dist(gc_admin, test_repo_name_2) break @@ -141,7 +141,7 @@ def test_move_cv_endpoint(self, galaxy_client): # readfrom tcp 172.18.0.3:37490->172.18.0.2:55001: # write tcp 172.18.0.3:37490->172.18.0.2:55001: use of closed network connection retries = 10 - for _ in range(0, retries): + for _ in range(retries): try: move_content_between_repos( gc_admin, content_units, repo_pulp_href_1, [repo_pulp_href_2] diff --git a/galaxy_ng/tests/integration/api/test_repository_labels.py b/galaxy_ng/tests/integration/api/test_repository_labels.py index 0567439b3b..e365b931af 100644 --- a/galaxy_ng/tests/integration/api/test_repository_labels.py +++ b/galaxy_ng/tests/integration/api/test_repository_labels.py @@ -27,7 +27,7 @@ def test_repository_labels(galaxy_client): # to take them into account in this test case repos_to_remove = [] for repo in repos: - if repo.startswith("repo-test-") or repo.startswith("repo_ansible-"): + if repo.startswith(("repo-test-", "repo_ansible-")): repos_to_remove.append(repo) for repo in repos_to_remove: repos.remove(repo) diff --git a/galaxy_ng/tests/integration/api/test_ui_namespace_owners.py b/galaxy_ng/tests/integration/api/test_ui_namespace_owners.py index 7d504920e2..865e6bb865 100644 --- a/galaxy_ng/tests/integration/api/test_ui_namespace_owners.py +++ b/galaxy_ng/tests/integration/api/test_ui_namespace_owners.py @@ -26,7 +26,7 @@ def test_api_ui_v1_namespace_owners_users_and_group_separation(ansible_config): cfg = ansible_config('partner_engineer') with UIClient(config=cfg) as uclient: - suffix = random.choice(range(0, 1000)) + suffix = random.choice(range(1000)) group_name = f'group{suffix}' user_name = f'user{suffix}' namespace_name = f'namespace{suffix}' diff --git a/galaxy_ng/tests/integration/api/test_ui_paths.py b/galaxy_ng/tests/integration/api/test_ui_paths.py index fd65ea8f23..aa0b073824 100644 --- a/galaxy_ng/tests/integration/api/test_ui_paths.py +++ b/galaxy_ng/tests/integration/api/test_ui_paths.py @@ -274,7 +274,7 @@ def test_api_ui_v1_execution_environments_registries(ansible_config): validate_json(instance=ds, schema=schema_objectlist) # try to create one - suffix = random.choice(range(0, 1000)) + suffix = random.choice(range(1000)) rname = f'redhat.io.{suffix}' payload = { 'name': rname, @@ -395,7 +395,7 @@ def test_api_ui_v1_groups(ansible_config): validate_json(instance=grp, schema=schema_group) # try to make a group - suffix = random.choice(range(0, 1000)) + suffix = random.choice(range(1000)) payload = {'name': f'foobar{suffix}'} resp = uclient.post('_ui/v1/groups/', payload=payload) assert resp.status_code == 201 @@ -448,7 +448,7 @@ def test_api_ui_v1_groups_users_add_delete(ansible_config): cfg = ansible_config('partner_engineer') with UIClient(config=cfg) as uclient: - suffix = random.choice(range(0, 1000)) + suffix = random.choice(range(1000)) group_name = f'group{suffix}' user_name = f'user{suffix}' @@ -972,7 +972,7 @@ def test_api_ui_v1_users(ansible_config): validate_json(instance=user, schema=schema_user) # try creating a user - suffix = random.choice(range(0, 9999)) + suffix = random.choice(range(9999)) payload = { 'username': f'foobar{suffix}', 'first_name': 'foobar', diff --git a/galaxy_ng/tests/integration/api/test_ui_paths_gateway.py b/galaxy_ng/tests/integration/api/test_ui_paths_gateway.py index 5e4d28f3ce..e33f9cfaf6 100644 --- a/galaxy_ng/tests/integration/api/test_ui_paths_gateway.py +++ b/galaxy_ng/tests/integration/api/test_ui_paths_gateway.py @@ -184,7 +184,7 @@ def test_gw_api_ui_v1_execution_environments_registries(galaxy_client): validate_json(instance=ds, schema=schema_objectlist) # try to create one - suffix = random.choice(range(0, 1000)) + suffix = random.choice(range(1000)) rname = f'redhat.io.{suffix}' payload = { 'name': rname, diff --git a/galaxy_ng/tests/integration/api/test_upload_concurrency.py b/galaxy_ng/tests/integration/api/test_upload_concurrency.py index 63346b416e..778d10fee5 100644 --- a/galaxy_ng/tests/integration/api/test_upload_concurrency.py +++ b/galaxy_ng/tests/integration/api/test_upload_concurrency.py @@ -29,7 +29,7 @@ def test_upload_concurrency(ansible_config, settings, galaxy_client): create_repo_and_dist(gc, repo_name) # publishing fails 504 gateway error # make 10 namespaces - namespaces = [create_test_namespace(gc) for x in range(0, total)] + namespaces = [create_test_namespace(gc) for x in range(total)] # make a collection for each namespace artifacts = [] @@ -59,7 +59,7 @@ def test_upload_concurrency(ansible_config, settings, galaxy_client): else: print(f"Function returned: {result}") - for _ in range(0, 10): + for _ in range(10): matches, _ = search_collection_endpoint( gc, repository_name=repo_name ) diff --git a/galaxy_ng/tests/integration/cli/test_legacy_role_download_counts.py b/galaxy_ng/tests/integration/cli/test_legacy_role_download_counts.py index b494b9f0f7..78d118da46 100644 --- a/galaxy_ng/tests/integration/cli/test_legacy_role_download_counts.py +++ b/galaxy_ng/tests/integration/cli/test_legacy_role_download_counts.py @@ -78,7 +78,7 @@ def test_legacy_role_download_counter_via_cli(ansible_config): assert role['download_count'] == 0 # validate install command - for _ in range(0, 5): + for _ in range(5): with tempfile.TemporaryDirectory() as roles_path: cfg = ansible_config(github_user) install_pid = ansible_galaxy( @@ -146,8 +146,8 @@ def fake_install_role(number): # fetch the correct url N times at once validate no race conditions ... total = 20 total_threads = total - args_list = [[x] for x in range(0, total)] - kwargs_list = [{} for x in range(0, total)] + args_list = [[x] for x in range(total)] + kwargs_list = [{} for x in range(total)] with concurrent.futures.ThreadPoolExecutor(max_workers=total_threads) as executor: future_to_args_kwargs = { diff --git a/galaxy_ng/tests/integration/community/test_community_api.py b/galaxy_ng/tests/integration/community/test_community_api.py index 9a27292333..e538cb87fd 100644 --- a/galaxy_ng/tests/integration/community/test_community_api.py +++ b/galaxy_ng/tests/integration/community/test_community_api.py @@ -278,7 +278,7 @@ def test_social_auth_delete_collection(ansible_config): token=client.get_hub_token(), ) - for _ in range(0, 20): + for _ in range(20): exists_resp = client.get( f"v3/plugin/ansible/content/published/collections/index/{namespace}/{name}/" ) @@ -335,7 +335,7 @@ def test_social_auth_deprecate_collection(ansible_config): token=client.get_hub_token(), ) - for _ in range(0, 20): + for _ in range(20): exists_resp = client.get( f"v3/plugin/ansible/content/published/collections/index/{namespace}/{name}/" ) diff --git a/galaxy_ng/tests/integration/community/test_community_namespace_rbac.py b/galaxy_ng/tests/integration/community/test_community_namespace_rbac.py index 70a7fe87c7..6797d032c3 100644 --- a/galaxy_ng/tests/integration/community/test_community_namespace_rbac.py +++ b/galaxy_ng/tests/integration/community/test_community_namespace_rbac.py @@ -105,7 +105,7 @@ def test_social_auth_v3_rbac_workflow(ansible_config): base_cfg = ansible_config('github_user_1') ga = GithubAdminClient() - suffix = ''.join([random.choice(string.ascii_lowercase) for x in range(0, 5)]) + suffix = ''.join([random.choice(string.ascii_lowercase) for x in range(5)]) user_a = ga.create_user(login='0xEEE-32i-' + suffix) user_a['username'] = user_a['login'] user_a['token'] = None @@ -551,7 +551,7 @@ def test_social_auth_no_duplicated_namespaces(ansible_config): sean.update(default_cfg) # login 10 times ... - for _ in range(0, 10): + for _ in range(10): with SocialGithubClient(config=sean) as client: client.get('_ui/v1/me/') diff --git a/galaxy_ng/tests/integration/community/test_v1_user_github_ids.py b/galaxy_ng/tests/integration/community/test_v1_user_github_ids.py index 935b9de480..b77bcc1c58 100644 --- a/galaxy_ng/tests/integration/community/test_v1_user_github_ids.py +++ b/galaxy_ng/tests/integration/community/test_v1_user_github_ids.py @@ -30,7 +30,7 @@ def extract_default_config(ansible_config): def test_v1_user_github_ids(ansible_config): """" The github_id should show up in the v1 user serializer """ - for x in range(0, 10): + for x in range(10): github_user = 'deleteme' + str(x) cleanup_social_user(github_user, ansible_config) diff --git a/galaxy_ng/tests/integration/utils/client_ansible_galaxy_cli.py b/galaxy_ng/tests/integration/utils/client_ansible_galaxy_cli.py index 81096c662f..f9226b6c9f 100644 --- a/galaxy_ng/tests/integration/utils/client_ansible_galaxy_cli.py +++ b/galaxy_ng/tests/integration/utils/client_ansible_galaxy_cli.py @@ -73,7 +73,7 @@ def ansible_galaxy( command_string = f"ansible-galaxy {command} -vvv --server={server} --ignore-certs" - for x in range(0, retries + 1): + for x in range(retries + 1): try: p = subprocess.run( command_string, diff --git a/galaxy_ng/tests/integration/utils/client_ansible_lib.py b/galaxy_ng/tests/integration/utils/client_ansible_lib.py index 25ae918914..7f425013b7 100644 --- a/galaxy_ng/tests/integration/utils/client_ansible_lib.py +++ b/galaxy_ng/tests/integration/utils/client_ansible_lib.py @@ -202,7 +202,7 @@ def request( if isinstance(args, (dict, list)): args = json.dumps(args) is_json = True - elif args and (args.startswith(b'{') or args.startswith(b'[')): + elif args and args.startswith((b'{', b'[')): args = json.dumps(json.loads(args)) is_json = True diff --git a/galaxy_ng/tests/integration/utils/collections.py b/galaxy_ng/tests/integration/utils/collections.py index bbe59ae62e..1a24762917 100644 --- a/galaxy_ng/tests/integration/utils/collections.py +++ b/galaxy_ng/tests/integration/utils/collections.py @@ -783,7 +783,6 @@ def recursive_delete_gk(gc_admin, namespace_name, cname, crepo="published"): resp = delete_collection(gc_admin, namespace=namespace_name, collection=cname) except GalaxyClientError as ge: print(ge) - pass # wait for the orphan_cleanup job to finish ... try: wait_for_task(gc_admin, resp, timeout=10000) diff --git a/galaxy_ng/tests/integration/utils/legacy.py b/galaxy_ng/tests/integration/utils/legacy.py index f3ffa3165b..c177698b2a 100644 --- a/galaxy_ng/tests/integration/utils/legacy.py +++ b/galaxy_ng/tests/integration/utils/legacy.py @@ -198,7 +198,7 @@ def is_valid(ns): while not is_valid(namespace): namespace = '' namespace += random.choice(string.ascii_lowercase + string.ascii_uppercase + string.digits) - for _ in range(0, random.choice(range(3, 63))): + for _ in range(random.choice(range(3, 63))): namespace += random.choice(string.ascii_lowercase + string.digits + '_') return namespace diff --git a/galaxy_ng/tests/integration/utils/namespaces.py b/galaxy_ng/tests/integration/utils/namespaces.py index 25b5c9b99f..c2bb69a46e 100644 --- a/galaxy_ng/tests/integration/utils/namespaces.py +++ b/galaxy_ng/tests/integration/utils/namespaces.py @@ -39,7 +39,7 @@ def is_valid(ns): while not is_valid(namespace): namespace = '' namespace += random.choice(string.ascii_lowercase) - for _ in range(0, random.choice(range(3, 63))): + for _ in range(random.choice(range(3, 63))): namespace += random.choice(string.ascii_lowercase + string.digits + '_') return namespace diff --git a/galaxy_ng/tests/integration/utils/users.py b/galaxy_ng/tests/integration/utils/users.py index 9494f08362..066dc402b9 100644 --- a/galaxy_ng/tests/integration/utils/users.py +++ b/galaxy_ng/tests/integration/utils/users.py @@ -38,7 +38,7 @@ def create_user(username, password, api_client=None): assert api_client is not None, "api_client is a required param" if password is None: - password = ''.join([random.choice(string.printable) for x in range(0, 12)]) + password = ''.join([random.choice(string.printable) for x in range(12)]) payload = { "username": username, diff --git a/galaxy_ng/tests/unit/app/utils/test_galaxy.py b/galaxy_ng/tests/unit/app/utils/test_galaxy.py index ccca1dfca7..8369fcafae 100644 --- a/galaxy_ng/tests/unit/app/utils/test_galaxy.py +++ b/galaxy_ng/tests/unit/app/utils/test_galaxy.py @@ -40,7 +40,7 @@ class UUIDConversionTestCase(TestCase): def test_uuid_to_int_and_back(self): """Make sure uuids can become ints and then back to uuids""" - for _i in range(0, 1000): + for _i in range(1000): test_uuid = str(uuid.uuid4()) test_int = uuid_to_int(test_uuid) reversed_uuid = int_to_uuid(test_int) diff --git a/profiles/community/github_mock/flaskapp.py b/profiles/community/github_mock/flaskapp.py index b98f0bbb3e..e0380a0f50 100644 --- a/profiles/community/github_mock/flaskapp.py +++ b/profiles/community/github_mock/flaskapp.py @@ -261,11 +261,11 @@ def get_new_uid(): def get_new_login(): - return ''.join([random.choice(string.ascii_lowercase) for x in range(0, 5)]) + return ''.join([random.choice(string.ascii_lowercase) for x in range(5)]) def get_new_password(): - return ''.join([random.choice(string.ascii_lowercase) for x in range(0, 12)]) + return ''.join([random.choice(string.ascii_lowercase) for x in range(12)]) # ---------------------------------------------------- diff --git a/pyproject.toml b/pyproject.toml index b456eb9eab..051aa96e83 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -119,6 +119,8 @@ select = [ "INT", # pyupgrade "UP", + # flake8-pie + "PIE", # flake8-pytest-style "PT", # ruff specific rules