Skip to content

Commit 97e2e4f

Browse files
committed
fix count occurences check
1 parent c90e563 commit 97e2e4f

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

gossipsub-interop/checks/partial_messages.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ def iter_stdout_logs(hosts_dir: Path):
3939

4040
def count_occurrences(path: Path, needle: str) -> int:
4141
"""Count how many times the string appears inside the file."""
42+
if not needle:
43+
return 0
44+
total = 0
4245
with path.open("r", encoding="utf-8", errors="replace") as handle:
43-
total = 0
44-
for chunk in iter(lambda: handle.read(4096), ""):
45-
total += chunk.count(needle)
46+
for line in handle:
47+
total += line.count(needle)
4648
return total
4749

4850

@@ -80,7 +82,10 @@ def main() -> int:
8082
f" - {rel_path}: found {occurrences} occurrences (expected >= {args.count})",
8183
file=sys.stderr,
8284
)
83-
print(f"{len(missing)} / {len(stdout_logs)} logs missing the message.", file=sys.stderr)
85+
print(
86+
f"{len(missing)} / {len(stdout_logs)} logs missing the message.",
87+
file=sys.stderr,
88+
)
8489
return 1
8590

8691
print(

0 commit comments

Comments
 (0)