Skip to content

Commit c5021a0

Browse files
authored
[pre-commit] Use correct comment format # noqa: not # noqa in tests common files (sonic-net#17652)
What is the motivation for this PR? In pre-commit, we were using # noqa to ignore failures/errors/warnings in our code, but once we use # noqa, it will ignore all pre-commit errors in this line, the correct solution is using # noqa: so only specific failures/errors/warnings would be ignored. How did you do it? Replace # noqa with # noqa: in tests common files How did you verify/test it?
1 parent d374e74 commit c5021a0

26 files changed

+136
-130
lines changed

tests/common/cache/facts_cache.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def _get_default_zone(function, func_args, func_kargs):
202202
Add the namespace to the default zone.
203203
"""
204204
hostname = None
205-
unicode_type = str if sys.version_info.major >= 3 else unicode # noqa F821
205+
unicode_type = str if sys.version_info.major >= 3 else unicode # noqa: F821
206206
if func_args:
207207
hostname = getattr(func_args[0], "hostname", None)
208208
if not hostname or type(hostname) not in [str, unicode_type]:

tests/common/devices/duthosts.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def __getitem__(self, index):
171171
Returns:
172172
[MultiAsicSonicHost]: Returns the specified duthost in duthosts. It is an instance of MultiAsicSonicHost.
173173
"""
174-
unicode_type = str if sys.version_info.major >= 3 else unicode # noqa F821
174+
unicode_type = str if sys.version_info.major >= 3 else unicode # noqa: F821
175175
if type(index) == int:
176176
return self.nodes[index]
177177
elif type(index) in [str, unicode_type]:

tests/common/devices/sonic.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1666,11 +1666,11 @@ def show_and_parse(self, show_cmd, header_len=1, **kwargs):
16661666
For example, part of the output of command 'show interface status':
16671667
16681668
admin@str-msn2700-02:~$ show interface status
1669-
Interface Lanes Speed MTU FEC Alias Vlan Oper Admin Type Asym PFC # noqa E501
1670-
--------------- --------------- ------- ----- ----- ------- --------------- ------ ------- --------------- ---------- # noqa E501
1671-
Ethernet0 0,1,2,3 40G 9100 N/A etp1 PortChannel0002 up up QSFP+ or later off # noqa E501
1672-
Ethernet4 4,5,6,7 40G 9100 N/A etp2 PortChannel0002 up up QSFP+ or later off # noqa E501
1673-
Ethernet8 8,9,10,11 40G 9100 N/A etp3 PortChannel0005 up up QSFP+ or later off # noqa E501
1669+
Interface Lanes Speed MTU FEC Alias Vlan Oper Admin Type Asym PFC # noqa: E501
1670+
--------------- --------------- ------- ----- ----- ------- --------------- ------ ------- --------------- ---------- # noqa: E501
1671+
Ethernet0 0,1,2,3 40G 9100 N/A etp1 PortChannel0002 up up QSFP+ or later off # noqa: E501
1672+
Ethernet4 4,5,6,7 40G 9100 N/A etp2 PortChannel0002 up up QSFP+ or later off # noqa: E501
1673+
Ethernet8 8,9,10,11 40G 9100 N/A etp3 PortChannel0005 up up QSFP+ or later off # noqa: E501
16741674
...
16751675
16761676
The parsed example will be like:

tests/common/dualtor/__init__.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from tests.common.dualtor.dual_tor_utils import * # noqa F401
2-
from tests.common.dualtor.mux_simulator_control import * # noqa F401
3-
from tests.common.dualtor.nic_simulator_control import * # noqa F401
4-
from tests.common.dualtor.dual_tor_common import * # noqa F401
1+
from tests.common.dualtor.dual_tor_utils import * # noqa: F401 F403
2+
from tests.common.dualtor.mux_simulator_control import * # noqa: F401 F403
3+
from tests.common.dualtor.nic_simulator_control import * # noqa: F401 F403
4+
from tests.common.dualtor.dual_tor_common import * # noqa: F401 F403

tests/common/dualtor/data_plane_utils.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import random
77
import shutil
88

