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

Consistently overwrite HOME.

Jelmer Vernooij 8 жил өмнө
parent
commit
34fe903c97

+ 2 - 0
dulwich/contrib/test_swift.py

@@ -430,7 +430,9 @@ class TestSwiftRepo(TestCase):
 @skipIf(missing_libs, skipmsg)
 @skipIfPY3
 class TestPackInfoLoadDump(TestCase):
+
     def setUp(self):
+        super(TestPackInfoLoadDump, self).setUp()
         conf = swift.load_conf(file=StringIO(config_file %
                                              def_config_file))
         sos = swift.SwiftObjectStore(

+ 16 - 1
dulwich/tests/__init__.py

@@ -29,7 +29,22 @@ import tempfile
 
 # If Python itself provides an exception, use that
 import unittest
-from unittest import SkipTest, TestCase, skipIf, expectedFailure
+from unittest import SkipTest, TestCase as _TestCase, skipIf, expectedFailure
+
+
+class TestCase(_TestCase):
+
+    def setUp(self):
+        super(TestCase, self).setUp()
+        self._old_home = os.environ.get("HOME")
+        os.environ["HOME"] = "/nonexistant"
+
+    def tearDown(self):
+        super(TestCase, self).tearDown()
+        if self._old_home:
+            os.environ["HOME"] = self._old_home
+        else:
+            del os.environ["HOME"]
 
 
 class BlackboxTestCase(TestCase):

+ 4 - 12
dulwich/tests/test_config.py

@@ -36,15 +36,7 @@ from dulwich.tests import (
     )
 
 
-class ConfigTestCase(TestCase):
-
-    def setUp(self):
-        super(ConfigTestCase, self).setUp()
-        self.addCleanup(os.environ.__setitem__, "HOME", os.environ["HOME"])
-        os.environ["HOME"] = "/nonexistant"
-
-
-class ConfigFileTests(ConfigTestCase):
+class ConfigFileTests(TestCase):
 
     def from_file(self, text):
         return ConfigFile.from_file(BytesIO(text))
@@ -171,7 +163,7 @@ class ConfigFileTests(ConfigTestCase):
         }}), cf)
 
 
-class ConfigDictTests(ConfigTestCase):
+class ConfigDictTests(TestCase):
 
     def test_get_set(self):
         cd = ConfigDict()
@@ -225,7 +217,7 @@ class ConfigDictTests(ConfigTestCase):
             list(cd.itersections()))
 
 
-class StackedConfigTests(ConfigTestCase):
+class StackedConfigTests(TestCase):
 
     def test_default_backends(self):
         StackedConfig.default_backends()
@@ -303,7 +295,7 @@ class CheckSectionNameTests(TestCase):
         self.assertTrue(_check_section_name(b"bar.bar"))
 
 
-class SubmodulesTests(ConfigTestCase):
+class SubmodulesTests(TestCase):
 
     def testSubmodules(self):
         cf = ConfigFile.from_file(BytesIO(b"""\

+ 0 - 4
dulwich/tests/test_repository.py

@@ -303,8 +303,6 @@ class RepositoryRootTests(TestCase):
         self.assertIsInstance(r.get_config(), Config)
 
     def test_get_config_stack(self):
-        self.addCleanup(os.environ.__setitem__, "HOME", os.environ["HOME"])
-        os.environ["HOME"] = "/nonexistant"
         r = self.open_repo('ooo_merge.git')
         self.assertIsInstance(r.get_config_stack(), Config)
 
@@ -629,8 +627,6 @@ class BuildRepoRootTests(TestCase):
         self.assertEqual(b"iso8859-1", r[commit_sha].encoding)
 
     def test_commit_config_identity(self):
-        self.addCleanup(os.environ.__setitem__, "HOME", os.environ["HOME"])
-        os.environ["HOME"] = "/nonexistant"
         # commit falls back to the users' identity if it wasn't specified
         r = self._repo
         c = r.get_config()