ruff UP022 (prefer capture_output over stdout=PIPE, stderr=PIPE)
This commit is contained in:
parent
c807ae8212
commit
7991889a97
10 changed files with 15 additions and 16 deletions
|
|
@ -247,7 +247,7 @@ class Daemon(Lockable):
|
|||
@classmethod
|
||||
def get_exec_version_str(cls):
|
||||
try:
|
||||
cp = run([cls.exec_fn, cls.version_info_arg], stdout=PIPE, stderr=PIPE, check=True, text=True)
|
||||
cp = run([cls.exec_fn, cls.version_info_arg], capture_output=True, check=True, text=True)
|
||||
except Exception as e:
|
||||
die(2, f'{e}\nUnable to execute {cls.exec_fn}')
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ ignore = [
|
|||
"SIM102", # Use a single `if` statement instead of nested `if` statements
|
||||
"SIM114", # Combine `if` branches using logical `or` operator
|
||||
"SIM905", # Consider using a list literal instead of `str.split`
|
||||
"UP022", # Prefer `capture_output` over sending `stdout` and `stderr` to `PIPE`
|
||||
"UP030", # Use implicit references for positional format fields
|
||||
"UP031", # Use format specifiers instead of percent format
|
||||
"UP032", # Use f-string instead of `format` call
|
||||
|
|
|
|||
|
|
@ -837,7 +837,7 @@ class CmdTestEthdev(CmdTestEthdevMethods, CmdTestBase, CmdTestShared):
|
|||
write_to_file(pwfile, '')
|
||||
run(['rm', '-rf', self.keystore_dir])
|
||||
cmd = f'geth account new --password={pwfile} --lightkdf --keystore {self.keystore_dir}'
|
||||
if (cp := run(cmd.split(), stdout=PIPE, stderr=PIPE, text=True)).returncode:
|
||||
if (cp := run(cmd.split(), capture_output=True, text=True)).returncode:
|
||||
die(1, cp.stderr)
|
||||
|
||||
def make_genesis(signer_addr, prealloc_addr):
|
||||
|
|
@ -882,7 +882,7 @@ class CmdTestEthdev(CmdTestEthdevMethods, CmdTestBase, CmdTestShared):
|
|||
|
||||
def init_genesis(fn):
|
||||
cmd = f'{d.exec_fn} init --datadir {d.datadir} {fn}'
|
||||
if (cp := run(cmd.split(), stdout=PIPE, stderr=PIPE, text=True)).returncode:
|
||||
if (cp := run(cmd.split(), capture_output=True, text=True)).returncode:
|
||||
die(1, cp.stderr)
|
||||
|
||||
d.stop(quiet=True)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ test.cmdtest_d.include.proxy: SSH SOCKS proxy runner for the cmdtest.py test sui
|
|||
"""
|
||||
|
||||
import atexit
|
||||
from subprocess import run, PIPE
|
||||
from subprocess import run
|
||||
|
||||
from mmgen.cfg import gc
|
||||
from mmgen.util import msg, die, fmt
|
||||
|
|
@ -77,7 +77,7 @@ class TestProxy:
|
|||
if port_in_use(self.port):
|
||||
omsg(f'Port {self.port} already in use. Assuming SSH SOCKS server is running')
|
||||
else:
|
||||
cp = run(a + b0 + b1, stdout=PIPE, stderr=PIPE, text=True)
|
||||
cp = run(a + b0 + b1, capture_output=True, text=True)
|
||||
if cp.stderr:
|
||||
omsg(cp.stderr)
|
||||
if cp.returncode == 0:
|
||||
|
|
|
|||
|
|
@ -117,13 +117,13 @@ class CmdTestInput(CmdTestBase):
|
|||
|
||||
def get_seed_from_stdin(self):
|
||||
self.spawn(msg_only=True)
|
||||
from subprocess import run, PIPE
|
||||
from subprocess import run
|
||||
cmd = ['python3', 'cmds/mmgen-walletconv', '--skip-cfg-file', '--in-fmt=words', '--out-fmt=words', '--outdir=test/trash']
|
||||
mn = sample_mn['mmgen']['mn']
|
||||
run_env = dict(os.environ)
|
||||
run_env['MMGEN_TEST_SUITE'] = ''
|
||||
|
||||
cp = run(cmd, input=mn.encode(), stdout=PIPE, stderr=PIPE, env=run_env)
|
||||
cp = run(cmd, input=mn.encode(), capture_output=True, env=run_env)
|
||||
|
||||
from mmgen.color import set_vt100
|
||||
set_vt100()
|
||||
|
|
|
|||
|
|
@ -475,7 +475,7 @@ class VirtBlockDeviceMacOS(VirtBlockDeviceBase):
|
|||
self.size = size
|
||||
|
||||
def _get_associations(self):
|
||||
cp = run(['hdiutil', 'info'], stdout=PIPE, stderr=PIPE, text=True, check=False)
|
||||
cp = run(['hdiutil', 'info'], capture_output=True, text=True, check=False)
|
||||
if cp.returncode == 0:
|
||||
lines = cp.stdout.splitlines()
|
||||
out = [re.sub('.* ', '', s.strip()) for s in lines if re.match(r'image-path|/dev/', s)]
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ test.modtest_d.dep: dependency unit tests for the MMGen suite
|
|||
|
||||
import sys
|
||||
|
||||
from subprocess import run, PIPE
|
||||
from subprocess import run
|
||||
|
||||
from mmgen.util import msg, rmsg, ymsg, gmsg
|
||||
from mmgen.exception import NoLEDSupport
|
||||
|
|
@ -29,7 +29,7 @@ class unit_tests:
|
|||
except ModuleNotFoundError as e:
|
||||
ymsg(f'{type(e).__name__}: {e}')
|
||||
msg('Installing secp256k1 module locally...')
|
||||
run(['python3', './setup.py', 'build_ext', '--inplace'], stdout=PIPE, stderr=PIPE, check=True)
|
||||
run(['python3', './setup.py', 'build_ext', '--inplace'], capture_output=True, check=True)
|
||||
ymsg('The module has been installed. Try re-running the test')
|
||||
sys.exit(1)
|
||||
return False
|
||||
|
|
@ -148,7 +148,7 @@ class unit_tests:
|
|||
'--stdout',
|
||||
init_proto(cfg, 'eth').checksummed_addr('deadbeef'*5),
|
||||
]
|
||||
cp = run(cmd, stdout=PIPE, stderr=PIPE, text=True)
|
||||
cp = run(cmd, capture_output=True, text=True)
|
||||
vmsg(cp.stderr)
|
||||
if cp.returncode:
|
||||
msg(cp.stderr)
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ test/scrambletest.py: seed scrambling and addrlist data generation tests for all
|
|||
"""
|
||||
|
||||
import os, time
|
||||
from subprocess import run, PIPE
|
||||
from subprocess import run
|
||||
from collections import namedtuple
|
||||
|
||||
try:
|
||||
|
|
@ -107,7 +107,7 @@ def make_cmd(progname, opts, add_opts, args):
|
|||
return ['python3'] + cvrg_opts + [f'cmds/{progname}', '-qS'] + opts + add_opts + [words_file] + args + ['1']
|
||||
|
||||
def run_cmd(cmd):
|
||||
cp = run(cmd, stdout=PIPE, stderr=PIPE, text=True, env=run_env)
|
||||
cp = run(cmd, capture_output=True, text=True, env=run_env)
|
||||
if cp.returncode != 0:
|
||||
die(2, f'\nSpawned program exited with error code {cp.returncode}:\n{cp.stderr}')
|
||||
return cp.stdout.splitlines()
|
||||
|
|
|
|||
|
|
@ -266,7 +266,7 @@ class MMGenToolTestUtils:
|
|||
else:
|
||||
msg_r('Testing {:{w}}'.format(full_name+':', w=msg_w))
|
||||
|
||||
cp = run(sys_cmd, stdout=PIPE, stderr=PIPE)
|
||||
cp = run(sys_cmd, capture_output=True)
|
||||
out = cp.stdout
|
||||
err = cp.stderr
|
||||
if cfg.debug:
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ def fork_cmd(cmd_name, args, opts, stdin_input):
|
|||
vmsg('{} {}'.format(
|
||||
green('Executing'),
|
||||
cyan(' '.join(cmd))))
|
||||
cp = run(cmd, input=stdin_input or None, stdout=PIPE, stderr=PIPE)
|
||||
cp = run(cmd, input=stdin_input or None, capture_output=True)
|
||||
try:
|
||||
cmd_out = cp.stdout.decode()
|
||||
except:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue