Revision: 18232
Author:   [email protected]
Date:     Tue Dec  3 12:38:25 2013 UTC
Log:      Mock out date call in push-to-trunk script for testability.

TEST=python -m unittest test_scripts.ScriptTest.testPrepareChangeLog
[email protected]

Review URL: https://codereview.chromium.org/98173003
http://code.google.com/p/v8/source/detail?r=18232

Modified:
 /branches/bleeding_edge/tools/push-to-trunk/common_includes.py
 /branches/bleeding_edge/tools/push-to-trunk/push_to_trunk.py
 /branches/bleeding_edge/tools/push-to-trunk/test_scripts.py

=======================================
--- /branches/bleeding_edge/tools/push-to-trunk/common_includes.py Tue Dec 3 09:13:51 2013 UTC +++ /branches/bleeding_edge/tools/push-to-trunk/common_includes.py Tue Dec 3 12:38:25 2013 UTC
@@ -26,6 +26,7 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+import datetime
 import os
 import re
 import subprocess
@@ -202,9 +203,12 @@
     finally:
       url_fh.close()

-  def Sleep(seconds):
+  def Sleep(self, seconds):
     time.sleep(seconds)

+  def GetDate(self):
+    return datetime.date.today().strftime("%Y-%m-%d")
+
 DEFAULT_SIDE_EFFECT_HANDLER = SideEffectHandler()


@@ -286,6 +290,9 @@
     cmd = lambda: self._side_effect_handler.ReadURL(url)
     return self.Retry(cmd, retry_on, wait_plan)

+  def GetDate(self):
+    return self._side_effect_handler.GetDate()
+
   def Die(self, msg=""):
     if msg != "":
       print "Error: %s" % msg
=======================================
--- /branches/bleeding_edge/tools/push-to-trunk/push_to_trunk.py Mon Dec 2 09:53:28 2013 UTC +++ /branches/bleeding_edge/tools/push-to-trunk/push_to_trunk.py Tue Dec 3 12:38:25 2013 UTC
@@ -26,7 +26,6 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

-import datetime
 import optparse
 import sys
 import tempfile
@@ -115,7 +114,7 @@
     # These version numbers are used again later for the trunk commit.
     self.ReadAndPersistVersion()

-    date = datetime.date.today().strftime("%Y-%m-%d")
+    date = self.GetDate()
     self.Persist("date", date)
     output = "%s: Version %s.%s.%s\n\n" % (date,
                                            self._state["major"],
=======================================
--- /branches/bleeding_edge/tools/push-to-trunk/test_scripts.py Tue Dec 3 09:13:51 2013 UTC +++ /branches/bleeding_edge/tools/push-to-trunk/test_scripts.py Tue Dec 3 12:38:25 2013 UTC
@@ -288,6 +288,9 @@
   def Sleep(self, seconds):
     pass

+  def GetDate(self):
+    return "1999-07-31"
+
   def ExpectGit(self, *args):
     """Convenience wrapper."""
     self._git_mock.Expect(*args)
@@ -444,35 +447,33 @@

     actual_cl = FileToText(TEST_CONFIG[CHANGELOG_ENTRY_FILE])

-    # TODO(machenbach): Mock out call to date() in order to make a fixed
-    # comparison here instead of a regexp match.
-    expected_cl = """\\d+\\-\\d+\\-\\d+: Version 3\\.22\\.5
+    expected_cl = """1999-07-31: Version 3.22.5

         Title text 1.

-        Title text 3 \\(Chromium issue 321\\).
+        Title text 3 (Chromium issue 321).

-        Performance and stability improvements on all platforms\\.
+        Performance and stability improvements on all platforms.
 #
-# The change log above is auto-generated\\. Please review if all relevant
-# commit messages from the list below are included\\.
-# All lines starting with # will be stripped\\.
+# The change log above is auto-generated. Please review if all relevant
+# commit messages from the list below are included.
+# All lines starting with # will be stripped.
 #
 #       Title text 1.
-#       \\(author1@chromium\\.org\\)
+#       ([email protected])
 #
-#       Title text 2 \\(Chromium issue 123\\).
-#       \\(author2@chromium\\.org\\)
+#       Title text 2 (Chromium issue 123).
+#       ([email protected])
 #
-#       Title text 3 \\(Chromium issue 321\\).
-#       \\(author3@chromium\\.org\\)
+#       Title text 3 (Chromium issue 321).
+#       ([email protected])
 #
-#       Title text 4 \\(Chromium issue 456\\).
-#       \\(author4@chromium\\.org\\)
+#       Title text 4 (Chromium issue 456).
+#       ([email protected])
 #
 #"""

-    self.assertTrue(re.match(expected_cl, actual_cl))
+    self.assertEquals(expected_cl, actual_cl)
     self.assertEquals("3", self.MakeStep().Restore("major"))
     self.assertEquals("22", self.MakeStep().Restore("minor"))
     self.assertEquals("5", self.MakeStep().Restore("build"))

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to