9-
from tests.common.dualtor.dual_tor_common import active_active_ports # noqa F401
10-
from tests.common.dualtor.dual_tor_common import active_standby_ports # noqa F401
11-
from tests.common.dualtor.dual_tor_common import cable_type # noqa F401
9+
from tests.common.dualtor.dual_tor_common import active_active_ports # noqa: F401
10+
from tests.common.dualtor.dual_tor_common import active_standby_ports # noqa: F401
11+
from tests.common.dualtor.dual_tor_common import cable_type # noqa: F401
1212
from tests.common.dualtor.dual_tor_common import CableType
1313
from tests.common.dualtor.dual_tor_io import DualTorIO
1414
from tests.common.helpers.assertions import pytest_assert
@@ -161,7 +161,7 @@ def verify_and_report(tor_IO, verify, delay, allowed_disruption,
161161
def run_test(
162162
duthosts, activehost, ptfhost, ptfadapter, vmhost, action,
163163
tbinfo, tor_vlan_port, send_interval, traffic_direction,
164-
stop_after, cable_type=CableType.active_standby, random_dst=None # noqa F811
164+
stop_after, cable_type=CableType.active_standby, random_dst=None # noqa: F811
165165
):
166166
io_ready = threading.Event()
167167

@@ -245,7 +245,7 @@ def save_pcap(request, pytestconfig):
245245

246246
@pytest.fixture
247247
def send_t1_to_server_with_action(duthosts, ptfhost, ptfadapter, tbinfo,
248-
cable_type, vmhost, save_pcap): # noqa F811
248+
cable_type, vmhost, save_pcap): # noqa: F811
249249
"""
250250
Starts IO test from T1 router to server.
251251
As part of IO test the background thread sends and sniffs packets.
@@ -311,7 +311,7 @@ def t1_to_server_io_test(activehost, tor_vlan_port=None,
311311

312312
@pytest.fixture
313313
def send_server_to_t1_with_action(duthosts, ptfhost, ptfadapter, tbinfo,
314-
cable_type, vmhost, save_pcap): # noqa F811
314+
cable_type, vmhost, save_pcap): # noqa: F811
315315
"""
316316
Starts IO test from server to T1 router.
317317
As part of IO test the background thread sends and sniffs packets.
@@ -381,7 +381,7 @@ def server_to_t1_io_test(activehost, tor_vlan_port=None,
381381

382382
@pytest.fixture
383383
def send_soc_to_t1_with_action(duthosts, ptfhost, ptfadapter, tbinfo,
384-
cable_type, vmhost, save_pcap): # noqa F811
384+
cable_type, vmhost, save_pcap): # noqa: F811
385385

386386
arp_setup(ptfhost)
387387

@@ -410,7 +410,7 @@ def soc_to_t1_io_test(activehost, tor_vlan_port=None,
410410

411411
@pytest.fixture
412412
def send_t1_to_soc_with_action(duthosts, ptfhost, ptfadapter, tbinfo,
413-
cable_type, vmhost, save_pcap): # noqa F811
413+
cable_type, vmhost, save_pcap): # noqa: F811
414414

415415
arp_setup(ptfhost)
416416

@@ -440,10 +440,10 @@ def t1_to_soc_io_test(activehost, tor_vlan_port=None,
440440

441441

442442
@pytest.fixture
443-
def select_test_mux_ports(active_active_ports, active_standby_ports): # noqa F811
443+
def select_test_mux_ports(active_active_ports, active_standby_ports): # noqa: F811
444444
"""Return helper function to select test mux ports based on cable_type"""
445445

446-
def _select_test_mux_ports(cable_type, count): # noqa F811
446+
def _select_test_mux_ports(cable_type, count): # noqa: F811
447447
if cable_type == CableType.active_active:
448448
test_mux_ports = random.sample(active_active_ports, count)
449449
elif cable_type == CableType.active_standby:
@@ -457,7 +457,7 @@ def _select_test_mux_ports(cable_type, count):
457457

458458
@pytest.fixture
459459
def send_server_to_server_with_action(duthosts, ptfhost, ptfadapter, tbinfo,
460-
cable_type, vmhost, save_pcap): # noqa F811
460+
cable_type, vmhost, save_pcap): # noqa: F811
461461

462462
arp_setup(ptfhost)
463463

