Convert test code to use subprocess.run. NFC (#1647)
This commit is contained in:
12
test/test.py
12
test/test.py
@@ -32,19 +32,18 @@ def listify(x):
|
|||||||
return [x]
|
return [x]
|
||||||
|
|
||||||
|
|
||||||
def check_call(cmd, **args):
|
def check_call(cmd, **kwargs):
|
||||||
if type(cmd) is not list:
|
if type(cmd) is not list:
|
||||||
cmd = cmd.split()
|
cmd = cmd.split()
|
||||||
print('running: %s' % cmd)
|
print('running: %s' % cmd)
|
||||||
args['universal_newlines'] = True
|
subprocess.run(cmd, check=True, text=True, **kwargs)
|
||||||
subprocess.check_call(cmd, **args)
|
|
||||||
|
|
||||||
|
|
||||||
def checked_call_with_output(cmd, expected=None, unexpected=None, stderr=None, env=None):
|
def checked_call_with_output(cmd, expected=None, unexpected=None, stderr=None, env=None):
|
||||||
cmd = cmd.split(' ')
|
cmd = cmd.split(' ')
|
||||||
print('running: %s' % cmd)
|
print('running: %s' % cmd)
|
||||||
try:
|
try:
|
||||||
stdout = subprocess.check_output(cmd, stderr=stderr, universal_newlines=True, env=env)
|
stdout = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=stderr, check=True, text=True, env=env).stdout
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print(e.stderr)
|
print(e.stderr)
|
||||||
print(e.stdout)
|
print(e.stdout)
|
||||||
@@ -59,8 +58,9 @@ def checked_call_with_output(cmd, expected=None, unexpected=None, stderr=None, e
|
|||||||
|
|
||||||
|
|
||||||
def failing_call_with_output(cmd, expected, env=None):
|
def failing_call_with_output(cmd, expected, env=None):
|
||||||
proc = subprocess.Popen(cmd.split(' '), stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, env=env)
|
proc = subprocess.run(cmd.split(' '), capture_output=True, text=True, env=env)
|
||||||
stdout, stderr = proc.communicate()
|
stdout = proc.stdout
|
||||||
|
stderr = proc.stderr
|
||||||
if WINDOWS:
|
if WINDOWS:
|
||||||
print('warning: skipping part of failing_call_with_output() due to error codes not being propagated (see #592)')
|
print('warning: skipping part of failing_call_with_output() due to error codes not being propagated (see #592)')
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user