[pypy-svn] buildbot default: make the hg calls global functions
RonnyPfannschmidt
commits-noreply at bitbucket.org
Wed Apr 20 15:53:15 CEST 2011
Author: Ronny Pfannschmidt <Ronny.Pfannschmidt at gmx.de>
Branch:
Changeset: r452:fc8c248f4680
Date: 2011-04-18 18:39 +0200
http://bitbucket.org/pypy/buildbot/changeset/fc8c248f4680/
Log: make the hg calls global functions
diff --git a/bitbucket_hook/hook.py b/bitbucket_hook/hook.py
--- a/bitbucket_hook/hook.py
+++ b/bitbucket_hook/hook.py
@@ -29,6 +29,21 @@
hgexe = str(py.path.local.sysfind('hg'))
+def _hgexe(argv):
+ proc = Popen([hgexe] + list(argv), stdout=PIPE, stderr=PIPE)
+ stdout, stderr = proc.communicate()
+ ret = proc.wait()
+ return stdout, stderr, ret
+
+def hg(self, *argv):
+ argv = map(str, argv)
+ stdout, stderr, ret = _hgexe(argv)
+ if ret != 0:
+ print >> sys.stderr, 'error: hg', ' '.join(argv)
+ print >> sys.stderr, stderr
+ raise Exception('error when executing hg')
+ return unicode(stdout, encoding='utf-8', errors='replace')
+
TEMPLATE = u"""\
Author: {author}
Branch: {branches}
@@ -91,21 +106,7 @@
self.seen_nodes.add(key)
yield commit
- def _hgexe(self, argv):
- proc = self.Popen([hgexe] + list(argv), stdout=self.PIPE,
- stderr=self.PIPE)
- stdout, stderr = proc.communicate()
- ret = proc.wait()
- return stdout, stderr, ret
- def hg(self, *argv):
- argv = map(str, argv)
- stdout, stderr, ret = self._hgexe(argv)
- if ret != 0:
- print >> sys.stderr, 'error: hg', ' '.join(argv)
- print >> sys.stderr, stderr
- raise Exception('error when executing hg')
- return unicode(stdout, encoding='utf-8', errors='replace')
SMTP = smtplib.SMTP
def send(self, from_, to, subject, body, test=False):
@@ -145,7 +146,7 @@
if not self.check_for_local_repo(self.local_repo):
print >> sys.stderr, 'Ignoring unknown repo', path
return
- self.hg('pull', '-R', self.local_repo)
+ hg('pull', '-R', self.local_repo)
self.handle_irc_message(test)
self.handle_diff_email(test)
@@ -201,7 +202,7 @@
url = self.remote_repo + 'changeset/' + commit['node'] + '/'
template = TEMPLATE % {'url': url}
subject = '%s %s: %s' % (reponame, commit['branch'], line0)
- body = self.hg('-R', self.local_repo, 'log', '-r', hgid,
+ body = hg('-R', self.local_repo, 'log', '-r', hgid,
'--template', template)
diff = self.get_diff(hgid, commit['files'])
body = body+diff
@@ -213,7 +214,7 @@
files = [item['file'] for item in files]
lines = []
for filename in files:
- out = self.hg('-R', self.local_repo, 'diff', '--git', '-c', hgid,
+ out = hg('-R', self.local_repo, 'diff', '--git', '-c', hgid,
self.local_repo.join(filename))
match = binary.search(out)
if match:
diff --git a/bitbucket_hook/test/test_hook.py b/bitbucket_hook/test/test_hook.py
--- a/bitbucket_hook/test/test_hook.py
+++ b/bitbucket_hook/test/test_hook.py
@@ -1,13 +1,13 @@
# -*- encoding: utf-8 -*-
-from bitbucket_hook.hook import BitbucketHookHandler, getpaths
+from bitbucket_hook import hook
-class BaseHandler(BitbucketHookHandler):
+class BaseHandler(hook.BitbucketHookHandler):
USE_COLOR_CODES = False
def __init__(self):
- BitbucketHookHandler.__init__(self)
+ hook.BitbucketHookHandler.__init__(self)
self.mails = []
self.messages = []
@@ -18,23 +18,20 @@
self.messages.append(message)
-def test_non_ascii_encoding_guess_utf8():
- class MyHandler(BaseHandler):
- def _hgexe(self, argv):
- return u'späm'.encode('utf-8'), '', 0
- #
- handler = MyHandler()
- stdout = handler.hg('foobar')
+def test_non_ascii_encoding_guess_utf8(monkeypatch):
+ def _hgexe(argv):
+ return u'späm'.encode('utf-8'), '', 0
+ monkeypatch.setattr(hook, '_hgexe', _hgexe)
+ stdout = hook.hg('foobar')
assert type(stdout) is unicode
assert stdout == u'späm'
-def test_non_ascii_encoding_invalid_utf8():
- class MyHandler(BaseHandler):
- def _hgexe(self, argv):
- return '\xe4aa', '', 0 # invalid utf-8 string
+def test_non_ascii_encoding_invalid_utf8(monkeypatch):
+ def _hgexe(argv):
+ return '\xe4aa', '', 0 # invalid utf-8 string
#
- handler = MyHandler()
- stdout = handler.hg('foobar')
+ monkeypatch.setattr(hook, '_hgexe', _hgexe)
+ stdout = hook.hg('foobar')
assert type(stdout) is unicode
assert stdout == u'\ufffdaa'
@@ -113,7 +110,7 @@
]
for f, wanted in files_expected:
- assert getpaths(f) == wanted
+ assert hook.getpaths(f) == wanted
# (input, expected output) for listfiles=True
files_expected = [([], nothing),
@@ -140,7 +137,7 @@
]
for f, wanted in files_expected:
- assert getpaths(f, listfiles=True) == wanted
+ assert hook.getpaths(f, listfiles=True) == wanted
@@ -227,8 +224,8 @@
def wait(*args, **kwargs): return 0
sendmail = noop
-def test_handle():
- handler = BitbucketHookHandler()
+def test_handle(monkeypatch):
+ handler = hook.BitbucketHookHandler()
commits, _ = irc_cases()
test_payload = {u'repository': {u'absolute_url': '',
u'name': u'test',
@@ -239,7 +236,7 @@
'commits': commits['commits']}
handler.call_subprocess = noop
- handler.Popen = mock
+ monkeypatch.setattr(hook, 'Popen', mock)
handler.SMTP = mock
handler.handle(test_payload)
@@ -250,13 +247,14 @@
handler.handle(test_payload, test=True)
-def test_ignore_duplicate_commits():
+def test_ignore_duplicate_commits(monkeypatch):
+ def hg(self, *args):
+ return '<hg %s>' % ' '.join(map(str, args))
+ monkeypatch.setattr(hook, 'hg', hg)
class MyHandler(BaseHandler):
seen_nodes = set() # make sure we do not depend on what the other
# tests did
- def hg(self, *args):
- return '<hg %s>' % ' '.join(map(str, args))
def check_for_local_repo(self, local_repo):
return True
More information about the Pypy-commit
mailing list