Changeset 170637 in webkit


Ignore:
Timestamp:
Jul 1, 2014 6:10:18 AM (10 years ago)
Author:
commit-queue@webkit.org
Message:

[webkitpy] Refactor pluralizer in grammar.py
https://bugs.webkit.org/show_bug.cgi?id=133067

Patch by Eva Balazsfalvi <evab.u-szeged@partner.samsung.com> on 2014-07-01
Reviewed by Csaba Osztrogonác.

  • Scripts/webkitpy/layout_tests/controllers/layout_test_runner.py:

(LayoutTestRunner.run_tests):

  • Scripts/webkitpy/layout_tests/controllers/manager.py:

(Manager.run):

  • Scripts/webkitpy/layout_tests/views/printing.py:

(Printer.print_found):
(Printer.print_workers_and_shards):
(Printer._print_one_line_summary):

  • Scripts/webkitpy/test/printer.py:

(Printer.print_result):

  • Scripts/webkitpy/tool/bot/feeders.py:

(EWSFeeder.feed):

  • Scripts/webkitpy/tool/bot/flakytestreporter.py:

(FlakyTestReporter._lookup_bug_for_flaky_test):

  • Scripts/webkitpy/tool/bot/irc_command.py:

(Rollout._check_diff_failure):

  • Scripts/webkitpy/tool/bot/irc_command_unittest.py:

(IRCCommandTest.test_rollout):

  • Scripts/webkitpy/tool/commands/download.py:

(AbstractPatchProcessingCommand._process_patch.execute):
(ProcessBugsMixin._fetch_list_of_patches_to_process):
(ProcessURLsMixin._fetch_list_of_patches_to_process):

  • Scripts/webkitpy/tool/commands/queries.py:

(WhatBroke.execute):

  • Scripts/webkitpy/tool/commands/suggestnominations.py:

(SuggestNominations._print_nominations):
(SuggestNominations._print_counts):

  • Scripts/webkitpy/tool/commands/suggestnominations_unittest.py:

(_make_options):
(test_basic):
(test_with_verbose):

  • Scripts/webkitpy/tool/commands/upload.py:

(PostCommits.execute):

  • Scripts/webkitpy/tool/grammar.py:

(pluralize):

  • Scripts/webkitpy/tool/grammar_unittest.py:

(GrammarTest.test_join_with_separators):
(GrammarTest):
(GrammarTest.test_plural):
(GrammarTest.test_pluralize):

  • Scripts/webkitpy/tool/multicommandtool.py:

(Command.check_arguments_and_execute):

  • Scripts/webkitpy/tool/steps/obsoletepatches.py:

(ObsoletePatches.run):

  • Scripts/webkitpy/tool/steps/preparechangelogforrevert.py:

(PrepareChangeLogForRevert._message_for_revert):

