Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_push_nothing_found(mocker):
retry_get = mocker.patch("mozregression.json_pushes.retry_get")
response = Mock(json=Mock(return_value={}))
retry_get.return_value = response
jpushes = JsonPushes()
with pytest.raises(MozRegressionError):
jpushes.push("invalid_changeset")
def test_pushes_within_changes_using_dates(mocker):
p1 = {"changesets": ["abc"], "date": 12345}
p2 = {"changesets": ["def"], "date": 67891}
pushes = {"1": p1, "2": p2}
retry_get = mocker.patch("mozregression.json_pushes.retry_get")
retry_get.return_value = Mock(json=Mock(return_value=pushes))
jpushes = JsonPushes(branch="m-i")
pushes = jpushes.pushes_within_changes(date(2015, 1, 1), date(2015, 2, 2))
assert pushes[0].push_id == "1"
assert pushes[1].push_id == "2"
retry_get.assert_called_once_with(
"https://hg.mozilla.org/integration/mozilla-inbound/json-pushes?"
"enddate=2015-02-03&startdate=2015-01-01"
def test_get_integration_range(mocker):
fetch_config = create_config("firefox", "linux", 64, "x86_64")
jpush_class = mocker.patch("mozregression.fetch_build_info.JsonPushes")
pushes = [create_push("b", 1), create_push("d", 2), create_push("f", 3)]
jpush = mocker.Mock(pushes_within_changes=mocker.Mock(return_value=pushes), spec=JsonPushes)
jpush_class.return_value = jpush
b_range = build_range.get_integration_range(fetch_config, "a", "e")
jpush_class.assert_called_once_with(branch="mozilla-central")
jpush.pushes_within_changes.assert_called_once_with("a", "e")
assert isinstance(b_range, build_range.BuildRange)
assert len(b_range) == 3
b_range.build_info_fetcher.find_build_info = lambda v: v
assert b_range[0] == pushes[0]
assert b_range[1] == pushes[1]
assert b_range[2] == pushes[2]
b_range.future_build_infos[0].date_or_changeset() == "b"
def test_pushes_within_changes(mocker):
push_first = {"1": {"changesets": ["a"]}}
other_pushes = {"2": {"changesets": ["b"]}, "3": {"changesets": ["c"]}}
retry_get = mocker.patch("mozregression.json_pushes.retry_get")
response = Mock(json=Mock(side_effect=[push_first, other_pushes]))
retry_get.return_value = response
jpushes = JsonPushes()
pushes = jpushes.pushes_within_changes("fromchset", "tochset")
assert pushes[0].push_id == "1"
assert pushes[0].changeset == "a"
assert pushes[1].push_id == "2"
assert pushes[1].changeset == "b"
assert pushes[2].push_id == "3"
assert pushes[2].changeset == "c"
retry_get.assert_has_calls(
[
call("https://hg.mozilla.org/mozilla-central/json-pushes" "?changeset=fromchset"),
call(
"https://hg.mozilla.org/mozilla-central/json-pushes"
"?fromchange=fromchset&tochange=tochset"
def test_push(mocker):
pushlog = {"1": {"changesets": ["a", "b", "c"], "date": 123456}}
retry_get = mocker.patch("mozregression.json_pushes.retry_get")
response = Mock(json=Mock(return_value=pushlog))
retry_get.return_value = response
jpushes = JsonPushes()
push = jpushes.push("validchangeset")
assert isinstance(push, Push)
assert push.push_id == "1"
assert push.changeset == "c"
assert push.changesets[0] == "a"
assert push.timestamp == 123456
assert push.utc_date == datetime(1970, 1, 2, 10, 17, 36)
assert str(push) == "c"
retry_get.assert_called_once_with(
"https://hg.mozilla.org/mozilla-central/json-pushes" "?changeset=validchangeset"
)
def _choose_integration_branch(self, changeset):
"""
Tries to determine which integration branch the given changeset
originated from by checking the date the changeset first showed up
in each repo. The repo with the earliest date is chosen.
"""
landings = {}
for k in ("autoland", "mozilla-inbound"):
jp = JsonPushes(k)
try:
push = jp.push(changeset, full="1")
landings[k] = push.timestamp
except EmptyPushlogError:
LOG.debug("Didn't find %s in %s" % (changeset, k))
repo = min(landings, key=landings.get)
LOG.debug("Repo '%s' seems to have the earliest push" % repo)
return repo
def __init__(self, fetch_config):
InfoFetcher.__init__(self, fetch_config)
self.jpushes = JsonPushes(branch=fetch_config.integration_branch)
# one good, one bad.
result = handler.handle_merge()
if result:
branch, good_rev, bad_rev = result
self.fetch_config.set_repo(branch)
return self._bisect_integration(good_rev, bad_rev, expand=DEFAULT_EXPAND)
else:
# This code is broken, it prints out the message even when
# there are multiple bug numbers or commits in the range.
# Somebody should fix it before re-enabling it.
return 0
# print a bug if:
# (1) there really is only one bad push (and we're not
# just missing the builds for some intermediate builds)
# (2) there is only one bug number in that push
jp = JsonPushes(handler.build_range[1].repo_name)
num_pushes = len(
jp.pushes_within_changes(
handler.build_range[0].changeset, handler.build_range[1].changeset,
)
)
if num_pushes == 2:
bugids = find_bugids_in_push(
handler.build_range[1].repo_name, handler.build_range[1].changeset,
)
if len(bugids) == 1:
word = "fix" if handler.find_fix else "regression"
LOG.info(
"Looks like the following bug has the "
" changes which introduced the"
" {}:\n{}".format(word, bug_url(bugids[0]))
)
oldest = push.changesets[0]["node"]
# exclude the merge commit
youngest = push.changesets[-2]["node"]
LOG.info("************* Switching to %s" % branch)
# we can't use directly the oldest changeset because we
# don't know yet if it is good.
#
# PUSH1 PUSH2
# [1 2] [3 4 5 6 7]
# G MERGE B
#
# so first grab the previous push to get the last known good
# changeset. This needs to be done on the right branch.
try:
jp2 = JsonPushes(branch)
raw = [int(p.push_id) for p in jp2.pushes_within_changes(oldest, youngest)]
data = jp2.pushes(startID=str(min(raw) - 2), endID=str(max(raw)),)
older = data[0].changeset
youngest = data[-1].changeset
# we are ready to bisect further
gr, br = self._reverse_if_find_fix(older, youngest)
result = (branch, gr, br)
except MozRegressionError:
LOG.debug("Got exception", exc_info=True)
raise MozRegressionError(
"Unable to exploit the merge commit. Origin branch is {}, and"
" the commit message for {} was:\n{}".format(
most_recent_push.repo_name, most_recent_push.short_changeset, msg
)