From 4021c35e937f1dcb648ec6c546183bd7770cb1cc Mon Sep 17 00:00:00 2001 From: Lucas Meneghel Rodrigues Date: Mon, 9 Jun 2014 23:17:25 -0300 Subject: [PATCH] avocado.core.exceptions: Modifications to CmdError for serialization In order to serialize the CmdError class, we need to allow passing None command and CmdResult objects to the class constructor. Signed-off-by: Lucas Meneghel Rodrigues --- avocado/core/exceptions.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/avocado/core/exceptions.py b/avocado/core/exceptions.py index 7901b40c..3f11a096 100644 --- a/avocado/core/exceptions.py +++ b/avocado/core/exceptions.py @@ -106,15 +106,18 @@ class TestWarn(TestBaseException): class CmdError(Exception): - def __init__(self, command, result): + def __init__(self, command=None, result=None): self.command = command self.result = result def __str__(self): - if self.result.exit_status is None: - msg = "Command '%s' failed and is not responding to signals" - msg %= self.command + if self.result is not None: + if self.result.exit_status is None: + msg = "Command '%s' failed and is not responding to signals" + msg %= self.command + else: + msg = "Command '%s' failed (rc=%d)" + msg %= (self.command, self.result.exit_status) + return msg else: - msg = "Command '%s' failed (rc=%d)" - msg %= (self.command, self.result.exit_status) - return msg + return "CmdError" -- GitLab