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

Unified Diff: testing_support/git/unittest_helpers.py

Issue 418643004: Copy git tooling into testing_support. (Closed) Base URL: https://chromium.googlesource.com/infra/testing/testing_support@master
Patch Set: fix scripts Created 6 years, 5 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/git/schema.py ('k') | testing_support/git/util.py » ('j') | 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
new file mode 100644
index 0000000000000000000000000000000000000000..0ac27bd6eaff996e6e29dbd9a9d7d3a18d0ff283
--- /dev/null
+++ b/testing_support/git/unittest_helpers.py
@@ -0,0 +1,81 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import unittest
+
+
+from testing_support.git.repo import GitRepo
+from testing_support.git.schema import GitRepoSchema
+
+
+class GitRepoSchemaTestBase(unittest.TestCase):
+ """A TestCase with a built-in GitRepoSchema.
+
+ 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.
+
+ You probably will end up using either GitRepoReadOnlyTestBase or
+ GitRepoReadWriteTestBase for real tests.
+ """
+ REPO_SCHEMA = None
+
+ @classmethod
+ 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 setUp(self):
+ super(GitRepoReadWriteTestBase, self).setUp()
+ self.repo = GitRepo(self.r_schema)
+
+ def tearDown(self):
+ self.repo.nuke()
+ super(GitRepoReadWriteTestBase, self).tearDown()
+
+ def assertSchema(self, schema_string):
+ self.assertEqual(GitRepoSchema(schema_string).simple_graph(),
+ self.repo.to_schema().simple_graph())
+
« no previous file with comments | « testing_support/git/schema.py ('k') | testing_support/git/util.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698