2
0
Эх сурвалжийг харах

Revert "Run Git in tests without user's ".gitconfig"."

This reverts commit 685cf860afc0efa0a4c1a4a8a9c45e80a71f626a,
as I have been unable to contact Risto about relicensing to Apachev2.
Jelmer Vernooij 8 жил өмнө
parent
commit
f2c26f08e0

+ 1 - 38
dulwich/tests/__init__.py

@@ -29,44 +29,7 @@ import tempfile
 
 # If Python itself provides an exception, use that
 import unittest
-from unittest import SkipTest, TestCase as _TestCase, skipIf, expectedFailure
-
-
-def get_safe_env(env=None):
-    """Returns the environment "env" (or a copy of "os.environ" by default)
-    modified to avoid side-effects caused by user's ~/.gitconfig"""
-
-    if env is None:
-        env = os.environ.copy()
-    # On Windows it's not enough to set "HOME" to a non-existing
-    # directory. Git.cmd takes the first existing directory out of
-    # "%HOME%", "%HOMEDRIVE%%HOMEPATH%" and "%USERPROFILE%".
-    for e in 'HOME', 'HOMEPATH', 'USERPROFILE':
-        env[e] = '/nosuchdir'
-    return env
-
-
-class TestCase(_TestCase):
-
-    def makeSafeEnv(self):
-        """Create environment with homedirectory-related variables stripped.
-
-        Modifies os.environ for the duration of a test case to avoid
-        side-effects caused by the user's ~/.gitconfig and other
-        files in their home directory.
-        """
-        old_env = os.environ
-        def restore():
-            os.environ = old_env
-        self.addCleanup(restore)
-        new_env = dict(os.environ)
-        for e in ['HOME', 'HOMEPATH', 'USERPROFILE']:
-            new_env[e] = '/nosuchdir'
-        os.environ = new_env
-
-    def setUp(self):
-        super(TestCase, self).setUp()
-        self.makeSafeEnv()
+from unittest import SkipTest, TestCase, skipIf, expectedFailure
 
 
 class BlackboxTestCase(TestCase):

+ 2 - 4
dulwich/tests/compat/test_client.py

@@ -58,7 +58,6 @@ from dulwich import (
     repo,
     )
 from dulwich.tests import (
-    get_safe_env,
     SkipTest,
     expectedFailure,
     )
@@ -268,7 +267,6 @@ class DulwichTCPClientTest(CompatTestCase, DulwichClientTestBase):
         if check_for_daemon(limit=1):
             raise SkipTest('git-daemon was already running on port %s' %
                               protocol.TCP_GIT_PORT)
-        env = get_safe_env()
         fd, self.pidfile = tempfile.mkstemp(prefix='dulwich-test-git-client',
                                             suffix=".pid")
         os.fdopen(fd).close()
@@ -279,7 +277,7 @@ class DulwichTCPClientTest(CompatTestCase, DulwichClientTestBase):
                 '--listen=localhost', '--reuseaddr',
                 self.gitroot]
         self.process = subprocess.Popen(
-            args, env=env, cwd=self.gitroot,
+            args, cwd=self.gitroot,
             stdout=subprocess.PIPE, stderr=subprocess.PIPE)
         if not check_for_daemon():
             raise SkipTest('git-daemon failed to start')
@@ -324,7 +322,7 @@ class TestSSHVendor(object):
         cmd, path = command.split(b' ')
         cmd = cmd.split(b'-', 1)
         path = path.replace(b"'", b"")
-        p = subprocess.Popen(cmd + [path], bufsize=0, env=get_safe_env(), stdin=subprocess.PIPE,
+        p = subprocess.Popen(cmd + [path], bufsize=0, stdin=subprocess.PIPE,
                              stdout=subprocess.PIPE, stderr=subprocess.PIPE)
         return client.SubprocessWrapper(p)
 

+ 1 - 2
dulwich/tests/compat/utils.py

@@ -34,7 +34,6 @@ from dulwich.repo import Repo
 from dulwich.protocol import TCP_GIT_PORT
 
 from dulwich.tests import (
-    get_safe_env,
     SkipTest,
     TestCase,
     )
@@ -123,7 +122,7 @@ def run_git(args, git_path=_DEFAULT_GIT, input=None, capture_stdout=False,
     :raise OSError: if the git executable was not found.
     """
 
-    env = get_safe_env(popen_kwargs.pop('env', None))
+    env = popen_kwargs.pop('env', {})
     env['LC_ALL'] = env['LANG'] = 'C'
 
     args = [git_path] + args