Location:
trunk/Tools
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r170623 r170637  
     12014-07-01  Eva Balazsfalvi  <evab.u-szeged@partner.samsung.com>
     2
     3        [webkitpy] Refactor pluralizer in grammar.py
     4        https://bugs.webkit.org/show_bug.cgi?id=133067
     5
     6        Reviewed by Csaba Osztrogonác.
     7
     8        * Scripts/webkitpy/layout_tests/controllers/layout_test_runner.py:
     9        (LayoutTestRunner.run_tests):
     10        * Scripts/webkitpy/layout_tests/controllers/manager.py:
     11        (Manager.run):
     12        * Scripts/webkitpy/layout_tests/views/printing.py:
     13        (Printer.print_found):
     14        (Printer.print_workers_and_shards):
     15        (Printer._print_one_line_summary):
     16        * Scripts/webkitpy/test/printer.py:
     17        (Printer.print_result):
     18        * Scripts/webkitpy/tool/bot/feeders.py:
     19        (EWSFeeder.feed):
     20        * Scripts/webkitpy/tool/bot/flakytestreporter.py:
     21        (FlakyTestReporter._lookup_bug_for_flaky_test):
     22        * Scripts/webkitpy/tool/bot/irc_command.py:
     23        (Rollout._check_diff_failure):
     24        * Scripts/webkitpy/tool/bot/irc_command_unittest.py:
     25        (IRCCommandTest.test_rollout):
     26        * Scripts/webkitpy/tool/commands/download.py:
     27        (AbstractPatchProcessingCommand._process_patch.execute):
     28        (ProcessBugsMixin._fetch_list_of_patches_to_process):
     29        (ProcessURLsMixin._fetch_list_of_patches_to_process):
     30        * Scripts/webkitpy/tool/commands/queries.py:
     31        (WhatBroke.execute):
     32        * Scripts/webkitpy/tool/commands/suggestnominations.py:
     33        (SuggestNominations._print_nominations):
     34        (SuggestNominations._print_counts):
     35        * Scripts/webkitpy/tool/commands/suggestnominations_unittest.py:
     36        (_make_options):
     37        (test_basic):
     38        (test_with_verbose):
     39        * Scripts/webkitpy/tool/commands/upload.py:
     40        (PostCommits.execute):
     41        * Scripts/webkitpy/tool/grammar.py:
     42        (pluralize):
     43        * Scripts/webkitpy/tool/grammar_unittest.py:
     44        (GrammarTest.test_join_with_separators):
     45        (GrammarTest):
     46        (GrammarTest.test_plural):
     47        (GrammarTest.test_pluralize):
     48        * Scripts/webkitpy/tool/multicommandtool.py:
     49        (Command.check_arguments_and_execute):
     50        * Scripts/webkitpy/tool/steps/obsoletepatches.py:
     51        (ObsoletePatches.run):
     52        * Scripts/webkitpy/tool/steps/preparechangelogforrevert.py:
     53        (PrepareChangeLogForRevert._message_for_revert):
     54
    1552014-06-30  Myles C. Maxfield  <mmaxfield@apple.com>
    256
  • trunk/Tools/Scripts/webkitpy/layout_tests/controllers/layout_test_runner.py

    r166515 r170637  
    126126            return run_results
    127127
    128         self._printer.write_update('Starting %s ...' % grammar.pluralize('worker', num_workers))
     128        self._printer.write_update('Starting %s ...' % grammar.pluralize(num_workers, "worker"))
    129129
    130130        try:
  • trunk/Tools/Scripts/webkitpy/layout_tests/controllers/manager.py

    r163134 r170637  
    5252from webkitpy.layout_tests.models import test_run_results
    5353from webkitpy.layout_tests.models.test_input import TestInput
     54from webkitpy.tool.grammar import pluralize
    5455
    5556_log = logging.getLogger(__name__)
     
    204205
    205206                _log.info('')
    206                 _log.info("Retrying %d unexpected failure(s) ..." % len(tests_to_retry))
     207                _log.info("Retrying %s ..." % pluralize(len(tests_to_retry), "unexpected failure"))
    207208                _log.info('')
    208209                retry_results = self._run_tests(tests_to_retry, tests_to_skip=set(), repeat_each=1, iterations=1,
  • trunk/Tools/Scripts/webkitpy/layout_tests/views/printing.py

    r151201 r170637  
    9999
    100100    def print_found(self, num_all_test_files, num_to_run, repeat_each, iterations):
    101         found_str = 'Found %s; running %d' % (grammar.pluralize('test', num_all_test_files), num_to_run)
     101        found_str = 'Found %s; running %d' % (grammar.pluralize(num_all_test_files, "test"), num_to_run)
    102102        if repeat_each * iterations > 1:
    103             found_str += ' (%d times each: --repeat-each=%d --iterations=%d)' % (repeat_each * iterations, repeat_each, iterations)
     103            found_str += ' (%s each: --repeat-each=%d --iterations=%d)' % (grammar.pluralize(repeat_each * iterations, "time"), repeat_each, iterations)
    104104        found_str += ', skipping %d' % (num_all_test_files - num_to_run)
    105105        self._print_default(found_str + '.')
     
    115115        if num_workers == 1:
    116116            self._print_default("Running 1 %s." % driver_name)
    117             self._print_debug("(%s)." % grammar.pluralize('shard', num_shards))
    118         else:
    119             self._print_default("Running %d %ss in parallel." % (num_workers, driver_name))
     117            self._print_debug("(%s)." % grammar.pluralize(num_shards, "shard"))
     118        else:
     119            self._print_default("Running %s in parallel." % (grammar.pluralize(num_workers, driver_name)))
    120120            self._print_debug("(%d shards; %d locked)." % (num_shards, num_locked_shards))
    121121        self._print_default('')
     
    281281                    summary = "The test ran as expected."
    282282            else:
    283                 summary = "%s ran as expected%s." % (grammar.pluralize('test', expected), incomplete_str)
    284         else:
    285             summary = "%s ran as expected, %d didn't%s:" % (grammar.pluralize('test', expected), unexpected, incomplete_str)
     283                summary = "%s ran as expected%s." % (grammar.pluralize(expected, "test"), incomplete_str)
     284        else:
     285            summary = "%s ran as expected, %d didn't%s:" % (grammar.pluralize(expected, "test"), unexpected, incomplete_str)
    286286
    287287        self._print_quiet(summary)
  • trunk/Tools/Scripts/webkitpy/test/printer.py

    r151201 r170637  
    2727from webkitpy.common.system.systemhost import SystemHost
    2828from webkitpy.layout_tests.views.metered_stream import MeteredStream
     29from webkitpy.tool.grammar import pluralize
    2930
    3031_log = logging.getLogger(__name__)
     
    179180    def print_result(self, run_time):
    180181        write = self.meter.writeln
    181         write('Ran %d test%s in %.3fs' % (self.num_started, self.num_started != 1 and "s" or "", run_time))
     182        write('Ran %s in %.3fs' % (pluralize(self.num_started, "test"), run_time))
    182183        if self.num_failures or self.num_errors:
    183184            write('FAILED (failures=%d, errors=%d)\n' % (self.num_failures, self.num_errors))
  • trunk/Tools/Scripts/webkitpy/tool/bot/feeders.py

    r159052 r170637  
    9494        ids_needing_review = set(self._tool.bugs.queries.fetch_attachment_ids_from_review_queue(datetime.today() - timedelta(7)))
    9595        new_ids = ids_needing_review.difference(self._ids_sent_to_server)
    96         _log.info("Feeding EWS (%s, %s new)" % (pluralize("r? patch", len(ids_needing_review)), len(new_ids)))
     96        _log.info("Feeding EWS (%s, %s new)" % (pluralize(len(ids_needing_review), "r? patch"), len(new_ids)))
    9797        for attachment_id in new_ids:  # Order doesn't really matter for the EWS.
    9898            self._tool.status_server.submit_to_ews(attachment_id)
  • trunk/Tools/Scripts/webkitpy/tool/bot/flakytestreporter.py

    r157682 r170637  
    8080            # FIXME: There are probably heuristics we could use for finding
    8181            # the right bug instead of the first, like open vs. closed.
    82             _log.warn("Found %s %s matching '%s' filed by a bot, using the first." % (pluralize('bug', len(bugs)), [bug.id() for bug in bugs], flaky_test))
     82            _log.warn("Found %s %s matching '%s' filed by a bot, using the first." % (pluralize(len(bugs), "bug"), [bug.id() for bug in bugs], flaky_test))
    8383        return bugs[0]
    8484
  • trunk/Tools/Scripts/webkitpy/tool/bot/irc_command.py

    r159675 r170637  
    3838from webkitpy.tool.bot.queueengine import TerminateQueue
    3939from webkitpy.tool.grammar import join_with_separators
     40from webkitpy.tool.grammar import pluralize
    4041
    4142
     
    214215
    215216        lines = error_log[revert_failure_message_start:].split('\n')[1:]
    216         files = itertools.takewhile(lambda line: tool.filesystem.exists(tool.scm().absolute_path(line)), lines)
     217        files = list(itertools.takewhile(lambda line: tool.filesystem.exists(tool.scm().absolute_path(line)), lines))
    217218        if files:
    218             return "Failed to apply reverse diff for file(s): %s" % ", ".join(files)
     219            return "Failed to apply reverse diff for %s: %s" % (pluralize(len(files), "file", showCount=False), ", ".join(files))
    219220        return None
    220221
  • trunk/Tools/Scripts/webkitpy/tool/bot/irc_command_unittest.py

    r148372 r170637  
    118118        tool.filesystem.files["/mock-checkout/test/file/one"] = ""
    119119        tool.filesystem.files["/mock-checkout/test/file/two"] = ""
    120         self.assertEqual("Failed to apply reverse diff for file(s): test/file/one, test/file/two",
     120        self.assertEqual("Failed to apply reverse diff for files: test/file/one, test/file/two",
    121121                          rollout._check_diff_failure("""
    122122Preparing rollout for bug 123456.
     
    131131Current branch master is up to date.
    132132        """, tool))
     133
     134        self.assertEqual("Failed to apply reverse diff for file: test/file/one",
     135                          rollout._check_diff_failure("""
     136Preparing rollout for bug 123456.
     137Updating working directory
     138Failed to apply reverse diff for revision 123456 because of the following conflicts:
     139test/file/one
     140Updating OpenSource
     141Current branch master is up to date.
     142        """, tool))
     143
    133144        self.assertEqual(None, rollout._check_diff_failure("""
    134145Preparing rollout for bug 123456.
  • trunk/Tools/Scripts/webkitpy/tool/commands/download.py

    r166646 r170637  
    172172        # It's nice to print out total statistics.
    173173        bugs_to_patches = self._collect_patches_by_bug(patches)
    174         _log.info("Processing %s from %s." % (pluralize("patch", len(patches)), pluralize("bug", len(bugs_to_patches))))
     174        _log.info("Processing %s from %s." % (pluralize(len(patches), "patch"), pluralize(len(bugs_to_patches), "bug")))
    175175
    176176        for patch in patches:
     
    217217        for bug_id in args:
    218218            patches = tool.bugs.fetch_bug(bug_id).reviewed_patches()
    219             _log.info("%s found on bug %s." % (pluralize("reviewed patch", len(patches)), bug_id))
     219            _log.info("%s found on bug %s." % (pluralize(len(patches), "reviewed patch"), bug_id))
    220220            all_patches += patches
    221221        if not all_patches:
     
    223223            for bug_id in args:
    224224                patches = tool.bugs.fetch_bug(bug_id).patches()
    225                 _log.info("%s found on bug %s." % (pluralize("patch", len(patches)), bug_id))
     225                _log.info("%s found on bug %s." % (pluralize(len(patches), "patch"), bug_id))
    226226                all_patches += patches
    227227        return all_patches
     
    235235            if bug_id:
    236236                patches = tool.bugs.fetch_bug(bug_id).patches()
    237                 _log.info("%s found on bug %s." % (pluralize("patch", len(patches)), bug_id))
     237                _log.info("%s found on bug %s." % (pluralize(len(patches), "patch"), bug_id))
    238238                all_patches += patches
    239239
  • trunk/Tools/Scripts/webkitpy/tool/commands/queries.py

    r160756 r170637  
    218218            failing_builders += 1
    219219        if failing_builders:
    220             print "%s of %s are failing" % (failing_builders, pluralize("builder", len(builder_statuses)))
     220            print "%s of %s are failing" % (failing_builders, pluralize(len(builder_statuses), "builder"))
    221221        else:
    222222            print "All builders are passing!"
  • trunk/Tools/Scripts/webkitpy/tool/commands/suggestnominations.py

    r150461 r170637  
    3333from webkitpy.common.checkout.changelog import ChangeLogEntry
    3434from webkitpy.common.config.committers import CommitterList
    35 from webkitpy.tool.grammar import join_with_separators
     35from webkitpy.tool import grammar
    3636from webkitpy.tool.multicommandtool import Command
    3737
     
    255255        for nomination in sorted(nominations, nomination_cmp):
    256256            # This is a little bit of a hack, but its convienent to just pass the nomination dictionary to the formating operator.
    257             nomination['roles_string'] = join_with_separators(nomination['roles']).upper()
     257            nomination['roles_string'] = grammar.join_with_separators(nomination['roles']).upper()
    258258            print "%(roles_string)s: %(author_name)s (%(author_email)s) has %(patch_count)s reviewed patches" % nomination
    259259            counter = counters_by_email[nomination['author_email']]
     
    289289                alias_list.append(alias)
    290290            if alias_list:
    291                 print "CONTRIBUTOR: %s (%s) has %d reviewed patches %s" % (author_name, author_email, patch_count, "(aliases: " + ", ".join(alias_list) + ")")
     291                print "CONTRIBUTOR: %s (%s) has %s %s" % (author_name, author_email, grammar.pluralize(patch_count, "reviewed patch"), "(aliases: " + ", ".join(alias_list) + ")")
    292292            else:
    293                 print "CONTRIBUTOR: %s (%s) has %d reviewed patches" % (author_name, author_email, patch_count)
     293                print "CONTRIBUTOR: %s (%s) has %s" % (author_name, author_email, grammar.pluralize(patch_count, "reviewed patch"))
    294294        return
    295295
  • trunk/Tools/Scripts/webkitpy/tool/commands/suggestnominations_unittest.py

    r149419 r170637  
    5757"""
    5858
    59     def _make_options(self, **kwargs):
     59    def _make_options(self, verbose=False, **kwargs):
    6060        defaults = {
    6161            'committer_minimum': 10,
     
    6363            'reviewer_minimum': 80,
    6464            'show_commits': False,
    65             'verbose': False,
     65            'verbose': verbose,
    6666        }
    6767        options = MockOptions(**defaults)
     
    102102        suggest_nominations._recent_commit_messages = lambda: [self.mock_non_committer_commit_message for _ in range(88)]
    103103        self.assert_execute_outputs(suggest_nominations, [], expected_stdout=expected_stdout, options=options)
     104
     105    def test_with_verbose(self):
     106        expected_stdout = "REVIEWER: Xianzhu Wang (wangxianzhu@chromium.org) has 88 reviewed patches\nCONTRIBUTOR: Xianzhu Wang (wangxianzhu@chromium.org) has 88 reviewed patches\n"
     107        options = self._make_options(verbose=True)
     108        suggest_nominations = SuggestNominations()
     109        suggest_nominations._init_options(options=options)
     110        suggest_nominations._recent_commit_messages = lambda: [self.mock_non_committer_commit_message for _ in range(88)]
     111        self.assert_execute_outputs(suggest_nominations, [], expected_stdout=expected_stdout, options=options)
  • trunk/Tools/Scripts/webkitpy/tool/commands/upload.py

    r148360 r170637  
    334334        commit_ids = tool.scm().commit_ids_from_commitish_arguments(args)
    335335        if len(commit_ids) > 10: # We could lower this limit, 10 is too many for one bug as-is.
    336             _log.error("webkit-patch does not support attaching %s at once.  Are you sure you passed the right commit range?" % (pluralize("patch", len(commit_ids))))
     336            _log.error("webkit-patch does not support attaching %s at once.  Are you sure you passed the right commit range?" % (pluralize(len(commit_ids), "patch")))
    337337            sys.exit(1)
    338338
  • trunk/Tools/Scripts/webkitpy/tool/grammar.py

    r56737 r170637  
    3939
    4040
    41 def pluralize(noun, count):
     41def pluralize(count, noun, showCount=True):
    4242    if count != 1:
    4343        noun = plural(noun)
    44     return "%d %s" % (count, noun)
     44    if showCount:
     45        return "%d %s" % (count, noun)
     46    else:
     47        return "%s" % noun
    4548
    4649
  • trunk/Tools/Scripts/webkitpy/tool/grammar_unittest.py

    r140510 r170637  
    3030
    3131from webkitpy.tool.grammar import join_with_separators
     32from webkitpy.tool.grammar import plural
     33from webkitpy.tool.grammar import pluralize
    3234
    3335class GrammarTest(unittest.TestCase):
     
    3739        self.assertEqual(join_with_separators(["one", "two"]), "one and two")
    3840        self.assertEqual(join_with_separators(["one", "two", "three"]), "one, two, and three")
     41
     42    def test_plural(self):
     43        self.assertEqual(plural("patch"), "patches")
     44        self.assertEqual(plural("test"), "tests")
     45
     46    def test_pluralize(self):
     47        self.assertEqual(pluralize(1, "patch"), "1 patch")
     48        self.assertEqual(pluralize(2, "patch"), "2 patches")
     49        self.assertEqual(pluralize(1, "patch", True), "1 patch")
     50        self.assertEqual(pluralize(2, "patch", True), "2 patches")
     51        self.assertEqual(pluralize(1, "patch", False), "patch")
     52        self.assertEqual(pluralize(2, "patch", False), "patches")
  • trunk/Tools/Scripts/webkitpy/tool/multicommandtool.py

    r148360 r170637  
    114114        if len(args) < len(self.required_arguments):
    115115            _log.error("%s required, %s provided.  Provided: %s  Required: %s\nSee '%s help %s' for usage." % (
    116                        pluralize("argument", len(self.required_arguments)),
    117                        pluralize("argument", len(args)),
     116                       pluralize(len(self.required_arguments), "argument"),
     117                       pluralize(len(args), "argument"),
    118118                       "'%s'" % " ".join(args),
    119119                       " ".join(self.required_arguments),
  • trunk/Tools/Scripts/webkitpy/tool/steps/obsoletepatches.py

    r135744 r170637  
    5050        if not patches:
    5151            return
    52         _log.info("Obsoleting %s on bug %s" % (pluralize("old patch", len(patches)), bug_id))
     52        _log.info("Obsoleting %s on bug %s" % (pluralize(len(patches), "old patch"), bug_id))
    5353        for patch in patches:
    5454            self._tool.bugs.obsolete_attachment(patch.id())
  • trunk/Tools/Scripts/webkitpy/tool/steps/preparechangelogforrevert.py

    r165447 r170637  
    2929from webkitpy.common.checkout.changelog import ChangeLog
    3030from webkitpy.common.config import urls
    31 from webkitpy.tool.grammar import join_with_separators
     31from webkitpy.tool import grammar
    3232from webkitpy.tool.steps.abstractstep import AbstractStep
    3333
     
    3636    @classmethod
    3737    def _message_for_revert(cls, revision_list, reason, description_list, reverted_bug_url_list, rollout_bug_url=None):
    38         message = "Unreviewed, rolling out %s.\n" % join_with_separators(['r' + str(revision) for revision in revision_list])
     38        message = "Unreviewed, rolling out %s.\n" % grammar.join_with_separators(['r' + str(revision) for revision in revision_list])
    3939        if rollout_bug_url:
    4040            message += "%s\n" % rollout_bug_url
     
    4343            message += "%s\n" % reason
    4444        message += "\n"
    45         pluralSuffix = 's' if len(revision_list) > 1 else ''
    46         message += "Reverted changeset%s:\n\n" % pluralSuffix
     45        message += "Reverted %s:\n\n" % grammar.pluralize(len(revision_list), "changeset", showCount=False)
    4746        for index in range(len(revision_list)):
    4847            if description_list[index]:
Note: See TracChangeset for help on using the changeset viewer.