Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1056)

Unified Diff: testing_support/git_test_utils.py

Issue 184253003: Add git-reup and friends (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@freeze_thaw
Patch Set: one more argparse Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: testing_support/git_test_utils.py
diff --git a/testing_support/git_test_utils.py b/testing_support/git_test_utils.py
index 5becad94ba58e0ece7bbcbdaa812fee034d1d0d9..33358f3312954c6a1555efb9cc7918b44f2abe38 100644
--- a/testing_support/git_test_utils.py
+++ b/testing_support/git_test_utils.py
@@ -10,9 +10,12 @@ import hashlib
import os
import shutil
import subprocess
+import sys
import tempfile
import unittest
+from cStringIO import StringIO
+
def git_hash_data(data, typ='blob'):
"""Calculate the git-style SHA1 for some data.
@@ -258,7 +261,7 @@ class GitRepo(object):
self._add_schema_commit(commit, schema.data_for(commit.name))
self.last_commit = self[commit.name]
if schema.master:
- self.git('update-ref', 'master', self[schema.master])
+ self.git('update-ref', 'refs/heads/master', self[schema.master])
def __getitem__(self, commit_name):
"""Gets the hash of a commit by its schema name.
@@ -354,11 +357,29 @@ class GitRepo(object):
finally:
os.chdir(curdir)
+ def capture_stdio(self, fn, *args, **kwargs):
+ """Run a python function with the given args and kwargs with the cwd set to
+ the git repo.
+
+ Returns the (stdout, stderr) of whatever ran, instead of the what |fn|
+ returned.
+ """
+ stdout = sys.stdout
+ stderr = sys.stderr
+ try:
+ sys.stdout = StringIO()
+ sys.stderr = StringIO()
+ self.run(fn, *args, **kwargs)
+ return sys.stdout.getvalue(), sys.stderr.getvalue()
+ finally:
+ sys.stdout = stdout
+ sys.stderr = stderr
+
class GitRepoSchemaTestBase(unittest.TestCase):
"""A TestCase with a built-in GitRepoSchema.
- Expects a class variable REPO to be a GitRepoSchema string in the form
+ Expects a class variable REPO_SCHEMA to be a GitRepoSchema string in the form
described by that class.
You may also set class variables in the form COMMIT_%(commit_name)s, which
@@ -367,7 +388,7 @@ class GitRepoSchemaTestBase(unittest.TestCase):
You probably will end up using either GitRepoReadOnlyTestBase or
GitRepoReadWriteTestBase for real tests.
"""
- REPO = None
+ REPO_SCHEMA = None
@classmethod
def getRepoContent(cls, commit):
@@ -376,8 +397,8 @@ class GitRepoSchemaTestBase(unittest.TestCase):
@classmethod
def setUpClass(cls):
super(GitRepoSchemaTestBase, cls).setUpClass()
- assert cls.REPO is not None
- cls.r_schema = GitRepoSchema(cls.REPO, cls.getRepoContent)
+ assert cls.REPO_SCHEMA is not None
+ cls.r_schema = GitRepoSchema(cls.REPO_SCHEMA, cls.getRepoContent)
class GitRepoReadOnlyTestBase(GitRepoSchemaTestBase):
@@ -387,12 +408,12 @@ class GitRepoReadOnlyTestBase(GitRepoSchemaTestBase):
This GitRepo will appear as self.repo, and will be deleted and recreated once
for the duration of all the tests in the subclass.
"""
- REPO = None
+ REPO_SCHEMA = None
@classmethod
def setUpClass(cls):
super(GitRepoReadOnlyTestBase, cls).setUpClass()
- assert cls.REPO is not None
+ assert cls.REPO_SCHEMA is not None
cls.repo = cls.r_schema.reify()
def setUp(self):
@@ -411,7 +432,7 @@ class GitRepoReadWriteTestBase(GitRepoSchemaTestBase):
This GitRepo will appear as self.repo, and will be deleted and recreated for
each test function in the subclass.
"""
- REPO = None
+ REPO_SCHEMA = None
def setUp(self):
super(GitRepoReadWriteTestBase, self).setUp()

Powered by Google App Engine
This is Rietveld 408576698