| 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())
|
| +
|
|
|