OLD | NEW |
1 # Copyright (C) 2010 Google Inc. All rights reserved. | 1 # Copyright (C) 2010 Google Inc. All rights reserved. |
2 # | 2 # |
3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
5 # met: | 5 # met: |
6 # | 6 # |
7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 result = self._filesystem.read_binary_file(native_diff_filename) | 510 result = self._filesystem.read_binary_file(native_diff_filename) |
511 else: | 511 else: |
512 err_str = "Image diff returned an exit code of %s. See http://cr
bug.com/278596" % exit_code | 512 err_str = "Image diff returned an exit code of %s. See http://cr
bug.com/278596" % exit_code |
513 except OSError as error: | 513 except OSError as error: |
514 err_str = 'error running image diff: %s' % error | 514 err_str = 'error running image diff: %s' % error |
515 finally: | 515 finally: |
516 self._filesystem.rmtree(str(tempdir)) | 516 self._filesystem.rmtree(str(tempdir)) |
517 | 517 |
518 return (result, err_str or None) | 518 return (result, err_str or None) |
519 | 519 |
520 def diff_text(self, expected_text, actual_text, expected_filename, actual_fi
lename): | |
521 """Returns a string containing the diff of the two text strings | |
522 in 'unified diff' format. | |
523 """ | |
524 | |
525 # The filenames show up in the diff output, make sure they're | |
526 # raw bytes and not unicode, so that they don't trigger join() | |
527 # trying to decode the input. | |
528 def to_raw_bytes(string_value): | |
529 if isinstance(string_value, unicode): | |
530 return string_value.encode('utf-8') | |
531 return string_value | |
532 expected_filename = to_raw_bytes(expected_filename) | |
533 actual_filename = to_raw_bytes(actual_filename) | |
534 diff = difflib.unified_diff(expected_text.splitlines(True), | |
535 actual_text.splitlines(True), | |
536 expected_filename, | |
537 actual_filename) | |
538 | |
539 # The diff generated by the difflib is incorrect if one of the files | |
540 # does not have a newline at the end of the file and it is present in | |
541 # the diff. Relevant Python issue: http://bugs.python.org/issue2142 | |
542 def diff_fixup(diff): | |
543 for line in diff: | |
544 yield line | |
545 if not line.endswith('\n'): | |
546 yield '\n\\ No newline at end of file\n' | |
547 | |
548 return ''.join(diff_fixup(diff)) | |
549 | |
550 def driver_name(self): | 520 def driver_name(self): |
551 if self.get_option('driver_name'): | 521 if self.get_option('driver_name'): |
552 return self.get_option('driver_name') | 522 return self.get_option('driver_name') |
553 return self.CONTENT_SHELL_NAME | 523 return self.CONTENT_SHELL_NAME |
554 | 524 |
555 def expected_baselines_by_extension(self, test_name): | 525 def expected_baselines_by_extension(self, test_name): |
556 """Returns a dict mapping baseline suffix to relative path for each base
line in | 526 """Returns a dict mapping baseline suffix to relative path for each base
line in |
557 a test. For reftests, it returns ".==" or ".!=" instead of the suffix. | 527 a test. For reftests, it returns ".==" or ".!=" instead of the suffix. |
558 """ | 528 """ |
559 # FIXME: The name similarity between this and expected_baselines() below
, is unfortunate. | 529 # FIXME: The name similarity between this and expected_baselines() below
, is unfortunate. |
(...skipping 1243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1803 | 1773 |
1804 def __init__(self, base, args, reference_args=None): | 1774 def __init__(self, base, args, reference_args=None): |
1805 self.name = base | 1775 self.name = base |
1806 self.base = base | 1776 self.base = base |
1807 self.args = args | 1777 self.args = args |
1808 self.reference_args = args if reference_args is None else reference_args | 1778 self.reference_args = args if reference_args is None else reference_args |
1809 self.tests = set() | 1779 self.tests = set() |
1810 | 1780 |
1811 def __repr__(self): | 1781 def __repr__(self): |
1812 return "PhysicalTestSuite('%s', '%s', %s, %s)" % (self.name, self.base,
self.args, self.reference_args) | 1782 return "PhysicalTestSuite('%s', '%s', %s, %s)" % (self.name, self.base,
self.args, self.reference_args) |
OLD | NEW |