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 83% |
rename from infra/services/gnumbd/test/gnumbd_smoketests_main.py |
rename to infra/services/gnumbd/test/gnumbd_test.py |
index 59bce565942f55386a7590ed6112c33bc13cfc28..b4c77401b7ecac2050a07706b185a5b5f45d9051 100644 |
--- a/infra/services/gnumbd/test/gnumbd_smoketests_main.py |
+++ b/infra/services/gnumbd/test/gnumbd_test.py |
@@ -3,19 +3,22 @@ |
# 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 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 |
from infra.ext import testing_support # pylint: disable=W0611 |
from testing_support import expect_tests # pylint: disable=F0401 |
@@ -65,7 +68,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 +95,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,7 +104,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 +127,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 +144,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( |
@@ -161,7 +164,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) |
cref.update(enabled_refglobs=['refs/heads/*'], interval=0) |
def checkpoint(message, include_committer=False, include_config=False): |
@@ -198,16 +201,28 @@ 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(): |
+ 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 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_base=test_name, ext='yaml', break_funcs=[test], |
+ covers=( |
+ expect_tests.Test.covers_obj(RunTest) + |
+ expect_tests.Test.covers_obj(gnumbd_test_definitions) |
+ )) |