Skip to content

Commit 09bddd9

Browse files
committed
Fix ruff linting errors
1 parent 369262b commit 09bddd9

2 files changed

Lines changed: 7 additions & 13 deletions

File tree

pingping/ping.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def _set_ping(self, count, layer, timeout):
4444
@classmethod
4545
def is_valid_ip(cls, ip):
4646
m = re.match(r"^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$", str(ip).strip())
47-
return bool(m) and all(map(lambda n: 0 <= int(n) <= 255, m.groups()))
47+
return bool(m) and all(0 <= int(n) <= 255 for n in m.groups())
4848

4949
def _add_ip(self, ip):
5050
if self.is_valid_ip(ip):
@@ -108,7 +108,9 @@ def _fetch_time(cls):
108108
return
109109

110110
@classmethod
111-
def _set_time(cls, result, index=[1, 2, 3]):
111+
def _set_time(cls, result, index=None):
112+
if index is None:
113+
index = [1, 2, 3]
112114
if result:
113115
cls.ping_data["min"] = float(result.group(index[0]))
114116
cls.ping_data["avg"] = float(result.group(index[1]))

tests/test_ping.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import json
22
import os
3-
import sys
43

54
import pytest
65

@@ -12,24 +11,17 @@ class TestPing:
1211

1312
@pytest.fixture
1413
def setup(self):
15-
# Not a good way to solve the encoding issue.
16-
if sys.version_info.major == 2:
17-
import imp
18-
19-
imp.reload(sys)
20-
sys.setdefaultencoding("utf-8")
21-
2214
p = Ping()
2315
yield p
2416

2517
def read_all_inputs(self, obj, langauge="en"):
2618
file_name = f"ping_{langauge}.json"
2719
ping_data = json.load(open(f"{self.file_path}/{file_name}"))
2820
result = {}
29-
for os, os_result in ping_data.items():
30-
result[os] = {}
21+
for os_name, os_result in ping_data.items():
22+
result[os_name] = {}
3123
for ip, each_ping in os_result.items():
32-
result[os][ip] = obj.fetch_ping_data(each_ping)
24+
result[os_name][ip] = obj.fetch_ping_data(each_ping)
3325
return result
3426

3527
def validate_result(self, result):

0 commit comments

Comments
 (0)