Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2012 Google Inc. All rights reserved. | 1 # Copyright (c) 2012 Google Inc. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """ | 5 """ |
| 6 TestGyp.py: a testing framework for GYP integration tests. | 6 TestGyp.py: a testing framework for GYP integration tests. |
| 7 """ | 7 """ |
| 8 | 8 |
| 9 import collections | 9 import collections |
| 10 from contextlib import contextmanager | |
| 10 import itertools | 11 import itertools |
| 11 import os | 12 import os |
| 12 import re | 13 import re |
| 13 import shutil | 14 import shutil |
| 14 import stat | 15 import stat |
| 15 import subprocess | 16 import subprocess |
| 16 import sys | 17 import sys |
| 17 import tempfile | 18 import tempfile |
| 18 | 19 |
| 19 import TestCmd | 20 import TestCmd |
| 20 import TestCommon | 21 import TestCommon |
| 21 from TestCommon import __all__ | 22 from TestCommon import __all__ |
| 22 | 23 |
| 23 __all__.extend([ | 24 __all__.extend([ |
| 24 'TestGyp', | 25 'TestGyp', |
| 25 ]) | 26 ]) |
| 26 | 27 |
| 28 | |
| 27 def remove_debug_line_numbers(contents): | 29 def remove_debug_line_numbers(contents): |
| 28 """Function to remove the line numbers from the debug output | 30 """Function to remove the line numbers from the debug output |
| 29 of gyp and thus remove the exremem fragility of the stdout | 31 of gyp and thus reduce the extreme fragility of the stdout |
| 30 comparison tests. | 32 comparison tests. |
| 31 """ | 33 """ |
| 32 lines = contents.splitlines() | 34 lines = contents.splitlines() |
| 33 # split each line on ":" | 35 # split each line on ":" |
| 34 lines = [l.split(":", 3) for l in lines] | 36 lines = [l.split(":", 3) for l in lines] |
| 35 # join each line back together while ignoring the | 37 # join each line back together while ignoring the |
| 36 # 3rd column which is the line number | 38 # 3rd column which is the line number |
| 37 lines = [len(l) > 3 and ":".join(l[3:]) or l for l in lines] | 39 lines = [len(l) > 3 and ":".join(l[3:]) or l for l in lines] |
| 38 return "\n".join(lines) | 40 return "\n".join(lines) |
| 39 | 41 |
| 42 | |
| 40 def match_modulo_line_numbers(contents_a, contents_b): | 43 def match_modulo_line_numbers(contents_a, contents_b): |
| 41 """File contents matcher that ignores line numbers.""" | 44 """File contents matcher that ignores line numbers.""" |
| 42 contents_a = remove_debug_line_numbers(contents_a) | 45 contents_a = remove_debug_line_numbers(contents_a) |
| 43 contents_b = remove_debug_line_numbers(contents_b) | 46 contents_b = remove_debug_line_numbers(contents_b) |
| 44 return TestCommon.match_exact(contents_a, contents_b) | 47 return TestCommon.match_exact(contents_a, contents_b) |
| 45 | 48 |
| 49 | |
| 50 @contextmanager | |
|
Nils Barth (inactive)
2014/04/08 08:56:32
This is a simple single-use context manager (CM),
| |
| 51 def LocalEnv(local_env): | |
| 52 """Context manager to provide a local OS environment.""" | |
| 53 env_copy = os.environ.copy() | |
| 54 os.environ.update(local_env) | |
| 55 yield | |
|
Stefan Haller
2014/04/08 17:05:41
Sorry for jumping in here: for correctness, this s
Nils Barth (inactive)
2014/04/09 03:09:18
Oh, good catch -- thanks!
*don't* need try: ... fi
| |
| 56 os.environ.clear() | |
| 57 os.environ.update(env_copy) | |
| 58 | |
| 59 | |
| 46 class TestGypBase(TestCommon.TestCommon): | 60 class TestGypBase(TestCommon.TestCommon): |
| 47 """ | 61 """ |
| 48 Class for controlling end-to-end tests of gyp generators. | 62 Class for controlling end-to-end tests of gyp generators. |
| 49 | 63 |
| 50 Instantiating this class will create a temporary directory and | 64 Instantiating this class will create a temporary directory and |
| 51 arrange for its destruction (via the TestCmd superclass) and | 65 arrange for its destruction (via the TestCmd superclass) and |
| 52 copy all of the non-gyptest files in the directory hierarchy of the | 66 copy all of the non-gyptest files in the directory hierarchy of the |
| 53 executing script. | 67 executing script. |
| 54 | 68 |
| 55 The default behavior is to test the 'gyp' or 'gyp.bat' file in the | 69 The default behavior is to test the 'gyp' or 'gyp.bat' file in the |
| (...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1108 | 1122 |
| 1109 def TestGyp(*args, **kw): | 1123 def TestGyp(*args, **kw): |
| 1110 """ | 1124 """ |
| 1111 Returns an appropriate TestGyp* instance for a specified GYP format. | 1125 Returns an appropriate TestGyp* instance for a specified GYP format. |
| 1112 """ | 1126 """ |
| 1113 format = kw.pop('format', os.environ.get('TESTGYP_FORMAT')) | 1127 format = kw.pop('format', os.environ.get('TESTGYP_FORMAT')) |
| 1114 for format_class in format_class_list: | 1128 for format_class in format_class_list: |
| 1115 if format == format_class.format: | 1129 if format == format_class.format: |
| 1116 return format_class(*args, **kw) | 1130 return format_class(*args, **kw) |
| 1117 raise Exception, "unknown format %r" % format | 1131 raise Exception, "unknown format %r" % format |
| OLD | NEW |