Use context manager to manage OS environment in tests

Currently tests use manual context management (try: ... finally: ...)
This is cleaner and more robust with a context manager:
https://docs.python.org/2/library/contextlib.html

Also fixes some bugs and typos.

Tests are:
test/cflags/gyptest-cflags.py (make + ninja)
test/cxxflags/gyptest-cxxflags.py (ninja)

R=thakis
TEST=PYTHONPATH=$CHROMIUM_DIR/tools/gyp/test/lib TESTGYP_FORMAT=make test/cflags/gyptest-cflags.py
TEST=PYTHONPATH=$CHROMIUM_DIR/tools/gyp/test/lib TESTGYP_FORMAT=ninja test/cflags/gyptest-cflags.py
TEST=PYTHONPATH=$CHROMIUM_DIR/tools/gyp/test/lib TESTGYP_FORMAT=ninja test/cxxflags/gyptest-cxxflags.py

Review URL: https://codereview.chromium.org/228323002/
Patch from Nils Barth <nbarth@chromium.org>!


git-svn-id: http://gyp.googlecode.com/svn/trunk@1893 78cadc50-ecff-11dd-a971-7dbc132099af