Title: [170637] trunk/Tools
Revision
170637
Author
[email protected]
Date
2014-07-01 06:10:18 -0700 (Tue, 01 Jul 2014)

Log Message

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

Patch by Eva Balazsfalvi <[email protected]> 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):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (170636 => 170637)


--- trunk/Tools/ChangeLog	2014-07-01 12:07:08 UTC (rev 170636)
+++ trunk/Tools/ChangeLog	2014-07-01 13:10:18 UTC (rev 170637)
@@ -1,3 +1,57 @@
+2014-07-01  Eva Balazsfalvi  <[email protected]>
+
+        [webkitpy] Refactor pluralizer in grammar.py
+        https://bugs.webkit.org/show_bug.cgi?id=133067
+
+        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):
+
 2014-06-30  Myles C. Maxfield  <[email protected]>
 
         [iOS] GSFontAddCGFont is deprecated and we use it in DumpRenderTree

Modified: trunk/Tools/Scripts/webkitpy/layout_tests/controllers/layout_test_runner.py (170636 => 170637)


--- trunk/Tools/Scripts/webkitpy/layout_tests/controllers/layout_test_runner.py	2014-07-01 12:07:08 UTC (rev 170636)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/controllers/layout_test_runner.py	2014-07-01 13:10:18 UTC (rev 170637)
@@ -125,7 +125,7 @@
         if self._options.dry_run:
             return run_results
 
-        self._printer.write_update('Starting %s ...' % grammar.pluralize('worker', num_workers))
+        self._printer.write_update('Starting %s ...' % grammar.pluralize(num_workers, "worker"))
 
         try:
             with message_pool.get(self, self._worker_factory, num_workers, self._port.worker_startup_delay_secs(), self._port.host) as pool:

Modified: trunk/Tools/Scripts/webkitpy/layout_tests/controllers/manager.py (170636 => 170637)


--- trunk/Tools/Scripts/webkitpy/layout_tests/controllers/manager.py	2014-07-01 12:07:08 UTC (rev 170636)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/controllers/manager.py	2014-07-01 13:10:18 UTC (rev 170637)
@@ -51,6 +51,7 @@
 from webkitpy.layout_tests.models import test_failures
 from webkitpy.layout_tests.models import test_run_results
 from webkitpy.layout_tests.models.test_input import TestInput
+from webkitpy.tool.grammar import pluralize
 
 _log = logging.getLogger(__name__)
 
@@ -203,7 +204,7 @@
                 enabled_pixel_tests_in_retry = self._force_pixel_tests_if_needed()
 
                 _log.info('')
-                _log.info("Retrying %d unexpected failure(s) ..." % len(tests_to_retry))
+                _log.info("Retrying %s ..." % pluralize(len(tests_to_retry), "unexpected failure"))
                 _log.info('')
                 retry_results = self._run_tests(tests_to_retry, tests_to_skip=set(), repeat_each=1, iterations=1,
                     num_workers=1, retrying=True)

Modified: trunk/Tools/Scripts/webkitpy/layout_tests/views/printing.py (170636 => 170637)


--- trunk/Tools/Scripts/webkitpy/layout_tests/views/printing.py	2014-07-01 12:07:08 UTC (rev 170636)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/views/printing.py	2014-07-01 13:10:18 UTC (rev 170637)
@@ -98,9 +98,9 @@
         self._print_default('')
 
     def print_found(self, num_all_test_files, num_to_run, repeat_each, iterations):
-        found_str = 'Found %s; running %d' % (grammar.pluralize('test', num_all_test_files), num_to_run)
+        found_str = 'Found %s; running %d' % (grammar.pluralize(num_all_test_files, "test"), num_to_run)
         if repeat_each * iterations > 1:
-            found_str += ' (%d times each: --repeat-each=%d --iterations=%d)' % (repeat_each * iterations, repeat_each, iterations)
+            found_str += ' (%s each: --repeat-each=%d --iterations=%d)' % (grammar.pluralize(repeat_each * iterations, "time"), repeat_each, iterations)
         found_str += ', skipping %d' % (num_all_test_files - num_to_run)
         self._print_default(found_str + '.')
 
