Make auto-roll testable.

Refactor the mock code for easier reuse. Mock out web requests.

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

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17987 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 3c95790f
......@@ -29,7 +29,6 @@
import optparse
import re
import sys
import urllib2
from common_includes import *
......@@ -66,15 +65,7 @@ class FetchLKGR(Step):
def RunStep(self):
lkgr_url = "https://v8-status.appspot.com/lkgr"
try:
# pylint: disable=E1121
url_fh = urllib2.urlopen(lkgr_url, None, 60)
except urllib2.URLError:
self.Die("URLException while fetching %s" % lkgr_url)
try:
self.Persist("lkgr", url_fh.read())
finally:
url_fh.close()
self.Persist("lkgr", self.ReadURL(lkgr_url))
class PushToTrunk(Step):
......@@ -94,6 +85,18 @@ class PushToTrunk(Step):
% (latest, lkgr))
def RunAutoRoll(config,
options,
side_effect_handler=DEFAULT_SIDE_EFFECT_HANDLER):
step_classes = [
Preparation,
FetchLatestRevision,
FetchLKGR,
PushToTrunk,
]
RunScript(step_classes, config, options, side_effect_handler)
def BuildOptions():
result = optparse.OptionParser()
result.add_option("-s", "--step", dest="s",
......@@ -105,15 +108,7 @@ def BuildOptions():
def Main():
parser = BuildOptions()
(options, args) = parser.parse_args()
step_classes = [
Preparation,
FetchLatestRevision,
FetchLKGR,
PushToTrunk,
]
RunScript(step_classes, CONFIG, options, DEFAULT_SIDE_EFFECT_HANDLER)
RunAutoRoll(CONFIG, options)
if __name__ == "__main__":
sys.exit(Main())
......@@ -31,6 +31,7 @@ import re
import subprocess
import sys
import textwrap
import urllib2
PERSISTFILE_BASENAME = "PERSISTFILE_BASENAME"
TEMP_BRANCH = "TEMP_BRANCH"
......@@ -192,6 +193,14 @@ class SideEffectHandler(object):
def ReadLine(self):
return sys.stdin.readline().strip()
def ReadURL(self, url):
# pylint: disable=E1121
url_fh = urllib2.urlopen(url, None, 60)
try:
return url_fh.read()
finally:
url_fh.close()
DEFAULT_SIDE_EFFECT_HANDLER = SideEffectHandler()
......@@ -251,6 +260,9 @@ class Step(object):
return self._side_effect_handler.Command(os.environ["EDITOR"], args,
pipe=False)
def ReadURL(self, url):
return self._side_effect_handler.ReadURL(url)
def Die(self, msg=""):
if msg != "":
print "Error: %s" % msg
......
This diff is collapsed.
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