[presubmit] Don't replace os.environ
Assigning os.environ the result of os.environ.copy() replaces it with a standard dict. This breaks reflection into the actual environment, as well as features such as case-insensitivity on Windows, leading to undefined standard library behavior. R=bryner, gavinmak Bug: 1511316 Change-Id: I63d026387104ae92669256567854f8bf9d2397a2 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5133887 Commit-Queue: Josip Sokcevic <sokcevic@chromium.org> Reviewed-by: Brian Ryner <bryner@google.com> Reviewed-by: Gavin Mak <gavinmak@google.com>changes/87/5133887/3
parent
0e40b92d9e
commit
1bdc5c8db4
@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env python3
|
||||
# Copyright 2024 The Chromium Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
import os.path
|
||||
import subprocess
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
sys.path.insert(0, ROOT_DIR)
|
||||
|
||||
import presubmit_support
|
||||
|
||||
|
||||
class PresubmitSupportTest(unittest.TestCase):
|
||||
def test_environ(self):
|
||||
self.assertIsNone(os.environ.get('PRESUBMIT_FOO_ENV', None))
|
||||
kv = {'PRESUBMIT_FOO_ENV': 'FOOBAR'}
|
||||
with presubmit_support.setup_environ(kv):
|
||||
self.assertEqual(os.environ.get('PRESUBMIT_FOO_ENV', None),
|
||||
'FOOBAR')
|
||||
self.assertIsNone(os.environ.get('PRESUBMIT_FOO_ENV', None))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
Loading…
Reference in New Issue