@@ -114,9 +114,9 @@
         driver_name = self._port.driver_name()
         if num_workers == 1:
             self._print_default("Running 1 %s." % driver_name)
-            self._print_debug("(%s)." % grammar.pluralize('shard', num_shards))
+            self._print_debug("(%s)." % grammar.pluralize(num_shards, "shard"))
         else:
-            self._print_default("Running %d %ss in parallel." % (num_workers, driver_name))
+            self._print_default("Running %s in parallel." % (grammar.pluralize(num_workers, driver_name)))
             self._print_debug("(%d shards; %d locked)." % (num_shards, num_locked_shards))
         self._print_default('')
 
@@ -280,9 +280,9 @@
                 else:
                     summary = "The test ran as expected."
             else:
-                summary = "%s ran as expected%s." % (grammar.pluralize('test', expected), incomplete_str)
+                summary = "%s ran as expected%s." % (grammar.pluralize(expected, "test"), incomplete_str)
         else:
-            summary = "%s ran as expected, %d didn't%s:" % (grammar.pluralize('test', expected), unexpected, incomplete_str)
+            summary = "%s ran as expected, %d didn't%s:" % (grammar.pluralize(expected, "test"), unexpected, incomplete_str)
 
         self._print_quiet(summary)
         self._print_quiet("")

Modified: trunk/Tools/Scripts/webkitpy/test/printer.py (170636 => 170637)


--- trunk/Tools/Scripts/webkitpy/test/printer.py	2014-07-01 12:07:08 UTC (rev 170636)
+++ trunk/Tools/Scripts/webkitpy/test/printer.py	2014-07-01 13:10:18 UTC (rev 170637)
@@ -26,6 +26,7 @@
 
 from webkitpy.common.system.systemhost import SystemHost
 from webkitpy.layout_tests.views.metered_stream import MeteredStream
+from webkitpy.tool.grammar import pluralize
 
 _log = logging.getLogger(__name__)
 
@@ -178,7 +179,7 @@
 
     def print_result(self, run_time):
         write = self.meter.writeln
-        write('Ran %d test%s in %.3fs' % (self.num_started, self.num_started != 1 and "s" or "", run_time))
+        write('Ran %s in %.3fs' % (pluralize(self.num_started, "test"), run_time))
         if self.num_failures or self.num_errors:
             write('FAILED (failures=%d, errors=%d)\n' % (self.num_failures, self.num_errors))
         else:

Modified: trunk/Tools/Scripts/webkitpy/tool/bot/feeders.py (170636 => 170637)


--- trunk/Tools/Scripts/webkitpy/tool/bot/feeders.py	2014-07-01 12:07:08 UTC (rev 170636)
+++ trunk/Tools/Scripts/webkitpy/tool/bot/feeders.py	2014-07-01 13:10:18 UTC (rev 170637)
@@ -93,7 +93,7 @@
     def feed(self):
         ids_needing_review = set(self._tool.bugs.queries.fetch_attachment_ids_from_review_queue(datetime.today() - timedelta(7)))
         new_ids = ids_needing_review.difference(self._ids_sent_to_server)
-        _log.info("Feeding EWS (%s, %s new)" % (pluralize("r? patch", len(ids_needing_review)), len(new_ids)))
+        _log.info("Feeding EWS (%s, %s new)" % (pluralize(len(ids_needing_review), "r? patch"), len(new_ids)))
         for attachment_id in new_ids:  # Order doesn't really matter for the EWS.
             self._tool.status_server.submit_to_ews(attachment_id)
             self._ids_sent_to_server.add(attachment_id)

Modified: trunk/Tools/Scripts/webkitpy/tool/bot/flakytestreporter.py (170636 => 170637)


--- trunk/Tools/Scripts/webkitpy/tool/bot/flakytestreporter.py	2014-07-01 12:07:08 UTC (rev 170636)
+++ trunk/Tools/Scripts/webkitpy/tool/bot/flakytestreporter.py	2014-07-01 13:10:18 UTC (rev 170637)
@@ -79,7 +79,7 @@
         if len(bugs) > 1:
             # FIXME: There are probably heuristics we could use for finding
             # the right bug instead of the first, like open vs. closed.
-            _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))
+            _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))
         return bugs[0]
 
     def _view_source_url_for_test(self, test_path):

