Mock out date call in push-to-trunk script for testability.

TEST=python -m unittest test_scripts.ScriptTest.testPrepareChangeLog
R=ulan@chromium.org

Review URL: https://codereview.chromium.org/98173003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18232 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent a06c8435
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import datetime
import os import os
import re import re
import subprocess import subprocess
...@@ -202,9 +203,12 @@ class SideEffectHandler(object): ...@@ -202,9 +203,12 @@ class SideEffectHandler(object):
finally: finally:
url_fh.close() url_fh.close()
def Sleep(seconds): def Sleep(self, seconds):
time.sleep(seconds) time.sleep(seconds)
def GetDate(self):
return datetime.date.today().strftime("%Y-%m-%d")
DEFAULT_SIDE_EFFECT_HANDLER = SideEffectHandler() DEFAULT_SIDE_EFFECT_HANDLER = SideEffectHandler()
...@@ -286,6 +290,9 @@ class Step(object): ...@@ -286,6 +290,9 @@ class Step(object):
cmd = lambda: self._side_effect_handler.ReadURL(url) cmd = lambda: self._side_effect_handler.ReadURL(url)
return self.Retry(cmd, retry_on, wait_plan) return self.Retry(cmd, retry_on, wait_plan)
def GetDate(self):
return self._side_effect_handler.GetDate()
def Die(self, msg=""): def Die(self, msg=""):
if msg != "": if msg != "":
print "Error: %s" % msg print "Error: %s" % msg
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import datetime
import optparse import optparse
import sys import sys
import tempfile import tempfile
...@@ -115,7 +114,7 @@ class PrepareChangeLog(Step): ...@@ -115,7 +114,7 @@ class PrepareChangeLog(Step):
# These version numbers are used again later for the trunk commit. # These version numbers are used again later for the trunk commit.
self.ReadAndPersistVersion() self.ReadAndPersistVersion()
date = datetime.date.today().strftime("%Y-%m-%d") date = self.GetDate()
self.Persist("date", date) self.Persist("date", date)
output = "%s: Version %s.%s.%s\n\n" % (date, output = "%s: Version %s.%s.%s\n\n" % (date,
self._state["major"], self._state["major"],
......
...@@ -288,6 +288,9 @@ class ScriptTest(unittest.TestCase): ...@@ -288,6 +288,9 @@ class ScriptTest(unittest.TestCase):
def Sleep(self, seconds): def Sleep(self, seconds):
pass pass
def GetDate(self):
return "1999-07-31"
def ExpectGit(self, *args): def ExpectGit(self, *args):
"""Convenience wrapper.""" """Convenience wrapper."""
self._git_mock.Expect(*args) self._git_mock.Expect(*args)
...@@ -444,35 +447,33 @@ class ScriptTest(unittest.TestCase): ...@@ -444,35 +447,33 @@ class ScriptTest(unittest.TestCase):
actual_cl = FileToText(TEST_CONFIG[CHANGELOG_ENTRY_FILE]) actual_cl = FileToText(TEST_CONFIG[CHANGELOG_ENTRY_FILE])
# TODO(machenbach): Mock out call to date() in order to make a fixed expected_cl = """1999-07-31: Version 3.22.5
# comparison here instead of a regexp match.
expected_cl = """\\d+\\-\\d+\\-\\d+: Version 3\\.22\\.5
Title text 1. 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 # The change log above is auto-generated. Please review if all relevant
# commit messages from the list below are included\\. # commit messages from the list below are included.
# All lines starting with # will be stripped\\. # All lines starting with # will be stripped.
# #
# Title text 1. # Title text 1.
# \\(author1@chromium\\.org\\) # (author1@chromium.org)
# #
# Title text 2 \\(Chromium issue 123\\). # Title text 2 (Chromium issue 123).
# \\(author2@chromium\\.org\\) # (author2@chromium.org)
# #
# Title text 3 \\(Chromium issue 321\\). # Title text 3 (Chromium issue 321).
# \\(author3@chromium\\.org\\) # (author3@chromium.org)
# #
# Title text 4 \\(Chromium issue 456\\). # Title text 4 (Chromium issue 456).
# \\(author4@chromium\\.org\\) # (author4@chromium.org)
# #
#""" #"""
self.assertTrue(re.match(expected_cl, actual_cl)) self.assertEquals(expected_cl, actual_cl)
self.assertEquals("3", self.MakeStep().Restore("major")) self.assertEquals("3", self.MakeStep().Restore("major"))
self.assertEquals("22", self.MakeStep().Restore("minor")) self.assertEquals("22", self.MakeStep().Restore("minor"))
self.assertEquals("5", self.MakeStep().Restore("build")) self.assertEquals("5", self.MakeStep().Restore("build"))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment