Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/layout_tests/port/base.py

Issue 2580293002: Style change: Rename error variables "e" -> "error" (Closed)
Patch Set: Rebase and fix formatter unittest. Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 image_diff_path = self._path_to_image_diff() 405 image_diff_path = self._path_to_image_diff()
406 if not self._filesystem.exists(image_diff_path): 406 if not self._filesystem.exists(image_diff_path):
407 _log.error("image_diff was not found at %s", image_diff_path) 407 _log.error("image_diff was not found at %s", image_diff_path)
408 return False 408 return False
409 return True 409 return True
410 410
411 def check_pretty_patch(self, more_logging=True): 411 def check_pretty_patch(self, more_logging=True):
412 """Checks whether we can use the PrettyPatch ruby script.""" 412 """Checks whether we can use the PrettyPatch ruby script."""
413 try: 413 try:
414 _ = self._executive.run_command(['ruby', '--version']) 414 _ = self._executive.run_command(['ruby', '--version'])
415 except OSError as e: 415 except OSError as error:
416 if e.errno in [errno.ENOENT, errno.EACCES, errno.ECHILD]: 416 if error.errno in [errno.ENOENT, errno.EACCES, errno.ECHILD]:
417 if more_logging: 417 if more_logging:
418 _log.warning("Ruby is not installed; can't generate pretty p atches.") 418 _log.warning("Ruby is not installed; can't generate pretty p atches.")
419 _log.warning('') 419 _log.warning('')
420 return False 420 return False
421 421
422 if not self._filesystem.exists(self._pretty_patch_path): 422 if not self._filesystem.exists(self._pretty_patch_path):
423 if more_logging: 423 if more_logging:
424 _log.warning("Unable to find %s; can't generate pretty patches." , self._pretty_patch_path) 424 _log.warning("Unable to find %s; can't generate pretty patches." , self._pretty_patch_path)
425 _log.warning('') 425 _log.warning('')
426 return False 426 return False
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 err_str = None 504 err_str = None
505 try: 505 try:
506 exit_code = self._executive.run_command(command, return_exit_code=Tr ue) 506 exit_code = self._executive.run_command(command, return_exit_code=Tr ue)
507 if exit_code == 0: 507 if exit_code == 0:
508 # The images are the same. 508 # The images are the same.
509 result = None 509 result = None
510 elif exit_code == 1: 510 elif exit_code == 1:
511 result = self._filesystem.read_binary_file(native_diff_filename) 511 result = self._filesystem.read_binary_file(native_diff_filename)
512 else: 512 else:
513 err_str = "Image diff returned an exit code of %s. See http://cr bug.com/278596" % exit_code 513 err_str = "Image diff returned an exit code of %s. See http://cr bug.com/278596" % exit_code
514 except OSError as e: 514 except OSError as error:
515 err_str = 'error running image diff: %s' % str(e) 515 err_str = 'error running image diff: %s' % error
516 finally: 516 finally:
517 self._filesystem.rmtree(str(tempdir)) 517 self._filesystem.rmtree(str(tempdir))
518 518
519 return (result, err_str or None) 519 return (result, err_str or None)
520 520
521 def diff_text(self, expected_text, actual_text, expected_filename, actual_fi lename): 521 def diff_text(self, expected_text, actual_text, expected_filename, actual_fi lename):
522 """Returns a string containing the diff of the two text strings 522 """Returns a string containing the diff of the two text strings
523 in 'unified diff' format. 523 in 'unified diff' format.
524 """ 524 """
525 525
(...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after
1445 def wdiff_text(self, actual_filename, expected_filename): 1445 def wdiff_text(self, actual_filename, expected_filename):
1446 """Returns a string of HTML indicating the word-level diff of the 1446 """Returns a string of HTML indicating the word-level diff of the
1447 contents of the two filenames. Returns an empty string if word-level 1447 contents of the two filenames. Returns an empty string if word-level
1448 diffing isn't available. 1448 diffing isn't available.
1449 """ 1449 """
1450 if not self.wdiff_available(): 1450 if not self.wdiff_available():
1451 return "" 1451 return ""
1452 try: 1452 try:
1453 # It's possible to raise a ScriptError we pass wdiff invalid paths. 1453 # It's possible to raise a ScriptError we pass wdiff invalid paths.
1454 return self._run_wdiff(actual_filename, expected_filename) 1454 return self._run_wdiff(actual_filename, expected_filename)
1455 except OSError as e: 1455 except OSError as error:
1456 if e.errno in [errno.ENOENT, errno.EACCES, errno.ECHILD]: 1456 if error.errno in (errno.ENOENT, errno.EACCES, errno.ECHILD):
1457 # Silently ignore cases where wdiff is missing. 1457 # Silently ignore cases where wdiff is missing.
1458 self._wdiff_available = False 1458 self._wdiff_available = False
1459 return "" 1459 return ""
1460 raise 1460 raise
1461 except ScriptError as e: 1461 except ScriptError as error:
1462 _log.error("Failed to run wdiff: %s", e) 1462 _log.error("Failed to run wdiff: %s", error)
1463 self._wdiff_available = False 1463 self._wdiff_available = False
1464 return self._wdiff_error_html 1464 return self._wdiff_error_html
1465 1465
1466 # This is a class variable so we can test error output easily. 1466 # This is a class variable so we can test error output easily.
1467 _pretty_patch_error_html = "Failed to run PrettyPatch, see error log." 1467 _pretty_patch_error_html = "Failed to run PrettyPatch, see error log."
1468 1468
1469 def pretty_patch_text(self, diff_path): 1469 def pretty_patch_text(self, diff_path):
1470 if self._pretty_patch_available is None: 1470 if self._pretty_patch_available is None:
1471 self._pretty_patch_available = self.check_pretty_patch(more_logging= False) 1471 self._pretty_patch_available = self.check_pretty_patch(more_logging= False)
1472 if not self._pretty_patch_available: 1472 if not self._pretty_patch_available:
1473 return self._pretty_patch_error_html 1473 return self._pretty_patch_error_html
1474 command = ("ruby", "-I", self._filesystem.dirname(self._pretty_patch_pat h), 1474 command = ("ruby", "-I", self._filesystem.dirname(self._pretty_patch_pat h),
1475 self._pretty_patch_path, diff_path) 1475 self._pretty_patch_path, diff_path)
1476 try: 1476 try:
1477 # Diffs are treated as binary (we pass decode_output=False) as they 1477 # Diffs are treated as binary (we pass decode_output=False) as they
1478 # may contain multiple files of conflicting encodings. 1478 # may contain multiple files of conflicting encodings.
1479 return self._executive.run_command(command, decode_output=False) 1479 return self._executive.run_command(command, decode_output=False)
1480 except OSError as e: 1480 except OSError as error:
1481 # If the system is missing ruby log the error and stop trying. 1481 # If the system is missing ruby log the error and stop trying.
1482 self._pretty_patch_available = False 1482 self._pretty_patch_available = False
1483 _log.error("Failed to run PrettyPatch (%s): %s", command, e) 1483 _log.error("Failed to run PrettyPatch (%s): %s", command, error)
1484 return self._pretty_patch_error_html 1484 return self._pretty_patch_error_html
1485 except ScriptError as e: 1485 except ScriptError as error:
1486 # If ruby failed to run for some reason, log the command 1486 # If ruby failed to run for some reason, log the command
1487 # output and stop trying. 1487 # output and stop trying.
1488 self._pretty_patch_available = False 1488 self._pretty_patch_available = False
1489 _log.error("Failed to run PrettyPatch (%s):\n%s", command, e.message _with_output()) 1489 _log.error("Failed to run PrettyPatch (%s):\n%s", command, error.mes sage_with_output())
1490 return self._pretty_patch_error_html 1490 return self._pretty_patch_error_html
1491 1491
1492 def default_configuration(self): 1492 def default_configuration(self):
1493 return 'Release' 1493 return 'Release'
1494 1494
1495 def clobber_old_port_specific_results(self): 1495 def clobber_old_port_specific_results(self):
1496 pass 1496 pass
1497 1497
1498 # FIXME: This does not belong on the port object. 1498 # FIXME: This does not belong on the port object.
1499 @memoized 1499 @memoized
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1639 PhysicalTestSuite('fast/text', ["--enable-direct-write", "--enable-f ont-antialiasing"]), 1639 PhysicalTestSuite('fast/text', ["--enable-direct-write", "--enable-f ont-antialiasing"]),
1640 ] 1640 ]
1641 1641
1642 def virtual_test_suites(self): 1642 def virtual_test_suites(self):
1643 if self._virtual_test_suites is None: 1643 if self._virtual_test_suites is None:
1644 path_to_virtual_test_suites = self._filesystem.join(self.layout_test s_dir(), 'VirtualTestSuites') 1644 path_to_virtual_test_suites = self._filesystem.join(self.layout_test s_dir(), 'VirtualTestSuites')
1645 assert self._filesystem.exists(path_to_virtual_test_suites), 'Layout Tests/VirtualTestSuites not found' 1645 assert self._filesystem.exists(path_to_virtual_test_suites), 'Layout Tests/VirtualTestSuites not found'
1646 try: 1646 try:
1647 test_suite_json = json.loads(self._filesystem.read_text_file(pat h_to_virtual_test_suites)) 1647 test_suite_json = json.loads(self._filesystem.read_text_file(pat h_to_virtual_test_suites))
1648 self._virtual_test_suites = [VirtualTestSuite(**d) for d in test _suite_json] 1648 self._virtual_test_suites = [VirtualTestSuite(**d) for d in test _suite_json]
1649 except ValueError as e: 1649 except ValueError as error:
1650 raise ValueError("LayoutTests/VirtualTestSuites is not a valid J SON file: %s" % str(e)) 1650 raise ValueError("LayoutTests/VirtualTestSuites is not a valid J SON file: %s" % error)
1651 return self._virtual_test_suites 1651 return self._virtual_test_suites
1652 1652
1653 def _all_virtual_tests(self, suites): 1653 def _all_virtual_tests(self, suites):
1654 tests = [] 1654 tests = []
1655 for suite in suites: 1655 for suite in suites:
1656 self._populate_virtual_suite(suite) 1656 self._populate_virtual_suite(suite)
1657 tests.extend(suite.tests.keys()) 1657 tests.extend(suite.tests.keys())
1658 return tests 1658 return tests
1659 1659
1660 def _virtual_tests_matching_paths(self, paths, suites): 1660 def _virtual_tests_matching_paths(self, paths, suites):
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1795 1795
1796 def __init__(self, base, args, reference_args=None): 1796 def __init__(self, base, args, reference_args=None):
1797 self.name = base 1797 self.name = base
1798 self.base = base 1798 self.base = base
1799 self.args = args 1799 self.args = args
1800 self.reference_args = args if reference_args is None else reference_args 1800 self.reference_args = args if reference_args is None else reference_args
1801 self.tests = set() 1801 self.tests = set()
1802 1802
1803 def __repr__(self): 1803 def __repr__(self):
1804 return "PhysicalTestSuite('%s', '%s', %s, %s)" % (self.name, self.base, self.args, self.reference_args) 1804 return "PhysicalTestSuite('%s', '%s', %s, %s)" % (self.name, self.base, self.args, self.reference_args)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698