Replaced subprocess commands by run() wherever possible.

This commit is contained in:
Claude Paroz 2019-08-23 10:53:36 +02:00 committed by Carlton Gibson
parent 7bd9633320
commit 9386586f31
13 changed files with 42 additions and 42 deletions

View file

@ -1,3 +1,4 @@
from subprocess import CompletedProcess
from unittest import mock, skipUnless
from django.db import connection
@ -9,13 +10,13 @@ from django.test import SimpleTestCase
class OracleDbshellTests(SimpleTestCase):
def _run_dbshell(self, rlwrap=False):
"""Run runshell command and capture its arguments."""
def _mock_subprocess_call(*args):
self.subprocess_args = tuple(*args)
return 0
def _mock_subprocess_run(*args):
self.subprocess_args = list(*args)
return CompletedProcess(self.subprocess_args, 0)
client = DatabaseClient(connection)
self.subprocess_args = None
with mock.patch('subprocess.call', new=_mock_subprocess_call):
with mock.patch('subprocess.run', new=_mock_subprocess_run):
with mock.patch('shutil.which', return_value='/usr/bin/rlwrap' if rlwrap else None):
client.runshell()
return self.subprocess_args