diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2015-08-29 07:57:50 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2015-08-29 07:57:50 -0400 |
commit | 198a684d250defdaab79d7055adb62fddf8a4e19 (patch) | |
tree | b3f826afb94d550fddaffbfb61a9363a60accda4 /tests/test_testing.py | |
parent | 3fb080e07ef7dd56c3b365ea3fc443902cfc5abf (diff) | |
download | python-coveragepy-198a684d250defdaab79d7055adb62fddf8a4e19.tar.gz |
Add an explicit test of EnvironmentAwareMixin
Diffstat (limited to 'tests/test_testing.py')
-rw-r--r-- | tests/test_testing.py | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/tests/test_testing.py b/tests/test_testing.py index 39c711b..80f0646 100644 --- a/tests/test_testing.py +++ b/tests/test_testing.py @@ -10,8 +10,9 @@ import sys from coverage.backunittest import TestCase from coverage.backward import to_bytes +from coverage.test_helpers import EnvironmentAwareMixin, TempDirMixin -from tests.coveragetest import TempDirMixin, CoverageTest +from tests.coveragetest import CoverageTest class TestingTest(TestCase): @@ -63,6 +64,30 @@ class TempDirMixinTest(TempDirMixin, TestCase): self.assertEqual(text, to_bytes("tabblo: «ταБЬℓσ»")) +class EnvironmentAwareMixinTest(EnvironmentAwareMixin, TestCase): + """Tests of test_helpers.EnvironmentAwareMixin.""" + + def test_setting_and_cleaning_env_vars(self): + # The before state. + home = os.environ["HOME"] + self.assertNotEqual(home, "Is where the heart is") + self.assertNotIn("XYZZY_PLUGH", os.environ) + + # Change the environment. + self.set_environ("HOME", "Is where the heart is") + self.set_environ("XYZZY_PLUGH", "Vogon") + + self.assertEqual(os.environ["HOME"], "Is where the heart is") + self.assertEqual(os.environ["XYZZY_PLUGH"], "Vogon") + + # Do the clean ups early. + self.doCleanups() + + # The environment should be restored. + self.assertEqual(os.environ["HOME"], home) + self.assertNotIn("XYZZY_PLUGH", os.environ) + + class CoverageTestTest(CoverageTest): """Test the methods in `CoverageTest`.""" |