[Piglit] [PATCH 10/10] framework: move TestWithEnvClean out of utils and into run_parser_tests.py
Dylan Baker
baker.dylan.c at gmail.com
Thu Jan 29 15:31:25 PST 2015
This is now the only user of this class, and it's a bit of an ugly
thing. So, rather than allowing it to live in utils where the temptation
to use it again might rear it's head, hide it in this module and get rid
of it another day.
---
framework/tests/run_parser_tests.py | 53 ++++++++++++++++++++++++++++++++++++-
framework/tests/utils.py | 51 -----------------------------------
2 files changed, 52 insertions(+), 52 deletions(-)
diff --git a/framework/tests/run_parser_tests.py b/framework/tests/run_parser_tests.py
index 7e5f466..77f60bb 100644
--- a/framework/tests/run_parser_tests.py
+++ b/framework/tests/run_parser_tests.py
@@ -33,7 +33,58 @@ import framework.programs.run as run
import framework.core as core
-class _Helpers(utils.TestWithEnvClean):
+class TestWithEnvClean(object):
+ """ Class that does cleanup with saved state
+
+ This could be done with test fixtures, but this should be cleaner in the
+ specific case of cleaning up environment variables
+
+ Nose will run a method (bound or unbound) at the start of the test called
+ setup() and one at the end called teardown(), we have added a teardown
+ method.
+
+ Using this gives us the assurance that we're not relying on settings from
+ other tests, making ours pass or fail, and that os.enviorn is the same
+ going in as it is going out.
+
+ This is modeled after Go's defer keyword.
+
+ """
+ def __init__(self):
+ self._saved = set()
+ self._teardown_calls = []
+
+ def add_teardown(self, var, restore=True):
+ """ Add os.environ values to remove in teardown """
+ if var in os.environ:
+ self._saved.add((var, os.environ.get(var), restore))
+ del os.environ[var]
+
+ def defer(self, func, *args):
+ """ Add a function (with arguments) to be run durring cleanup """
+ self._teardown_calls.append((func, args))
+
+ def teardown(self):
+ """ Teardown the test
+
+ Restore any variables that were unset at the begining of the test, and
+ run any differed methods.
+
+ """
+ for key, value, restore in self._saved:
+ # If value is None the value was unset previously, put it back
+ if value is None:
+ del os.environ[key]
+ elif restore:
+ os.environ[key] = value
+
+ # Teardown calls is a FIFO stack, the defered calls must be run in
+ # reversed order to make any sense
+ for call, args in reversed(self._teardown_calls):
+ call(*args)
+
+
+class _Helpers(TestWithEnvClean):
""" Some helpers to be shared between tests """
def _unset_config(self):
""" Ensure that no config files are being accidently loaded """
diff --git a/framework/tests/utils.py b/framework/tests/utils.py
index 59da6b9..c124f92 100644
--- a/framework/tests/utils.py
+++ b/framework/tests/utils.py
@@ -187,57 +187,6 @@ def privileged_test(func):
return sudo_test_wrapper
-class TestWithEnvClean(object):
- """ Class that does cleanup with saved state
-
- This could be done with test fixtures, but this should be cleaner in the
- specific case of cleaning up environment variables
-
- Nose will run a method (bound or unbound) at the start of the test called
- setup() and one at the end called teardown(), we have added a teardown
- method.
-
- Using this gives us the assurance that we're not relying on settings from
- other tests, making ours pass or fail, and that os.enviorn is the same
- going in as it is going out.
-
- This is modeled after Go's defer keyword.
-
- """
- def __init__(self):
- self._saved = set()
- self._teardown_calls = []
-
- def add_teardown(self, var, restore=True):
- """ Add os.environ values to remove in teardown """
- if var in os.environ:
- self._saved.add((var, os.environ.get(var), restore))
- del os.environ[var]
-
- def defer(self, func, *args):
- """ Add a function (with arguments) to be run durring cleanup """
- self._teardown_calls.append((func, args))
-
- def teardown(self):
- """ Teardown the test
-
- Restore any variables that were unset at the begining of the test, and
- run any differed methods.
-
- """
- for key, value, restore in self._saved:
- # If value is None the value was unset previously, put it back
- if value is None:
- del os.environ[key]
- elif restore:
- os.environ[key] = value
-
- # Teardown calls is a FIFO stack, the defered calls must be run in
- # reversed order to make any sense
- for call, args in reversed(self._teardown_calls):
- call(*args)
-
-
class StaticDirectory(object):
""" Helper class providing shared files creation and cleanup
--
2.2.2
More information about the Piglit
mailing list