pytest: close file handles after use (cont.), and tidy-ups

- dante.py, dnsd.py, sshd.py: drop redundant conditions.
  Spotted in sshd by GitHub Code Quality.
- curl.py: comment out `if` to silence CodeQL warning.

Reported by GitHub CodeQL

Follow-up to 8145476d5d #21916

Closes #21917
This commit is contained in:
Viktor Szakats 2026-06-09 02:08:30 +02:00
parent 7b9d74abf6
commit cb4465bfe6
No known key found for this signature in database
9 changed files with 91 additions and 35 deletions

View file

@ -191,13 +191,14 @@ class RunTcpDump:
if self._proc:
raise Exception('tcpdump still running')
lines = []
for line in open(self._stdoutfile):
m = re.match(r'.* IP 127\.0\.0\.1\.(\d+) [<>] 127\.0\.0\.1\.(\d+):.*', line)
if m:
sport = int(m.group(1))
dport = int(m.group(2))
if ports is None or sport in ports or dport in ports:
lines.append(line)
with open(self._stdoutfile) as fd:
for line in fd:
m = re.match(r'.* IP 127\.0\.0\.1\.(\d+) [<>] 127\.0\.0\.1\.(\d+):.*', line)
if m:
sport = int(m.group(1))
dport = int(m.group(2))
if ports is None or sport in ports or dport in ports:
lines.append(line)
return lines
@property
@ -208,7 +209,8 @@ class RunTcpDump:
def stderr(self) -> List[str]:
if self._proc:
raise Exception('tcpdump still running')
return open(self._stderrfile).readlines()
with open(self._stderrfile) as fd:
return fd.readlines()
def sample(self):
# not sure how to make that detection reliable for all platforms
@ -1027,8 +1029,8 @@ class CurlClient:
cwd=self._run_dir, shell=False,
env=self._run_env)
profile = RunProfile(p.pid, started_at, self._run_dir)
if intext is not None and False:
p.communicate(input=intext.encode(), timeout=1)
#if intext is not None and False:
# p.communicate(input=intext.encode(), timeout=1)
if self._with_perf:
perf = PerfProfile(p.pid, self._run_dir)
perf.start()