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

Unified Diff: test/lib/TestGyp.py

Issue 228323002: Use context manager to manage OS environment in tests (Closed) Base URL: https://chromium.googlesource.com/external/gyp.git@master
Patch Set: Revised docs and which build Created 6 years, 8 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
« no previous file with comments | « test/cxxflags/gyptest-cxxflags.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/lib/TestGyp.py
diff --git a/test/lib/TestGyp.py b/test/lib/TestGyp.py
index 306bf3d3ad2caadb7a6826d0118feeca8e387031..36b6281c33451b4a86c9ca19306aea4cd5226133 100644
--- a/test/lib/TestGyp.py
+++ b/test/lib/TestGyp.py
@@ -7,6 +7,7 @@ TestGyp.py: a testing framework for GYP integration tests.
"""
import collections
+from contextlib import contextmanager
import itertools
import os
import re
@@ -24,9 +25,10 @@ __all__.extend([
'TestGyp',
])
+
def remove_debug_line_numbers(contents):
"""Function to remove the line numbers from the debug output
- of gyp and thus remove the exremem fragility of the stdout
+ of gyp and thus reduce the extreme fragility of the stdout
comparison tests.
"""
lines = contents.splitlines()
@@ -37,12 +39,26 @@ def remove_debug_line_numbers(contents):
lines = [len(l) > 3 and ":".join(l[3:]) or l for l in lines]
return "\n".join(lines)
+
def match_modulo_line_numbers(contents_a, contents_b):
"""File contents matcher that ignores line numbers."""
contents_a = remove_debug_line_numbers(contents_a)
contents_b = remove_debug_line_numbers(contents_b)
return TestCommon.match_exact(contents_a, contents_b)
+
+@contextmanager
+def LocalEnv(local_env):
+ """Context manager to provide a local OS environment."""
+ old_env = os.environ.copy()
+ os.environ.update(local_env)
+ try:
+ yield
+ finally:
+ os.environ.clear()
+ os.environ.update(old_env)
+
+
class TestGypBase(TestCommon.TestCommon):
"""
Class for controlling end-to-end tests of gyp generators.
« no previous file with comments | « test/cxxflags/gyptest-cxxflags.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698