tests/locks: save/restore global env state
authorZac Medico <zmedico@gentoo.org>
Wed, 14 Dec 2011 09:17:16 +0000 (01:17 -0800)
committerZac Medico <zmedico@gentoo.org>
Wed, 14 Dec 2011 09:17:16 +0000 (01:17 -0800)
This ensures that global __PORTAGE_TEST_HARDLINK_LOCKS overrides work
correctly for all tests.

pym/portage/tests/locks/test_asynchronous_lock.py
pym/portage/tests/locks/test_lock_nonblock.py

index c896cb45c17965ab91c956db635dc9f6317e434f..49dd10ec40caeb3e294da53d5305f1a7c0f2f4e8 100644 (file)
@@ -43,11 +43,14 @@ class AsynchronousLockTestCase(TestCase):
                self._testAsynchronousLock()
 
        def testAsynchronousLockHardlink(self):
+               prev_state = os.environ.pop("__PORTAGE_TEST_HARDLINK_LOCKS", None)
                os.environ["__PORTAGE_TEST_HARDLINK_LOCKS"] = "1"
                try:
                        self._testAsynchronousLock()
                finally:
                        os.environ.pop("__PORTAGE_TEST_HARDLINK_LOCKS", None)
+                       if prev_state is not None:
+                               os.environ["__PORTAGE_TEST_HARDLINK_LOCKS"] = prev_state
 
        def _testAsynchronousLockWait(self):
                scheduler = PollScheduler().sched_iface
@@ -81,11 +84,14 @@ class AsynchronousLockTestCase(TestCase):
                self._testAsynchronousLockWait()
 
        def testAsynchronousLockWaitHardlink(self):
+               prev_state = os.environ.pop("__PORTAGE_TEST_HARDLINK_LOCKS", None)
                os.environ["__PORTAGE_TEST_HARDLINK_LOCKS"] = "1"
                try:
                        self._testAsynchronousLockWait()
                finally:
                        os.environ.pop("__PORTAGE_TEST_HARDLINK_LOCKS", None)
+                       if prev_state is not None:
+                               os.environ["__PORTAGE_TEST_HARDLINK_LOCKS"] = prev_state
 
        def _testAsynchronousLockWaitCancel(self):
                scheduler = PollScheduler().sched_iface
@@ -116,11 +122,14 @@ class AsynchronousLockTestCase(TestCase):
                self._testAsynchronousLockWaitCancel()
 
        def testAsynchronousLockWaitCancelHardlink(self):
+               prev_state = os.environ.pop("__PORTAGE_TEST_HARDLINK_LOCKS", None)
                os.environ["__PORTAGE_TEST_HARDLINK_LOCKS"] = "1"
                try:
                        self._testAsynchronousLockWaitCancel()
                finally:
                        os.environ.pop("__PORTAGE_TEST_HARDLINK_LOCKS", None)
+                       if prev_state is not None:
+                               os.environ["__PORTAGE_TEST_HARDLINK_LOCKS"] = prev_state
 
        def _testAsynchronousLockWaitKill(self):
                scheduler = PollScheduler().sched_iface
@@ -157,8 +166,11 @@ class AsynchronousLockTestCase(TestCase):
                self._testAsynchronousLockWaitKill()
 
        def testAsynchronousLockWaitKillHardlink(self):
+               prev_state = os.environ.pop("__PORTAGE_TEST_HARDLINK_LOCKS", None)
                os.environ["__PORTAGE_TEST_HARDLINK_LOCKS"] = "1"
                try:
                        self._testAsynchronousLockWaitKill()
                finally:
                        os.environ.pop("__PORTAGE_TEST_HARDLINK_LOCKS", None)
+                       if prev_state is not None:
+                               os.environ["__PORTAGE_TEST_HARDLINK_LOCKS"] = prev_state
index 914084ca7dc88c1d9a5d403c716638e371db9642..17f854dbe43240701d95026bff88ad11130fa3c0 100644 (file)
@@ -48,9 +48,12 @@ class LockNonblockTestCase(TestCase):
                self._testLockNonblock()
 
        def testLockNonblockHardlink(self):
+               prev_state = os.environ.pop("__PORTAGE_TEST_HARDLINK_LOCKS", None)
                os.environ["__PORTAGE_TEST_HARDLINK_LOCKS"] = "1"
                try:
                        self._testLockNonblock()
                finally:
                        os.environ.pop("__PORTAGE_TEST_HARDLINK_LOCKS", None)
+                       if prev_state is not None:
+                               os.environ["__PORTAGE_TEST_HARDLINK_LOCKS"] = prev_state