1from exc.test_failed import TestFailed
2from conf import hook
3
4""" Post-Test Hook: ExpectedRetCode
5This is a post-test hook which checks if the exit code of the Wget instance
6under test is the same as that expected. As a result, this is a very important
7post test hook which is checked in all the tests.
8Returns a TestFailed exception if the return code does not match the expected
9value. Else returns gracefully.
10"""
11
12
13@hook(alias='ExpectedRetcode')
14class ExpectedRetCode:
15    def __init__(self, expected_ret_code):
16        self.expected_ret_code = expected_ret_code
17
18    def __call__(self, test_obj):
19        if test_obj.ret_code != self.expected_ret_code:
20            if test_obj.ret_code == 45:
21                failure = "Memory Leak Found by Valgrind"
22            else:
23                failure = "Return codes do not match.\n" \
24                          "Expected: %s\n" \
25                          "Actual: %s" % (self.expected_ret_code,
26                                          test_obj.ret_code)
27            raise TestFailed(failure)
28