Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 """Utility module for testharness.""" | |
| 6 | |
| 7 | |
| 8 # const definitions | |
| 9 TESTHARNESSREPORT_HEADER = 'This is a testharness.js-based test.' | |
| 10 TESTHARNESSREPORT_FOOTER = 'Harness: the test ran to completion.' | |
| 11 | |
| 12 | |
| 13 def is_testharness_output(content_text): | |
| 14 """Returns whether the content_text in parameter is a testharness output. | |
| 15 | |
| 16 Returns: | |
| 17 True if content_text is a valid testharness output. False otherwise. | |
| 18 """ | |
|
Dirk Pranke
2014/09/02 23:48:17
I would just use the first line of the docstring,
mlamouri (slow - plz ping)
2014/09/03 10:53:46
Done.
| |
| 19 | |
| 20 # Leading and trailing white spaces are accepted. | |
| 21 lines = content_text.strip().splitlines() | |
| 22 lines = [line.strip() for line in lines] | |
| 23 | |
| 24 # A testharness output is defined as containing the header and the footer. | |
| 25 found_header = False | |
| 26 found_footer = False | |
| 27 for line in lines: | |
| 28 if line == TESTHARNESSREPORT_HEADER: | |
| 29 found_header = True | |
| 30 elif line == TESTHARNESSREPORT_FOOTER: | |
| 31 found_footer = True | |
| 32 | |
| 33 return found_header and found_footer | |
| 34 | |
| 35 | |
| 36 def is_testharness_output_passing(content_text): | |
| 37 """Returns whether the content_text in parameter is a passing testharness ou tput. | |
| 38 | |
| 39 Note: | |
| 40 It is expected that the |content_text| is a testharness output. | |
| 41 | |
| 42 Returns: | |
| 43 True if content_text is a passing testharness output. False otherwise. | |
|
Dirk Pranke
2014/09/02 23:48:17
Same thing, I would delete lines 41-30 (but keep t
mlamouri (slow - plz ping)
2014/09/03 10:53:46
Done. I assumed that you meant 41-43.
| |
| 44 """ | |
| 45 | |
| 46 # Leading and trailing white spaces are accepted. | |
| 47 lines = content_text.strip().splitlines() | |
| 48 lines = [line.strip() for line in lines] | |
| 49 | |
| 50 # The check is very conservative and reject any unexpected content in the ou tput. | |
|
Dirk Pranke
2014/09/02 23:48:17
nit: grammar: "rejects", not "reject".
mlamouri (slow - plz ping)
2014/09/03 10:53:46
Done.
| |
| 51 for line in lines: | |
| 52 # There should be no empty lines. | |
| 53 if len(line) == 0: | |
| 54 return False | |
| 55 | |
| 56 # Those lines are expected to be exactly equivalent. | |
| 57 if line == TESTHARNESSREPORT_HEADER or \ | |
| 58 line == TESTHARNESSREPORT_FOOTER: | |
| 59 continue | |
| 60 | |
| 61 # Those are expected passing output. | |
| 62 if line.startswith('CONSOLE') or \ | |
| 63 line.startswith('PASS'): | |
| 64 continue | |
| 65 | |
| 66 # Those are expected failing outpu. | |
|
Dirk Pranke
2014/09/02 23:48:17
Nit: typo: "output", not "outpu"
mlamouri (slow - plz ping)
2014/09/03 10:53:46
Done.
| |
| 67 if line.startswith('FAIL') or \ | |
| 68 line.startswith('TIMEOUT') or \ | |
| 69 line.startswith('NOTRUN') or \ | |
| 70 line.startswith('Harness Error. harness_status = '): | |
| 71 return False | |
| 72 | |
| 73 # Unexpected output should be considered as a failure. | |
| 74 return False | |
| 75 | |
| 76 return True | |
| OLD | NEW |