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

Unified Diff: infra/services/gnumbd/test/gnumbd_test.py

Issue 413983003: Refactor infra git libs and testing. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: 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
Index: infra/services/gnumbd/test/gnumbd_test.py
diff --git a/infra/services/gnumbd/test/gnumbd_smoketests_main.py b/infra/services/gnumbd/test/gnumbd_test.py
similarity index 82%
rename from infra/services/gnumbd/test/gnumbd_smoketests_main.py
rename to infra/services/gnumbd/test/gnumbd_test.py
index de284f5561af33b84829ab25515a0b43df349013..261490ea9e45f812a7df138c8ee76abd05d8b8a6 100644
--- a/infra/services/gnumbd/test/gnumbd_smoketests_main.py
+++ b/infra/services/gnumbd/test/gnumbd_test.py
@@ -11,11 +11,12 @@ import tempfile
from cStringIO import StringIO
-from infra.services.gnumbd import inner_loop as gnumbd
+from infra.services.gnumbd import gnumbd
-from infra.services.gnumbd.support import config_ref, data, git
+from infra.libs import git2
+from infra.libs.git2 import data
-from infra.services.gnumbd.test import gnumbd_smoketests
+from infra.services.gnumbd.test import gnumbd_test_definitions
# should already be on path
agable 2014/07/25 21:03:39 No longer necessary -- guaranteed by run.py.
iannucci 2014/07/26 00:18:43 Done.
import expect_tests # pylint: disable=F0401
agable 2014/07/25 21:03:39 Pylint also no longer necessary?
iannucci 2014/07/26 00:18:43 Done.
@@ -65,7 +66,7 @@ class GitTree(GitEntry):
tf.seek(0)
return repo.run('mktree', '-z', stdin=tf).strip()
-class TestRef(git.Ref):
+class TestRef(git2.Ref):
def synthesize_commit(self, message, number=None, tree=None, svn=False,
footers=None):
footers = footers or collections.OrderedDict()
@@ -92,7 +93,7 @@ class TestClock(object):
return self._time
-class TestConfigRef(config_ref.ConfigRef):
+class TestConfigRef(gnumbd.GnumbdConfigRef):
def update(self, **values):
new_config = self.current
new_config.update(values)
@@ -101,14 +102,14 @@ class TestConfigRef(config_ref.ConfigRef):
tree=GitTree({'config.json': GitFile(json.dumps(new_config))}))
-class TestRepo(git.Repo):
- def __init__(self, short_name, tmpdir, clock, mirror_of=None):
+class TestRepo(git2.Repo):
+ def __init__(self, short_name, clock, mirror_of=None):
super(TestRepo, self).__init__(mirror_of or 'local test repo')
self._short_name = short_name
- self.repos_dir = tmpdir
+ self.repos_dir = tempfile.tempdir
if mirror_of is None:
- self._repo_path = tempfile.mkdtemp(dir=self.repos_dir, suffix='.git')
+ self._repo_path = tempfile.mkdtemp(suffix='.git')
self.run('init', '--bare')
self._clock = clock
@@ -124,7 +125,7 @@ class TestRepo(git.Repo):
tree = tree.intern(self) if isinstance(tree, GitTree) else tree
assert isinstance(tree, str)
- parents = [parent.hsh] if parent is not git.INVALID else []
+ parents = [parent.hsh] if parent is not git2.INVALID else []
timestamp = data.CommitTimestamp(self._clock.time(), '+', 8, 0)
user = data.CommitUser('Test User', 'test_user@example.com', timestamp)
@@ -141,7 +142,7 @@ class TestRepo(git.Repo):
else:
fmt = '%H%x00%B%x00%x00'
for ref in (r.ref for r in self.refglob('*')):
- if ref == gnumbd.DEFAULT_CONFIG_REF and not include_config:
+ if ref == gnumbd.GnumbdConfigRef.REF and not include_config:
continue
log = self.run('log', ref, '--format=%s' % fmt)
ret[ref] = collections.OrderedDict(
@@ -155,13 +156,13 @@ class TestRepo(git.Repo):
return 'TestRepo(%r)' % self._short_name
-def RunTest(tmpdir, test_name):
+def RunTest(test_name):
ret = []
clock = TestClock()
- origin = TestRepo('origin', tmpdir, clock)
- local = TestRepo('local', tmpdir, clock, origin.repo_path)
+ origin = TestRepo('origin', clock)
+ local = TestRepo('local', clock, origin.repo_path)
- cref = TestConfigRef(origin[gnumbd.DEFAULT_CONFIG_REF])
+ cref = TestConfigRef(origin)
cref.update(enabled_refglobs=['refs/heads/*'], interval=0)
def checkpoint(message, include_committer=False, include_config=False):
@@ -198,16 +199,20 @@ def RunTest(tmpdir, test_name):
root_logger.setLevel(log_level)
ret.append({'log output': logout.getvalue().splitlines()})
- gnumbd_smoketests.GNUMBD_TESTS[test_name](
+ gnumbd_test_definitions.GNUMBD_TESTS[test_name](
origin, local, cref, run, checkpoint)
return expect_tests.Result(ret)
-def GenTests(tmpdir):
- for test_name, test in gnumbd_smoketests.GNUMBD_TESTS.iteritems():
+@expect_tests.test_generator
+def GenTests():
+ for test_name, test in gnumbd_test_definitions.GNUMBD_TESTS.iteritems():
yield expect_tests.Test(
__package__ + '.' + test_name,
- expect_tests.FuncCall(RunTest, tmpdir, test_name),
- os.path.join(BASE_PATH, 'gnumbd_smoketests.expected'),
- test_name, 'yaml', break_funcs=[test])
+ expect_tests.FuncCall(RunTest, test_name),
+ expect_base=test_name, ext='yaml', break_funcs=[test],
+ covers=(
+ expect_tests.Test.covers_obj(RunTest) +
+ expect_tests.Test.covers_obj(gnumbd_test_definitions)
+ ))

Powered by Google App Engine
This is Rietveld 408576698