From 715716a7079e0ece85522455897710106ca29b44 Mon Sep 17 00:00:00 2001 From: Shwetha-H-Panduranga Date: Wed, 4 Jan 2012 17:38:29 +0530 Subject: validate stderr stream also. This is useful for performing negative testing Change-Id: I13c77926a4046b3aa729a006840453d69dc81c14 Signed-off-by: Shwetha-H-Panduranga --- libs/utils/atfutils.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/libs/utils/atfutils.py b/libs/utils/atfutils.py index b1f774e..79f7eba 100644 --- a/libs/utils/atfutils.py +++ b/libs/utils/atfutils.py @@ -16,7 +16,7 @@ def assert_success(exit_status): """ if exit_status is None: return 1 - + if not exit_status: return 0 else: @@ -27,7 +27,7 @@ def assert_failure(exit_status): """ if exit_status is None: return 1 - + if exit_status: return 0 else: @@ -38,25 +38,25 @@ def expect(actual_string, expected_string): """ escaped_pattern = re.escape(expected_string) new_pattern = re.compile(escaped_pattern, re.IGNORECASE) - + matched = False if not expected_string: matched = True - + else: if re.search(new_pattern, actual_string): matched = True return matched -def validate_output(output, expected_exit_status, expected_output): +def validate_output(output, expected_exit_status, expected_output, stream="stdout"): """ Parameters: output: This is dictionary which is return value of executecommand(ssh module) - + expected_exit_status: exit_status we are expecting - + expected_output : output expected from the execution of command Returns: @@ -66,18 +66,25 @@ def validate_output(output, expected_exit_status, expected_output): False: if output doesn't match with expected_exit_status or expected_output """ + output_status = False if expected_exit_status is not 0: exit_status = assert_failure(output['exitstatus']) else: exit_status = assert_success(output['exitstatus']) - - output_status = expect(str(output['stdoutdata']), - expected_output) + + if stream is "stdout": + output_status = expect(str(output['stdoutdata']), + expected_output) + + elif stream is "stderr": + output_status = expect(str(output['stderrdata']), + expected_output) + if output_status is True and (not exit_status): return 0 else: return 1 - + def print_stdout(stdoutdata): """ """ -- cgit