Index: infra/services/gnumbd/test/inner_loop_test.py |
diff --git a/infra/services/gnumbd/test/gnumbd_smoketests_main.py b/infra/services/gnumbd/test/inner_loop_test.py |
similarity index 80% |
rename from infra/services/gnumbd/test/gnumbd_smoketests_main.py |
rename to infra/services/gnumbd/test/inner_loop_test.py |
index 59bce565942f55386a7590ed6112c33bc13cfc28..81af595efa99ac434b7e10ea60cb4622565b0176 100644 |
--- a/infra/services/gnumbd/test/gnumbd_smoketests_main.py |
+++ b/infra/services/gnumbd/test/inner_loop_test.py |
@@ -3,19 +3,23 @@ |
# found in the LICENSE file. |
import collections |
+import glob |
import json |
import logging |
import os |
+import shutil |
import sys |
import tempfile |
from cStringIO import StringIO |
-from infra.services.gnumbd import inner_loop as gnumbd |
+from infra.services.gnumbd import inner_loop |
-from infra.services.gnumbd.support import config_ref, data, git |
+from infra.libs import git2 |
+from infra.libs.git2 import config_ref |
+from infra.libs.git2 import data |
-from infra.services.gnumbd.test import gnumbd_smoketests |
+from infra.services.gnumbd.test import inner_loop_test_definitions |
from infra.ext import testing_support # pylint: disable=W0611 |
from testing_support import expect_tests # pylint: disable=F0401 |
@@ -65,17 +69,17 @@ 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() |
if number is not None: |
if svn: |
- footers[gnumbd.GIT_SVN_ID] = [ |
+ footers[inner_loop.GIT_SVN_ID] = [ |
'svn://repo/path@%s 0039d316-1c4b-4281-b951-d872f2087c98' % number] |
else: |
- footers[gnumbd.COMMIT_POSITION] = [ |
- gnumbd.FMT_COMMIT_POSITION(self, number)] |
+ footers[inner_loop.COMMIT_POSITION] = [ |
+ inner_loop.FMT_COMMIT_POSITION(self, number)] |
commit = self.repo.synthesize_commit(self.commit, message, footers=footers, |
tree=tree) |
@@ -101,7 +105,7 @@ class TestConfigRef(config_ref.ConfigRef): |
tree=GitTree({'config.json': GitFile(json.dumps(new_config))})) |
-class TestRepo(git.Repo): |
+class TestRepo(git2.Repo): |
def __init__(self, short_name, tmpdir, clock, mirror_of=None): |
super(TestRepo, self).__init__(mirror_of or 'local test repo') |
self._short_name = short_name |
@@ -124,7 +128,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 +145,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 == inner_loop.DEFAULT_CONFIG_REF and not include_config: |
continue |
log = self.run('log', ref, '--format=%s' % fmt) |
ret[ref] = collections.OrderedDict( |
@@ -161,7 +165,7 @@ def RunTest(tmpdir, test_name): |
origin = TestRepo('origin', tmpdir, clock) |
local = TestRepo('local', tmpdir, clock, origin.repo_path) |
- cref = TestConfigRef(origin[gnumbd.DEFAULT_CONFIG_REF]) |
+ cref = TestConfigRef(origin[inner_loop.DEFAULT_CONFIG_REF]) |
cref.update(enabled_refglobs=['refs/heads/*'], interval=0) |
def checkpoint(message, include_committer=False, include_config=False): |
@@ -185,7 +189,7 @@ def RunTest(tmpdir, test_name): |
try: |
sys.stderr = sys.stdout = open(os.devnull, 'w') |
local.reify() |
- gnumbd.inner_loop(local, cref, clock) |
+ inner_loop.inner_loop(local, cref, clock) |
except Exception: # pragma: no cover |
import traceback |
ret.append(traceback.format_exc().splitlines()) |
@@ -198,16 +202,28 @@ def RunTest(tmpdir, test_name): |
root_logger.setLevel(log_level) |
ret.append({'log output': logout.getvalue().splitlines()}) |
- gnumbd_smoketests.GNUMBD_TESTS[test_name]( |
+ inner_loop_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.generator |
+def GenTests(): |
+ suffix = '.gnumbd_inner_loop' |
+ tmpdir = tempfile.mkdtemp(suffix) |
+ for p in glob.glob(os.path.join(os.path.dirname(tmpdir), '*'+suffix)): |
+ if p != tmpdir: # pragma: no cover |
+ shutil.rmtree(p) |
+ |
+ yield expect_tests.Cleanup(expect_tests.FuncCall(shutil.rmtree, tmpdir)) |
+ |
+ for test_name, test in inner_loop_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_base=test_name, ext='yaml', break_funcs=[test], |
+ covers=( |
+ expect_tests.Test.covers_obj(RunTest) + |
+ expect_tests.Test.covers_obj(inner_loop_test_definitions) |
+ )) |