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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « testing_support/git/schema.py ('k') | testing_support/git/util.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import unittest
6
7
8 from testing_support.git.repo import GitRepo
9 from testing_support.git.schema import GitRepoSchema
10
11
12 class GitRepoSchemaTestBase(unittest.TestCase):
13 """A TestCase with a built-in GitRepoSchema.
14
15 Expects a class variable REPO_SCHEMA to be a GitRepoSchema string in the form
16 described by that class.
17
18 You may also set class variables in the form COMMIT_%(commit_name)s, which
19 provide the content for the given commit_name commits.
20
21 You probably will end up using either GitRepoReadOnlyTestBase or
22 GitRepoReadWriteTestBase for real tests.
23 """
24 REPO_SCHEMA = None
25
26 @classmethod
27 def getRepoContent(cls, commit):
28 return getattr(cls, 'COMMIT_%s' % commit, None)
29
30 @classmethod
31 def setUpClass(cls):
32 super(GitRepoSchemaTestBase, cls).setUpClass()
33 assert cls.REPO_SCHEMA is not None
34 cls.r_schema = GitRepoSchema(cls.REPO_SCHEMA, cls.getRepoContent)
35
36
37 class GitRepoReadOnlyTestBase(GitRepoSchemaTestBase):
38 """Injects a GitRepo object given the schema and content from
39 GitRepoSchemaTestBase into TestCase classes which subclass this.
40
41 This GitRepo will appear as self.repo, and will be deleted and recreated once
42 for the duration of all the tests in the subclass.
43 """
44 REPO_SCHEMA = None
45
46 @classmethod
47 def setUpClass(cls):
48 super(GitRepoReadOnlyTestBase, cls).setUpClass()
49 assert cls.REPO_SCHEMA is not None
50 cls.repo = GitRepo(cls.r_schema)
51
52 def setUp(self):
53 self.repo.git('checkout', '-f', self.repo.last_commit)
54
55 @classmethod
56 def tearDownClass(cls):
57 cls.repo.nuke()
58 super(GitRepoReadOnlyTestBase, cls).tearDownClass()
59
60
61 class GitRepoReadWriteTestBase(GitRepoSchemaTestBase):
62 """Injects a GitRepo object given the schema and content from
63 GitRepoSchemaTestBase into TestCase classes which subclass this.
64
65 This GitRepo will appear as self.repo, and will be deleted and recreated for
66 each test function in the subclass.
67 """
68 REPO_SCHEMA = None
69
70 def setUp(self):
71 super(GitRepoReadWriteTestBase, self).setUp()
72 self.repo = GitRepo(self.r_schema)
73
74 def tearDown(self):
75 self.repo.nuke()
76 super(GitRepoReadWriteTestBase, self).tearDown()
77
78 def assertSchema(self, schema_string):
79 self.assertEqual(GitRepoSchema(schema_string).simple_graph(),
80 self.repo.to_schema().simple_graph())
81
OLDNEW
« 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