tests/common/dualtor/dual_tor_mock.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from ipaddress import ip_interface, IPv4Interface, IPv6Interface, \
99
ip_address, IPv4Address
1010
from tests.common import config_reload
11-
from tests.common.dualtor.dual_tor_utils import tor_mux_intfs # noqa F401
11+
from tests.common.dualtor.dual_tor_utils import tor_mux_intfs # noqa: F401
1212
from tests.common.helpers.assertions import pytest_assert
1313
from tests.common.platform.processes_utils import wait_critical_processes
1414
from tests.common.utilities import wait_until
@@ -64,7 +64,7 @@ def _apply_config_to_swss(dut, swss_config_str, swss_filename='swss_config_file'
6464
dut.shell('docker exec swss sh -c "swssconfig {}"'.format(swss_filename))
6565

6666

67-
def set_dual_tor_state_to_orchagent(dut, state, tor_mux_intfs): # noqa F811
67+
def set_dual_tor_state_to_orchagent(dut, state, tor_mux_intfs): # noqa: F811
6868
"""
6969
Helper function for setting active/standby state to orchagent
7070
"""
@@ -104,7 +104,7 @@ def check_config_applied(num_tor_mux_intfs):
104104
wait_until(120, 5, 5, check_config_applied, len(tor_mux_intfs))
105105

106106

107-
def del_dual_tor_state_from_orchagent(dut, state, tor_mux_intfs): # noqa F811
107+
def del_dual_tor_state_from_orchagent(dut, state, tor_mux_intfs): # noqa: F811
108108
"""
109109
Helper function for deleting active/standby state to orchagent
110110
"""
@@ -127,7 +127,7 @@ def del_dual_tor_state_from_orchagent(dut, state, tor_mux_intfs): # noqa F
127127
_apply_config_to_swss(dut, swss_config_str, swss_filename)
128128

129129

130-
def _apply_dual_tor_state_to_orchagent(dut, state, tor_mux_intfs): # noqa F811
130+
def _apply_dual_tor_state_to_orchagent(dut, state, tor_mux_intfs): # noqa: F811
131131
'''
132132
Helper function to configure active/standby state in orchagent
133133
@@ -158,15 +158,15 @@ def set_mux_state(dut, tbinfo, state, itfs, toggle_all_simulator_ports):
158158

159159

160160
@pytest.fixture(scope='module')
161-
def apply_active_state_to_orchagent(rand_selected_dut, tor_mux_intfs): # noqa F811
161+
def apply_active_state_to_orchagent(rand_selected_dut, tor_mux_intfs): # noqa: F811
162162
dut = rand_selected_dut
163163

164164
for func in _apply_dual_tor_state_to_orchagent(dut, 'active', tor_mux_intfs):
165165
yield func
166166

167167

168168
@pytest.fixture(scope='module')
169-
def apply_standby_state_to_orchagent(rand_selected_dut, tor_mux_intfs): # noqa F811
169+
def apply_standby_state_to_orchagent(rand_selected_dut, tor_mux_intfs): # noqa: F811
170170
dut = rand_selected_dut
171171

172172
for func in _apply_dual_tor_state_to_orchagent(dut, 'standby', tor_mux_intfs):
@@ -230,7 +230,7 @@ def mock_server_base_ip_addr(rand_selected_dut, tbinfo):
230230

231231
@pytest.fixture(scope='module')
232232
def mock_server_ip_mac_map(rand_selected_dut, tbinfo, ptfadapter,
233-
mock_server_base_ip_addr, tor_mux_intfs): # noqa F811
233+
mock_server_base_ip_addr, tor_mux_intfs): # noqa: F811
234234
dut = rand_selected_dut
235235

236236
server_ipv4_base_addr, _ = mock_server_base_ip_addr
@@ -257,7 +257,7 @@ def mock_server_ip_mac_map(rand_selected_dut, tbinfo, ptfadapter,
257257

258258
@pytest.fixture(scope='module')
259259
def mock_server_ipv6_mac_map(rand_selected_dut, tbinfo, ptfadapter,
260-
mock_server_base_ip_addr, tor_mux_intfs): # noqa F811
260+
mock_server_base_ip_addr, tor_mux_intfs): # noqa: F811
261261
dut = rand_selected_dut
262262
_, server_ipv6_base_addr = mock_server_base_ip_addr
263263
server_ipv6_mac_map = {}
@@ -415,7 +415,7 @@ def check_config_applied(tunnel_params):
415415

416416
@pytest.fixture(scope='module')
417417
def apply_mux_cable_table_to_dut(cleanup_mocked_configs, rand_selected_dut,
418-
mock_server_base_ip_addr, tor_mux_intfs): # noqa F811
418+
mock_server_base_ip_addr, tor_mux_intfs): # noqa: F811
419419
'''
420420
Adds the MUX_CABLE table to config DB
421421
'''

0 commit comments

Comments
 (0)