From: Tony Young Date: Fri, 21 Jan 2011 21:06:28 +0000 (-0800) Subject: Two improvements to regression test script X-Git-Url: http://www.zmx.ovh/git.videolan.org/?a=commitdiff_plain;h=f04f004db516077b119dde8b9feef08c29451239;p=x264.git Two improvements to regression test script Use SHA-1 hashes for temporary file names to avoid exceeding OS filename length limits. Correctly return to the original branch after testing if you were on a branch. --- diff --git a/tools/digress/scm/git.py b/tools/digress/scm/git.py index 01b508c9..3e1ed4a3 100644 --- a/tools/digress/scm/git.py +++ b/tools/digress/scm/git.py @@ -3,8 +3,12 @@ Git SCM backend for Digress. """ from subprocess import Popen, PIPE, STDOUT +import re + from digress.errors import SCMError +GIT_BRANCH_EXPR = re.compile("[*] (.*)") + def checkout(revision): """ Checkout a revision from git. @@ -38,6 +42,22 @@ def current_rev(): """ return rev_parse("HEAD") +def current_branch(): + """ + Get the current branch. + """ + proc = Popen([ + "git", + "branch", + "--no-color" + ], stdout=PIPE, stderr=STDOUT) + + output = proc.communicate()[0].strip() + if proc.returncode != 0: + raise SCMError("branch error: %s" % output) + branch_name = GIT_BRANCH_EXPR.findall(output)[0] + return branch_name != "(no branch)" and branch_name or None + def revisions(rev_a, rev_b): """ Get a list of revisions from one to another. diff --git a/tools/digress/testing.py b/tools/digress/testing.py index bc45097b..f2312704 100644 --- a/tools/digress/testing.py +++ b/tools/digress/testing.py @@ -22,6 +22,8 @@ from functools import wraps from itertools import izip_longest +from hashlib import sha1 + class depends(object): """ Dependency decorator for a test. @@ -142,6 +144,7 @@ class Fixture(object): Takes a revision for an argument. """ oldrev = None + oldbranch = None dirty = False try: @@ -152,6 +155,7 @@ class Fixture(object): if revision: oldrev = self.scm.current_rev() + oldbranch = self.scm.current_branch() if dirty: self.scm.stash() @@ -164,8 +168,8 @@ class Fixture(object): if os.path.isdir(self.datastore): if self.flush_before: self.flush(rev) - - os.makedirs(self.datastore) + else: + os.makedirs(self.datastore) else: rev = "(dirty working tree)" self.datastore = None @@ -201,6 +205,8 @@ class Fixture(object): finally: if oldrev: self.scm.checkout(oldrev) + if oldbranch: + self.scm.checkout(oldbranch) if dirty: self.scm.unstash() @@ -488,7 +494,10 @@ class Case(object): # XXX: this smells funny raise IOError - with open(os.path.join(self.datastore, "%s.json" % test_name), "r") as f: + with open(os.path.join( + self.datastore, + "%s.json" % sha1(test_name).hexdigest() + ), "r") as f: result = json.load(f) value = str(result["value"]) @@ -539,7 +548,10 @@ class Case(object): result = { "status" : status, "value" : value, "time" : run_time } if self.datastore: - with open(os.path.join(self.datastore, "%s.json" % test_name), "w") as f: + with open(os.path.join( + self.datastore, + "%s.json" % sha1(test_name).hexdigest() + ), "w") as f: json.dump(result, f) results[test_name] = result @@ -549,7 +561,10 @@ class Case(object): print "Running case %s..." % self.__class__.__name__ if self.fixture.datastore: - self.datastore = os.path.join(self.fixture.datastore, self.__class__.__name__) + self.datastore = os.path.join( + self.fixture.datastore, + sha1(self.__class__.__name__).hexdigest() + ) if not os.path.isdir(self.datastore): os.makedirs(self.datastore) else: