aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2023-05-26 22:47:38 -0400
committerMike Frysinger <vapier@google.com>2023-05-26 23:05:02 -0400
commit4bcabe493db69886e287a28a9ccd66a501fab8fa (patch)
tree90d235604062397467d5b8d2e7922fcbfcb265a9
parent958d01176166cce29564cc3a2ef1e03db8159827 (diff)
downloadrepohooks-4bcabe493db69886e287a28a9ccd66a501fab8fa.tar.gz
utils: drop unused CalledProcessError.exception
The subprocess module doesn't have it, and we don't use it, so drop it. Bug: None Test: unittests Change-Id: I5e563bf3cf05bfff1cb6c1c90b30e37a3e27cffb
-rw-r--r--rh/utils.py11
-rwxr-xr-xrh/utils_unittest.py10
2 files changed, 2 insertions, 19 deletions
diff --git a/rh/utils.py b/rh/utils.py
index 14553a8..a00b12b 100644
--- a/rh/utils.py
+++ b/rh/utils.py
@@ -81,15 +81,9 @@ class CalledProcessError(subprocess.CalledProcessError):
returncode: The exit code of the process.
cmd: The command that triggered this exception.
msg: Short explanation of the error.
- exception: The underlying Exception if available.
"""
- def __init__(self, returncode, cmd, stdout=None, stderr=None, msg=None,
- exception=None):
- if exception is not None and not isinstance(exception, Exception):
- raise TypeError(
- f'exception must be an exception instance; got {exception!r}')
-
+ def __init__(self, returncode, cmd, stdout=None, stderr=None, msg=None):
super().__init__(returncode, cmd, stdout)
# The parent class will set |output|, so delete it.
del self.output
@@ -99,7 +93,6 @@ class CalledProcessError(subprocess.CalledProcessError):
# TODO(vapier): When we're Python 3-only, move stderr to the init above.
self.stderr = stderr
self.msg = msg
- self.exception = exception
@property
def cmdstr(self):
@@ -420,7 +413,7 @@ def run(cmd, redirect_stdout=False, redirect_stderr=False, cwd=None, input=None,
result = CompletedProcess(args=cmd, stderr=estr, returncode=255)
else:
raise CalledProcessError(
- result.returncode, result.cmd, msg=estr, exception=e,
+ result.returncode, result.cmd, msg=estr,
stdout=ensure_text(result.stdout),
stderr=ensure_text(result.stderr)) from e
finally:
diff --git a/rh/utils_unittest.py b/rh/utils_unittest.py
index 7928dd5..277abff 100755
--- a/rh/utils_unittest.py
+++ b/rh/utils_unittest.py
@@ -98,34 +98,24 @@ class CalledProcessErrorTests(unittest.TestCase):
def test_basic(self):
"""Basic test we can create a normal instance."""
rh.utils.CalledProcessError(0, ['mycmd'])
- rh.utils.CalledProcessError(1, ['mycmd'], exception=Exception('bad'))
def test_stringify(self):
"""Check stringify() handling."""
# We don't assert much so we leave flexibility in changing format.
err = rh.utils.CalledProcessError(0, ['mycmd'])
self.assertIn('mycmd', err.stringify())
- err = rh.utils.CalledProcessError(
- 0, ['mycmd'], exception=Exception('bad'))
- self.assertIn('mycmd', err.stringify())
def test_str(self):
"""Check str() handling."""
# We don't assert much so we leave flexibility in changing format.
err = rh.utils.CalledProcessError(0, ['mycmd'])
self.assertIn('mycmd', str(err))
- err = rh.utils.CalledProcessError(
- 0, ['mycmd'], exception=Exception('bad'))
- self.assertIn('mycmd', str(err))
def test_repr(self):
"""Check repr() handling."""
# We don't assert much so we leave flexibility in changing format.
err = rh.utils.CalledProcessError(0, ['mycmd'])
self.assertNotEqual('', repr(err))
- err = rh.utils.CalledProcessError(
- 0, ['mycmd'], exception=Exception('bad'))
- self.assertNotEqual('', repr(err))
class RunCommandTests(unittest.TestCase):