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

Unified Diff: test/cxxflags/gyptest-cxxflags.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: 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
Index: test/cxxflags/gyptest-cxxflags.py
diff --git a/test/cxxflags/gyptest-cxxflags.py b/test/cxxflags/gyptest-cxxflags.py
index 70142e7cedadcac595b239e1b889c4aa3865a20b..e0daea2126a9aa1d52546bef69d435ac6b318029 100755
--- a/test/cxxflags/gyptest-cxxflags.py
+++ b/test/cxxflags/gyptest-cxxflags.py
@@ -12,29 +12,15 @@ the use of the environment during regeneration when the gyp file changes.
import os
import TestGyp
-env_stack = []
-
-
-def PushEnv():
- env_copy = os.environ.copy()
- env_stack.append(env_copy)
-
-def PopEnv():
- os.eniron=env_stack.pop()
Nils Barth (inactive) 2014/04/08 08:56:32 Ow, notice the typos? os.eniron (not os.en*v*iron)
# Regenerating build files when a gyp file changes is currently only supported
# by the make generator.
test = TestGyp.TestGyp(formats=['make'])
-try:
- PushEnv()
- os.environ['CXXFLAGS'] = '-O0'
+# We reset the environ after calling gyp. When the auto-regeneration happens,
+# the same define should be reused anyway.
+with TestGyp.LocalEnv({'CXXFLAGS': '-O0'}):
test.run_gyp('cxxflags.gyp')
-finally:
- # We clear the environ after calling gyp. When the auto-regeneration happens,
- # the same define should be reused anyway. Reset to empty string first in
- # case the platform doesn't support unsetenv.
- PopEnv()
test.build('cxxflags.gyp')
@@ -45,15 +31,8 @@ test.run_built_executable('cxxflags', stdout=expect)
test.sleep()
-try:
- PushEnv()
- os.environ['CXXFLAGS'] = '-O2'
+with TestGyp.LocalEnv({'CXXFLAGS': '-O2'}):
test.run_gyp('cxxflags.gyp')
-finally:
- # We clear the environ after calling gyp. When the auto-regeneration happens,
- # the same define should be reused anyway. Reset to empty string first in
- # case the platform doesn't support unsetenv.
- PopEnv()
test.build('cxxflags.gyp')
« no previous file with comments | « test/cflags/gyptest-cflags.py ('k') | test/lib/TestGyp.py » ('j') | test/lib/TestGyp.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698