Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 collections | |
| 6 import json | |
| 7 import logging | |
| 8 import os | |
| 9 import subprocess | |
| 10 import sys | |
| 11 import tempfile | |
| 12 | |
| 13 from cStringIO import StringIO | |
| 14 | |
| 15 import expect_tests | |
| 16 | |
| 17 from infra.libs.git2.testing_support import TestClock | |
| 18 from infra.libs.git2.testing_support import TestRepo | |
| 19 from infra.services.gsubtreed import gsubtreed | |
| 20 from infra.services.gsubtreed.test import gsubtreed_test_definitions | |
| 21 | |
| 22 | |
| 23 BASE_PATH = os.path.dirname(os.path.abspath(__file__)) | |
| 24 | |
| 25 | |
| 26 class TestConfigRef(gsubtreed.GsubtreedConfigRef): | |
| 27 def update(self, **values): | |
| 28 new_config = self.current | |
| 29 new_config.update(values) | |
| 30 self.ref.make_commit( | |
| 31 'update(%r)' % values.keys(), | |
| 32 {'config.json': json.dumps(new_config)}) | |
| 33 | |
| 34 | |
| 35 # TODO(iannucci): Make these first class data library objects | |
|
Vadim Sh.
2014/08/17 19:37:59
huh? what exactly?
iannucci
2014/08/17 22:35:30
Oh, oops. That was from before I moved all the stu
| |
| 36 def RunTest(test_name): | |
| 37 ret = [] | |
| 38 clock = TestClock() | |
| 39 origin = TestRepo('origin', clock) | |
| 40 local = TestRepo('local', clock, origin.repo_path) | |
| 41 | |
| 42 base_repo_path = tempfile.mkdtemp() | |
| 43 | |
| 44 enabled_paths = ['mirrored_path/subpath', 'mirrored_path'] | |
| 45 cref = TestConfigRef(origin) | |
| 46 cref.update(enabled_paths=enabled_paths) | |
| 47 | |
| 48 for path in enabled_paths: | |
| 49 full_path = os.path.join(base_repo_path, path) | |
| 50 try: | |
| 51 os.makedirs(full_path) | |
| 52 except OSError: | |
| 53 pass | |
| 54 with open(os.devnull, 'w') as dn: | |
| 55 subprocess.check_call(['git', 'init', '--bare'], cwd=full_path, | |
| 56 stdout=dn, stderr=dn) | |
| 57 | |
| 58 def checkpoint(message, include_committer=False, include_config=False): | |
| 59 osnap = origin.snap(include_committer, include_config) | |
| 60 for ref in osnap: | |
| 61 # since the subtree-processed refs are actually tags on master, don't | |
| 62 # bother showing them in their entirety | |
| 63 if 'subtree-processed' in ref: | |
| 64 if len(osnap[ref]) <= 1: | |
| 65 continue # pragma: no cover | |
| 66 osnap[ref] = collections.OrderedDict([ | |
| 67 next(osnap[ref].iteritems()), | |
| 68 ('etc', '...') | |
| 69 ]) | |
| 70 ret.append([message, {'origin': osnap}]) | |
| 71 | |
| 72 def run(): | |
| 73 stdout = sys.stdout | |
| 74 stderr = sys.stderr | |
| 75 | |
| 76 logout = StringIO() | |
| 77 root_logger = logging.getLogger() | |
| 78 shandler = logging.StreamHandler(logout) | |
| 79 shandler.setFormatter( | |
| 80 logging.Formatter('%(levelname)s: %(message)s')) | |
| 81 root_logger.addHandler(shandler) | |
| 82 shandler.setLevel(logging.INFO) | |
| 83 | |
| 84 success = False | |
| 85 processed = {} | |
| 86 try: | |
| 87 with open(os.devnull, 'w') as dn: | |
| 88 # TODO(iannucci): Let expect_tests absorb stdio | |
| 89 sys.stderr = sys.stdout = dn | |
| 90 local.reify() | |
| 91 success, processed = gsubtreed.inner_loop(local, cref, | |
| 92 'file://' + base_repo_path) | |
| 93 except Exception: # pragma: no cover | |
| 94 import traceback | |
|
Vadim Sh.
2014/08/17 19:37:59
move it to where all other imports are
iannucci
2014/08/17 22:35:30
I have no idea why I did this... :/
| |
| 95 ret.append(traceback.format_exc().splitlines()) | |
| 96 finally: | |
| 97 sys.stdout = stdout | |
| 98 sys.stderr = stderr | |
| 99 | |
| 100 root_logger.removeHandler(shandler) | |
| 101 ret.append({'log output': logout.getvalue().splitlines()}) | |
| 102 | |
| 103 ret.append({ | |
| 104 'inner_loop success': success, | |
| 105 'processed': processed, | |
| 106 }) | |
| 107 | |
| 108 gsubtreed_test_definitions.GSUBTREED_TESTS[test_name](origin, run, checkpoint) | |
| 109 | |
| 110 return expect_tests.Result(ret) | |
| 111 | |
| 112 | |
| 113 @expect_tests.test_generator | |
| 114 def GenTests(): | |
| 115 for test_name, test in gsubtreed_test_definitions.GSUBTREED_TESTS.iteritems(): | |
| 116 yield expect_tests.Test( | |
| 117 __package__ + '.' + test_name, | |
| 118 expect_tests.FuncCall(RunTest, test_name), | |
| 119 expect_base=test_name, ext='yaml', break_funcs=[test], | |
| 120 covers=( | |
| 121 expect_tests.Test.covers_obj(RunTest) + | |
| 122 expect_tests.Test.covers_obj(gsubtreed_test_definitions) | |
| 123 )) | |
| OLD | NEW |