Modified: trunk/Tools/Scripts/webkitpy/tool/bot/irc_command.py (170636 => 170637)


--- trunk/Tools/Scripts/webkitpy/tool/bot/irc_command.py	2014-07-01 12:07:08 UTC (rev 170636)
+++ trunk/Tools/Scripts/webkitpy/tool/bot/irc_command.py	2014-07-01 13:10:18 UTC (rev 170637)
@@ -37,6 +37,7 @@
 from webkitpy.common.system.executive import ScriptError
 from webkitpy.tool.bot.queueengine import TerminateQueue
 from webkitpy.tool.grammar import join_with_separators
+from webkitpy.tool.grammar import pluralize
 
 
 def _post_error_and_check_for_bug_url(tool, nicks_string, exception):
@@ -213,9 +214,9 @@
             return None
 
         lines = error_log[revert_failure_message_start:].split('\n')[1:]
-        files = itertools.takewhile(lambda line: tool.filesystem.exists(tool.scm().absolute_path(line)), lines)
+        files = list(itertools.takewhile(lambda line: tool.filesystem.exists(tool.scm().absolute_path(line)), lines))
         if files:
-            return "Failed to apply reverse diff for file(s): %s" % ", ".join(files)
+            return "Failed to apply reverse diff for %s: %s" % (pluralize(len(files), "file", showCount=False), ", ".join(files))
         return None
 
     def execute(self, nick, args, tool, sheriff):

Modified: trunk/Tools/Scripts/webkitpy/tool/bot/irc_command_unittest.py (170636 => 170637)


--- trunk/Tools/Scripts/webkitpy/tool/bot/irc_command_unittest.py	2014-07-01 12:07:08 UTC (rev 170636)
+++ trunk/Tools/Scripts/webkitpy/tool/bot/irc_command_unittest.py	2014-07-01 13:10:18 UTC (rev 170637)
@@ -117,7 +117,7 @@
         tool = MockTool()
         tool.filesystem.files["/mock-checkout/test/file/one"] = ""
         tool.filesystem.files["/mock-checkout/test/file/two"] = ""
