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

Unified Diff: testing_support/git/unittest_helpers.py

Issue 483553002: Make git unittest_helpers only use setUp/tearDown. (Closed) Base URL: https://chromium.googlesource.com/infra/testing/testing_support.git@master
Patch Set: Fix docs and bump version Created 6 years, 4 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
« no previous file with comments | « testing_support/__init__.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: testing_support/git/unittest_helpers.py
diff --git a/testing_support/git/unittest_helpers.py b/testing_support/git/unittest_helpers.py
index 94a720efa1e5537aafc998b8b94970d1c97fe261..8e091c52dec01967f1b0aa7324d421b9e7ad625e 100644
--- a/testing_support/git/unittest_helpers.py
+++ b/testing_support/git/unittest_helpers.py
@@ -8,17 +8,19 @@ from testing_support.git.repo import GitRepo
from testing_support.git.schema import GitRepoSchema
-class GitRepoSchemaTestBase(auto_stub.TestCase):
- """A TestCase with a built-in GitRepoSchema.
+class GitRepoTestBase(auto_stub.TestCase):
+ """A TestCase with a built-in GitRepoSchema and a GitRepo based on that
+ schema.
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
- provide the content for the given commit_name commits.
+ provide the content for the given commit_name commits (this behavior can be
+ overridden by overriding getRepoContent()).
- You probably will end up using either GitRepoReadOnlyTestBase or
- GitRepoReadWriteTestBase for real tests.
+ This GitRepo will appear as self.repo, and will be deleted and recreated for
+ each test method in the subclass.
"""
REPO_SCHEMA = None
@@ -26,55 +28,32 @@ class GitRepoSchemaTestBase(auto_stub.TestCase):
def getRepoContent(cls, commit):
return getattr(cls, 'COMMIT_%s' % commit, None)
- @classmethod
- def setUpClass(cls):
- super(GitRepoSchemaTestBase, cls).setUpClass()
- assert cls.REPO_SCHEMA is not None
- cls.r_schema = GitRepoSchema(cls.REPO_SCHEMA, cls.getRepoContent)
-
-
-class GitRepoReadOnlyTestBase(GitRepoSchemaTestBase):
- """Injects a GitRepo object given the schema and content from
- GitRepoSchemaTestBase into TestCase classes which subclass this.
-
- 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_SCHEMA = None
-
- @classmethod
- def setUpClass(cls):
- super(GitRepoReadOnlyTestBase, cls).setUpClass()
- assert cls.REPO_SCHEMA is not None
- cls.repo = GitRepo(cls.r_schema)
-
- def setUp(self):
- self.repo.git('checkout', '-f', self.repo.last_commit)
-
- @classmethod
- def tearDownClass(cls):
- cls.repo.nuke()
- super(GitRepoReadOnlyTestBase, cls).tearDownClass()
-
-
-class GitRepoReadWriteTestBase(GitRepoSchemaTestBase):
- """Injects a GitRepo object given the schema and content from
- GitRepoSchemaTestBase into TestCase classes which subclass this.
-
- This GitRepo will appear as self.repo, and will be deleted and recreated for
- each test function in the subclass.
- """
- REPO_SCHEMA = None
+ def assertSchema(self, schema_string):
+ self.assertEqual(GitRepoSchema(schema_string).simple_graph(),
+ self.repo.to_schema().simple_graph())
def setUp(self):
- super(GitRepoReadWriteTestBase, self).setUp()
+ super(GitRepoTestBase, self).setUp()
+ assert self.REPO_SCHEMA is not None
+ # TODO(iannucci): r_schema could be established at class-load time, using
+ # a metaclass. This would enable us to only parse the schema once per
+ # derived test case class.
+ self.r_schema = GitRepoSchema(self.REPO_SCHEMA, self.getRepoContent)
self.repo = GitRepo(self.r_schema)
+ self.repo.git('checkout', '-f', self.repo.last_commit)
def tearDown(self):
- self.repo.nuke()
- super(GitRepoReadWriteTestBase, self).tearDown()
+ try:
+ self.repo.nuke()
+ finally:
+ super(GitRepoTestBase, self).tearDown()
- def assertSchema(self, schema_string):
- self.assertEqual(GitRepoSchema(schema_string).simple_graph(),
- self.repo.to_schema().simple_graph())
+# The read-only version used to set up and tear down repo on a setUpClass basis,
+# and the read-write version used to do it on a setUp basis. This is no longer
+# the case. Keep the names around, but they're deprecated.
+GitRepoReadWriteTestBase = GitRepoTestBase
+GitRepoReadOnlyTestBase = GitRepoTestBase
+
+# Additionally, there was a schema-only version, but it was pretty useless
+GitRepoSchemaTestBase = GitRepoTestBase
« no previous file with comments | « testing_support/__init__.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698