From b98e6eec58f645c152425808c06756ca83bbf0f7 Mon Sep 17 00:00:00 2001 From: Azim Khan Date: Thu, 28 Jun 2018 17:11:33 +0100 Subject: [PATCH] Replace asserts with exceptions in mbedtls_test.py --- tests/scripts/mbedtls_test.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/scripts/mbedtls_test.py b/tests/scripts/mbedtls_test.py index b825f13596..52fd0a9c28 100755 --- a/tests/scripts/mbedtls_test.py +++ b/tests/scripts/mbedtls_test.py @@ -34,6 +34,11 @@ import binascii from mbed_host_tests import BaseHostTest, event_callback +class TestDataParserError(Exception): + """Indicates error in test data, read from .data file.""" + pass + + class TestDataParser(object): """ parser for mbedtls test data files. @@ -107,7 +112,9 @@ class TestDataParser(object): function = int(parts[0]) x = parts[1:] l = len(x) - assert l % 2 == 0, "Number of test arguments should be even: %s" % line + if l % 2 != 0: + raise TestDataParserError("Number of test arguments should " + "be even: %s" % line) args = [(x[i * 2], x[(i * 2) + 1]) for i in range(len(x)/2)] self.tests.append((name, function, deps, args)) @@ -194,10 +201,13 @@ class MbedTlsTest(BaseHostTest): :param hex_str: Hex in string format. :return: Output Byte array """ - assert hex_str[0] == '"' and hex_str[len(hex_str) - 1] == '"', \ - "HEX test parameter missing '\"': %s" % hex_str + if hex_str[0] != '"' or hex_str[len(hex_str) - 1] != '"': + raise TestDataParserError("HEX test parameter missing '\"':" + " %s" % hex_str) hex_str = hex_str.strip('"') - assert len(hex_str) % 2 == 0, "HEX parameter len should be mod of 2: %s" % hex_str + if len(hex_str) % 2 != 0: + raise TestDataParserError("HEX parameter len should be mod of " + "2: %s" % hex_str) b = binascii.unhexlify(hex_str) return b