-        self.assertEqual("Failed to apply reverse diff for file(s): test/file/one, test/file/two",
+        self.assertEqual("Failed to apply reverse diff for files: test/file/one, test/file/two",
                           rollout._check_diff_failure("""
 Preparing rollout for bug 123456.
 Updating working directory
@@ -130,6 +130,17 @@
 Updating OpenSource
 Current branch master is up to date.
         """, tool))
+
+        self.assertEqual("Failed to apply reverse diff for file: test/file/one",
+                          rollout._check_diff_failure("""
+Preparing rollout for bug 123456.
+Updating working directory
+Failed to apply reverse diff for revision 123456 because of the following conflicts:
+test/file/one
+Updating OpenSource
+Current branch master is up to date.
+        """, tool))
+
         self.assertEqual(None, rollout._check_diff_failure("""
 Preparing rollout for bug 123456.
 Updating working directory

Modified: trunk/Tools/Scripts/webkitpy/tool/commands/download.py (170636 => 170637)


--- trunk/Tools/Scripts/webkitpy/tool/commands/download.py	2014-07-01 12:07:08 UTC (rev 170636)
+++ trunk/Tools/Scripts/webkitpy/tool/commands/download.py	2014-07-01 13:10:18 UTC (rev 170637)
@@ -171,7 +171,7 @@
 
         # It's nice to print out total statistics.
         bugs_to_patches = self._collect_patches_by_bug(patches)
-        _log.info("Processing %s from %s." % (pluralize("patch", len(patches)), pluralize("bug", len(bugs_to_patches))))
+        _log.info("Processing %s from %s." % (pluralize(len(patches), "patch"), pluralize(len(bugs_to_patches), "bug")))
 
         for patch in patches:
             self._process_patch(patch, options, args, tool)
@@ -216,13 +216,13 @@
         all_patches = []
         for bug_id in args:
             patches = tool.bugs.fetch_bug(bug_id).reviewed_patches()
-            _log.info("%s found on bug %s." % (pluralize("reviewed patch", len(patches)), bug_id))
+            _log.info("%s found on bug %s." % (pluralize(len(patches), "reviewed patch"), bug_id))
             all_patches += patches
         if not all_patches:
             _log.info("No reviewed patches found, looking for unreviewed patches.")
             for bug_id in args:
                 patches = tool.bugs.fetch_bug(bug_id).patches()
-                _log.info("%s found on bug %s." % (pluralize("patch", len(patches)), bug_id))
+                _log.info("%s found on bug %s." % (pluralize(len(patches), "patch"), bug_id))
                 all_patches += patches
         return all_patches
 
@@ -234,7 +234,7 @@
             bug_id = urls.parse_bug_id(url)
             if bug_id:
                 patches = tool.bugs.fetch_bug(bug_id).patches()
-                _log.info("%s found on bug %s." % (pluralize("patch", len(patches)), bug_id))
+                _log.info("%s found on bug %s." % (pluralize(len(patches), "patch"), bug_id))
                 all_patches += patches
 
             attachment_id = urls.parse_attachment_id(url)

Modified: trunk/Tools/Scripts/webkitpy/tool/commands/queries.py (170636 => 170637)


--- trunk/Tools/Scripts/webkitpy/tool/commands/queries.py	2014-07-01 12:07:08 UTC (rev 170636)
+++ trunk/Tools/Scripts/webkitpy/tool/commands/queries.py	2014-07-01 13:10:18 UTC (rev 170637)
@@ -217,7 +217,7 @@
             self._print_blame_information_for_builder(builder_status, name_width=longest_builder_name)
             failing_builders += 1
         if failing_builders:
-            print "%s of %s are failing" % (failing_builders, pluralize("builder", len(builder_statuses)))
+            print "%s of %s are failing" % (failing_builders, pluralize(len(builder_statuses), "builder"))
         else:
             print "All builders are passing!"
 

Modified: trunk/Tools/Scripts/webkitpy/tool/commands/suggestnominations.py (170636 => 170637)


--- trunk/Tools/Scripts/webkitpy/tool/commands/suggestnominations.py	2014-07-01 12:07:08 UTC (rev 170636)
+++ trunk/Tools/Scripts/webkitpy/tool/commands/suggestnominations.py	2014-07-01 13:10:18 UTC (rev 170637)
@@ -32,7 +32,7 @@
 
 from webkitpy.common.checkout.changelog import ChangeLogEntry
 from webkitpy.common.config.committers import CommitterList
-from webkitpy.tool.grammar import join_with_separators
+from webkitpy.tool import grammar
 from webkitpy.tool.multicommandtool import Command
 
 
@@ -254,7 +254,7 @@
 
         for nomination in sorted(nominations, nomination_cmp):
             # This is a little bit of a hack, but its convienent to just pass the nomination dictionary to the formating operator.
-            nomination['roles_string'] = join_with_separators(nomination['roles']).upper()
+            nomination['roles_string'] = grammar.join_with_separators(nomination['roles']).upper()
             print "%(roles_string)s: %(author_name)s (%(author_email)s) has %(patch_count)s reviewed patches" % nomination
             counter = counters_by_email[nomination['author_email']]
 
@@ -288,9 +288,9 @@
             for alias in counter['emails']:
                 alias_list.append(alias)
             if alias_list:
-                print "CONTRIBUTOR: %s (%s) has %d reviewed patches %s" % (author_name, author_email, patch_count, "(aliases: " + ", ".join(alias_list) + ")")
+                print "CONTRIBUTOR: %s (%s) has %s %s" % (author_name, author_email, grammar.pluralize(patch_count, "reviewed patch"), "(aliases: " + ", ".join(alias_list) + ")")
             else:
-                print "CONTRIBUTOR: %s (%s) has %d reviewed patches" % (author_name, author_email, patch_count)
+                print "CONTRIBUTOR: %s (%s) has %s" % (author_name, author_email, grammar.pluralize(patch_count, "reviewed patch"))
         return
 
     def execute(self, options, args, tool):

Modified: trunk/Tools/Scripts/webkitpy/tool/commands/suggestnominations_unittest.py (170636 => 170637)


--- trunk/Tools/Scripts/webkitpy/tool/commands/suggestnominations_unittest.py	2014-07-01 12:07:08 UTC (rev 170636)
+++ trunk/Tools/Scripts/webkitpy/tool/commands/suggestnominations_unittest.py	2014-07-01 13:10:18 UTC (rev 170637)
@@ -56,13 +56,13 @@
 git-svn-id: http://svn.webkit.org/repository/webkit/trunk@95219 268f45cc-cd09-0410-ab3c-d52691b4dbfc
 """
 
-    def _make_options(self, **kwargs):
+    def _make_options(self, verbose=False, **kwargs):
         defaults = {
             'committer_minimum': 10,
             'max_commit_age': 9,
             'reviewer_minimum': 80,
             'show_commits': False,
-            'verbose': False,
+            'verbose': verbose,
         }
         options = MockOptions(**defaults)
         options.update(**kwargs)
@@ -101,3 +101,11 @@
         suggest_nominations._init_options(options=options)
         suggest_nominations._recent_commit_messages = lambda: [self.mock_non_committer_commit_message for _ in range(88)]
         self.assert_execute_outputs(suggest_nominations, [], expected_stdout=expected_stdout, options=options)
+
+    def test_with_verbose(self):
+        expected_stdout = "REVIEWER: Xianzhu Wang ([email protected]) has 88 reviewed patches\nCONTRIBUTOR: Xianzhu Wang ([email protected]) has 88 reviewed patches\n"
+        options = self._make_options(verbose=True)
+        suggest_nominations = SuggestNominations()
+        suggest_nominations._init_options(options=options)
+        suggest_nominations._recent_commit_messages = lambda: [self.mock_non_committer_commit_message for _ in range(88)]
+        self.assert_execute_outputs(suggest_nominations, [], expected_stdout=expected_stdout, options=options)

Modified: trunk/Tools/Scripts/webkitpy/tool/commands/upload.py (170636 => 170637)


--- trunk/Tools/Scripts/webkitpy/tool/commands/upload.py	2014-07-01 12:07:08 UTC (rev 170636)
+++ trunk/Tools/Scripts/webkitpy/tool/commands/upload.py	2014-07-01 13:10:18 UTC (rev 170637)
@@ -333,7 +333,7 @@
     def execute(self, options, args, tool):
         commit_ids = tool.scm().commit_ids_from_commitish_arguments(args)
         if len(commit_ids) > 10: # We could lower this limit, 10 is too many for one bug as-is.
-            _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))))
+            _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")))
             sys.exit(1)
 
         have_obsoleted_patches = set()

