"""
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.
"""
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.
from itertools import izip_longest
+from hashlib import sha1
+
class depends(object):
"""
Dependency decorator for a test.
Takes a revision for an argument.
"""
oldrev = None
+ oldbranch = None
dirty = False
try:
if revision:
oldrev = self.scm.current_rev()
+ oldbranch = self.scm.current_branch()
if dirty:
self.scm.stash()
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
finally:
if oldrev:
self.scm.checkout(oldrev)
+ if oldbranch:
+ self.scm.checkout(oldbranch)
if dirty:
self.scm.unstash()
# 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"])
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
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: