diff options
Diffstat (limited to 'tests/component/__init__.py')
-rw-r--r-- | tests/component/__init__.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/component/__init__.py b/tests/component/__init__.py index b6ba796f..58508030 100644 --- a/tests/component/__init__.py +++ b/tests/component/__init__.py @@ -20,6 +20,7 @@ Module for testing individual command line tools of the git-buildpackage suite """ +import hashlib import os import shutil import tempfile @@ -205,3 +206,32 @@ class ComponentTestBase(unittest.TestCase, GbpLogTester): for (h, s) in rem: n = repo.rev_parse(h) ok_(n == s, "Head '%s' points to %s' instead of '%s'" % (h, n, s)) + + @staticmethod + def hash_file(filename): + h = hashlib.md5() + with open(filename, 'rb') as f: + buf = f.read() + h.update(buf) + return h.hexdigest() + + @staticmethod + def check_hook_vars(name, expected): + """ + Check that a hook had the given vars in + it's environment. + This assumes the hook was set too + printenv > hookname.out + """ + with open('%s.out' % name) as f: + parsed = dict([line[:-1].split('=', 1) for line in f.readlines() if line.startswith("GBP_")]) + + for var in expected: + if len(var) == 2: + k, v = var + else: + k, v = var, None + ok_(k in parsed, "%s not found in %s" % (k, parsed)) + if v is not None: + ok_(v == parsed[k], + "Got %s not expected value %s for %s" % (parsed[k], v, k)) |