Modified: trunk/Tools/Scripts/webkitpy/tool/grammar.py (170636 => 170637)


--- trunk/Tools/Scripts/webkitpy/tool/grammar.py	2014-07-01 12:07:08 UTC (rev 170636)
+++ trunk/Tools/Scripts/webkitpy/tool/grammar.py	2014-07-01 13:10:18 UTC (rev 170637)
@@ -38,10 +38,13 @@
         return noun + "s"
 
 
-def pluralize(noun, count):
+def pluralize(count, noun, showCount=True):
     if count != 1:
         noun = plural(noun)
-    return "%d %s" % (count, noun)
+    if showCount:
+        return "%d %s" % (count, noun)
+    else:
+        return "%s" % noun
 
 
 def join_with_separators(list_of_strings, separator=', ', _only_two_separator_=" and ", last_separator=', and '):

Modified: trunk/Tools/Scripts/webkitpy/tool/grammar_unittest.py (170636 => 170637)


--- trunk/Tools/Scripts/webkitpy/tool/grammar_unittest.py	2014-07-01 12:07:08 UTC (rev 170636)
+++ trunk/Tools/Scripts/webkitpy/tool/grammar_unittest.py	2014-07-01 13:10:18 UTC (rev 170637)
@@ -29,6 +29,8 @@
 import unittest2 as unittest
 
 from webkitpy.tool.grammar import join_with_separators
+from webkitpy.tool.grammar import plural
+from webkitpy.tool.grammar import pluralize
 
 class GrammarTest(unittest.TestCase):
 
@@ -36,3 +38,15 @@
         self.assertEqual(join_with_separators(["one"]), "one")
         self.assertEqual(join_with_separators(["one", "two"]), "one and two")
         self.assertEqual(join_with_separators(["one", "two", "three"]), "one, two, and three")
