Skip to content

Commit 9591864

Browse files
Jim RyanAlexFenlon
authored andcommitted
Chore/python clean up, and unused variable check to pre commit (#5866)
* delete obscured function * autopep8 * remove unsed imports * remove unused variables * add autoflake * fix pre commit * remove used vars via pre commit * remove unused variables and presumably pure function calls * remove unused calls
1 parent 6cd931d commit 9591864

36 files changed

+67
-154
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ repos:
6363
hooks:
6464
- id: black
6565

66+
- repo: https://github.com/PyCQA/autoflake
67+
rev: v2.3.1
68+
hooks:
69+
- id: autoflake
70+
files: tests/.*\.py$
71+
args: ['--in-place', '--remove-all-unused-imports', '--remove-unused-variable']
72+
6673
- repo: https://github.com/python-jsonschema/check-jsonschema
6774
rev: 0.28.6
6875
hooks:

perf-tests/suite/ap_request_perf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22

33
import yaml
4-
from locust import HttpUser, TaskSet, task
4+
from locust import HttpUser, task
55

66
host = ""
77

perf-tests/suite/test_ap_reload_perf.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import json
2-
import logging
32
import os
43
import re
54
import subprocess
@@ -9,7 +8,7 @@
98
import requests
109
import yaml
1110
from kubernetes.client import V1ContainerPort
12-
from settings import DEPLOYMENTS, TEST_DATA
11+
from settings import TEST_DATA
1312
from suite.utils.ap_resources_utils import (
1413
create_ap_logconf_from_yaml,
1514
create_ap_policy_from_yaml,
@@ -25,14 +24,9 @@
2524
delete_items_from_yaml,
2625
ensure_connection_to_public_endpoint,
2726
ensure_response_from_backend,
28-
get_events,
29-
get_file_contents,
30-
get_first_pod_name,
31-
get_ingress_nginx_template_conf,
3227
get_resource_metrics,
3328
replace_ingress_with_ap_annotations,
3429
wait_before_test,
35-
wait_for_event_increment,
3630
wait_until_all_pods_are_ready,
3731
)
3832
from suite.utils.yaml_utils import get_first_ingress_host_from_yaml

perf-tests/suite/test_vs_perf.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import json
2-
import re
3-
import subprocess
4-
from datetime import datetime
52

63
import pytest
74
import requests

tests/suite/fixtures/ic_fixtures.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def crd_ingress_controller(
102102
ingress_controller_endpoint.port,
103103
ingress_controller_endpoint.port_ssl,
104104
)
105-
except ApiException as ex:
105+
except ApiException:
106106
# Finalizer method doesn't start if fixture creation was incomplete, ensure clean up here
107107
print("Restore the ClusterRole:")
108108
patch_rbac(kube_apis.rbac_v1, f"{DEPLOYMENTS}/rbac/rbac.yaml")
@@ -267,7 +267,6 @@ def crd_ingress_controller_with_dos(
267267

268268
print("------------------------- Create syslog svc -----------------------")
269269
src_syslog_yaml = f"{TEST_DATA}/dos/dos-syslog.yaml"
270-
log_loc = f"/var/log/messages"
271270
create_items_from_yaml(kube_apis, src_syslog_yaml, namespace)
272271
before = time.time()
273272
wait_until_all_pods_are_ready(kube_apis.v1, namespace)
@@ -397,7 +396,7 @@ def crd_ingress_controller_with_ed(
397396
ingress_controller_prerequisites.namespace,
398397
cm_source,
399398
)
400-
except ApiException as ex:
399+
except ApiException:
401400
# Finalizer method doesn't start if fixture creation was incomplete, ensure clean up here
402401
print("Restore the ClusterRole:")
403402
patch_rbac(kube_apis.rbac_v1, f"{DEPLOYMENTS}/rbac/rbac.yaml")

tests/suite/grpc/helloworld_pb2.py

Lines changed: 8 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/suite/grpc/helloworld_pb2_grpc.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ def __init__(self, channel):
1616
channel: A grpc.Channel.
1717
"""
1818
self.SayHello = channel.unary_unary(
19-
'/helloworld.Greeter/SayHello',
20-
request_serializer=helloworld__pb2.HelloRequest.SerializeToString,
21-
response_deserializer=helloworld__pb2.HelloReply.FromString,
22-
)
19+
'/helloworld.Greeter/SayHello',
20+
request_serializer=helloworld__pb2.HelloRequest.SerializeToString,
21+
response_deserializer=helloworld__pb2.HelloReply.FromString,
22+
)
2323

2424

2525
class GreeterServicer(object):
@@ -36,35 +36,36 @@ def SayHello(self, request, context):
3636

3737
def add_GreeterServicer_to_server(servicer, server):
3838
rpc_method_handlers = {
39-
'SayHello': grpc.unary_unary_rpc_method_handler(
40-
servicer.SayHello,
41-
request_deserializer=helloworld__pb2.HelloRequest.FromString,
42-
response_serializer=helloworld__pb2.HelloReply.SerializeToString,
43-
),
39+
'SayHello': grpc.unary_unary_rpc_method_handler(
40+
servicer.SayHello,
41+
request_deserializer=helloworld__pb2.HelloRequest.FromString,
42+
response_serializer=helloworld__pb2.HelloReply.SerializeToString,
43+
),
4444
}
4545
generic_handler = grpc.method_handlers_generic_handler(
46-
'helloworld.Greeter', rpc_method_handlers)
46+
'helloworld.Greeter', rpc_method_handlers)
4747
server.add_generic_rpc_handlers((generic_handler,))
4848

49-
5049
# This class is part of an EXPERIMENTAL API.
50+
51+
5152
class Greeter(object):
5253
"""The greeting service definition.
5354
"""
5455

5556
@staticmethod
5657
def SayHello(request,
57-
target,
58-
options=(),
59-
channel_credentials=None,
60-
call_credentials=None,
61-
insecure=False,
62-
compression=None,
63-
wait_for_ready=None,
64-
timeout=None,
65-
metadata=None):
58+
target,
59+
options=(),
60+
channel_credentials=None,
61+
call_credentials=None,
62+
insecure=False,
63+
compression=None,
64+
wait_for_ready=None,
65+
timeout=None,
66+
metadata=None):
6667
return grpc.experimental.unary_unary(request, target, '/helloworld.Greeter/SayHello',
67-
helloworld__pb2.HelloRequest.SerializeToString,
68-
helloworld__pb2.HelloReply.FromString,
69-
options, channel_credentials,
70-
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
68+
helloworld__pb2.HelloRequest.SerializeToString,
69+
helloworld__pb2.HelloReply.FromString,
70+
options, channel_credentials,
71+
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)

tests/suite/test_annotations.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,6 @@ def test_standard_ingress(
565565
expected_strings,
566566
unexpected_strings,
567567
):
568-
initial_events = get_events(kube_apis.v1, annotations_setup.namespace)
569-
initial_count = get_event_count(annotations_setup.ingress_event_text, initial_events)
570568
print("Case 8: standard ingress")
571569
replace_ingresses_from_yaml(kube_apis.networking_v1, annotations_setup.namespace, yaml_file)
572570
wait_before_test(1)
@@ -577,7 +575,6 @@ def test_standard_ingress(
577575
annotations_setup.ingress_pod_name,
578576
ingress_controller_prerequisites.namespace,
579577
)
580-
new_events = get_events(kube_apis.v1, annotations_setup.namespace)
581578
for _ in expected_strings:
582579
assert _ in result_conf
583580
for _ in unexpected_strings:

tests/suite/test_app_protect_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22
import requests
33
import yaml
4-
from settings import CRDS, DEPLOYMENTS, TEST_DATA
4+
from settings import CRDS, TEST_DATA
55
from suite.utils.ap_resources_utils import (
66
create_ap_logconf_from_yaml,
77
create_ap_policy_from_yaml,

tests/suite/test_app_protect_waf_policies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def test_ap_waf_policy_block(
177177
"syslog:server=127.0.0.1:514",
178178
)
179179
elif waf == waf_pol_default_src:
180-
pol_name = create_policy_from_yaml(kube_apis.custom_objects, waf, test_namespace)
180+
create_policy_from_yaml(kube_apis.custom_objects, waf, test_namespace)
181181
else:
182182
pytest.fail(f"Invalid argument")
183183

0 commit comments

Comments
 (0)