test: Move error string into exception
This is normally expected and also less code.
This commit is contained in:
1 file changed
+5
-10
@@ -64,11 +64,9 @@ class ToolUtils(BitcoinTestFramework):
|
|||||||
with open(self.testcase_dir / outputFn, encoding="utf8") as f:
|
with open(self.testcase_dir / outputFn, encoding="utf8") as f:
|
||||||
outputData = f.read()
|
outputData = f.read()
|
||||||
if not outputData:
|
if not outputData:
|
||||||
logging.error("Output data missing for " + outputFn)
|
raise Exception(f"Output data missing for {outputFn}")
|
||||||
raise Exception
|
|
||||||
if not outputType:
|
if not outputType:
|
||||||
logging.error("Output file %s does not have a file extension" % outputFn)
|
raise Exception(f"Output file {outputFn} does not have a file extension")
|
||||||
raise Exception
|
|
||||||
|
|
||||||
# Run the test
|
# Run the test
|
||||||
res = subprocess.run(execrun, capture_output=True, text=True, input=inputData)
|
res = subprocess.run(execrun, capture_output=True, text=True, input=inputData)
|
||||||
@@ -107,20 +105,17 @@ class ToolUtils(BitcoinTestFramework):
|
|||||||
if "return_code" in testObj:
|
if "return_code" in testObj:
|
||||||
wantRC = testObj['return_code']
|
wantRC = testObj['return_code']
|
||||||
if res.returncode != wantRC:
|
if res.returncode != wantRC:
|
||||||
logging.error(f"Return code mismatch for {outputFn}; res: {str(res)}")
|
raise Exception(f"Return code mismatch for {outputFn}; res: {str(res)}")
|
||||||
raise Exception
|
|
||||||
|
|
||||||
if "error_txt" in testObj:
|
if "error_txt" in testObj:
|
||||||
want_error = testObj["error_txt"]
|
want_error = testObj["error_txt"]
|
||||||
# A partial match instead of an exact match makes writing tests easier
|
# A partial match instead of an exact match makes writing tests easier
|
||||||
# and should be sufficient.
|
# and should be sufficient.
|
||||||
if want_error not in res.stderr:
|
if want_error not in res.stderr:
|
||||||
logging.error(f"Error mismatch:\nExpected: {want_error}\nReceived: {res.stderr.rstrip()}\nres: {str(res)}")
|
raise Exception(f"Error mismatch:\nExpected: {want_error}\nReceived: {res.stderr.rstrip()}\nres: {str(res)}")
|
||||||
raise Exception
|
|
||||||
else:
|
else:
|
||||||
if res.stderr:
|
if res.stderr:
|
||||||
logging.error(f"Unexpected error received: {res.stderr.rstrip()}\nres: {str(res)}")
|
raise Exception(f"Unexpected error received: {res.stderr.rstrip()}\nres: {str(res)}")
|
||||||
raise Exception
|
|
||||||
|
|
||||||
|
|
||||||
def parse_output(a, fmt):
|
def parse_output(a, fmt):
|
||||||
|
|||||||
Reference in new issue
Block a user