+
+    def test_plural(self):
+        self.assertEqual(plural("patch"), "patches")
+        self.assertEqual(plural("test"), "tests")
+
+    def test_pluralize(self):
+        self.assertEqual(pluralize(1, "patch"), "1 patch")
+        self.assertEqual(pluralize(2, "patch"), "2 patches")
+        self.assertEqual(pluralize(1, "patch", True), "1 patch")
+        self.assertEqual(pluralize(2, "patch", True), "2 patches")
+        self.assertEqual(pluralize(1, "patch", False), "patch")
+        self.assertEqual(pluralize(2, "patch", False), "patches")

Modified: trunk/Tools/Scripts/webkitpy/tool/multicommandtool.py (170636 => 170637)


--- trunk/Tools/Scripts/webkitpy/tool/multicommandtool.py	2014-07-01 12:07:08 UTC (rev 170636)
+++ trunk/Tools/Scripts/webkitpy/tool/multicommandtool.py	2014-07-01 13:10:18 UTC (rev 170637)
@@ -113,8 +113,8 @@
     def check_arguments_and_execute(self, options, args, tool=None):
         if len(args) < len(self.required_arguments):
             _log.error("%s required, %s provided.  Provided: %s  Required: %s\nSee '%s help %s' for usage." % (
-                       pluralize("argument", len(self.required_arguments)),
-                       pluralize("argument", len(args)),
+                       pluralize(len(self.required_arguments), "argument"),
+                       pluralize(len(args), "argument"),
                        "'%s'" % " ".join(args),
                        " ".join(self.required_arguments),
                        tool.name(),

Modified: trunk/Tools/Scripts/webkitpy/tool/steps/obsoletepatches.py (170636 => 170637)


--- trunk/Tools/Scripts/webkitpy/tool/steps/obsoletepatches.py	2014-07-01 12:07:08 UTC (rev 170636)
+++ trunk/Tools/Scripts/webkitpy/tool/steps/obsoletepatches.py	2014-07-01 13:10:18 UTC (rev 170637)
@@ -49,6 +49,6 @@
         patches = self._tool.bugs.fetch_bug(bug_id).patches()
         if not patches:
             return
-        _log.info("Obsoleting %s on bug %s" % (pluralize("old patch", len(patches)), bug_id))
+        _log.info("Obsoleting %s on bug %s" % (pluralize(len(patches), "old patch"), bug_id))
         for patch in patches:
             self._tool.bugs.obsolete_attachment(patch.id())

Modified: trunk/Tools/Scripts/webkitpy/tool/steps/preparechangelogforrevert.py (170636 => 170637)


--- trunk/Tools/Scripts/webkitpy/tool/steps/preparechangelogforrevert.py	2014-07-01 12:07:08 UTC (rev 170636)
+++ trunk/Tools/Scripts/webkitpy/tool/steps/preparechangelogforrevert.py	2014-07-01 13:10:18 UTC (rev 170637)
@@ -28,22 +28,21 @@
 
 from webkitpy.common.checkout.changelog import ChangeLog
 from webkitpy.common.config import urls
-from webkitpy.tool.grammar import join_with_separators
+from webkitpy.tool import grammar
 from webkitpy.tool.steps.abstractstep import AbstractStep
 
 
 class PrepareChangeLogForRevert(AbstractStep):
     @classmethod
     def _message_for_revert(cls, revision_list, reason, description_list, reverted_bug_url_list, rollout_bug_url=None):
-        message = "Unreviewed, rolling out %s.\n" % join_with_separators(['r' + str(revision) for revision in revision_list])
+        message = "Unreviewed, rolling out %s.\n" % grammar.join_with_separators(['r' + str(revision) for revision in revision_list])
         if rollout_bug_url:
             message += "%s\n" % rollout_bug_url
         message += "\n"
         if reason:
             message += "%s\n" % reason
         message += "\n"
-        pluralSuffix = 's' if len(revision_list) > 1 else ''
-        message += "Reverted changeset%s:\n\n" % pluralSuffix
+        message += "Reverted %s:\n\n" % grammar.pluralize(len(revision_list), "changeset", showCount=False)
         for index in range(len(revision_list)):
             if description_list[index]:
                 message += "\"%s\"\n" % description_list[index]
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to