[Piglit] [PATCH 11/18] programs_tests.py: Move additional code into a shared method

Dylan Baker baker.dylan.c at gmail.com
Tue Aug 19 13:25:05 PDT 2014


Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 framework/tests/programs_tests.py | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/framework/tests/programs_tests.py b/framework/tests/programs_tests.py
index a395b76..2c114b4 100644
--- a/framework/tests/programs_tests.py
+++ b/framework/tests/programs_tests.py
@@ -51,13 +51,17 @@ class TestGetConfig(utils.TestWithEnvClean):
         self.add_teardown('XDG_CONFIG_HOME')
         self.add_teardown('HOME')
 
-    def test_xdg_config_home(self):
-        """ get_config() finds $XDG_CONFIG_HOME/piglit.conf """
-        self.__unset_config()
+    def __move_local(self):
+        """ Move a local piglit.conf so it isn't overwritten """
         if os.path.exists('piglit.conf'):
             shutil.move('piglit.conf', 'piglit.conf.restore')
             self.defer(shutil.move, 'piglit.conf.restore', 'piglit.conf')
 
+    def test_xdg_config_home(self):
+        """ get_config() finds $XDG_CONFIG_HOME/piglit.conf """
+        self.__unset_config()
+        self.__move_local()
+
         with utils.tempdir() as tdir:
             os.environ['XDG_CONFIG_HOME'] = tdir
             with open(os.path.join(tdir, 'piglit.conf'), 'w') as f:
@@ -70,9 +74,7 @@ class TestGetConfig(utils.TestWithEnvClean):
     def test_config_home_fallback(self):
         """ get_config() finds $HOME/.config/piglit.conf """
         self.__unset_config()
-        if os.path.exists('piglit.conf'):
-            shutil.move('piglit.conf', 'piglit.conf.restore')
-            self.defer(shutil.move, 'piglit.conf.restore', 'piglit.conf')
+        self.__move_local()
 
         with utils.tempdir() as tdir:
             os.environ['HOME'] = tdir
@@ -87,9 +89,7 @@ class TestGetConfig(utils.TestWithEnvClean):
     def test_local(self):
         """ get_config() finds ./piglit.conf """
         self.__unset_config()
-        if os.path.exists('piglit.conf'):
-            shutil.move('piglit.conf', 'piglit.conf.restore')
-            self.defer(shutil.move, 'piglit.conf.restore', 'piglit.conf')
+        self.__move_local()
 
         with utils.tempdir() as tdir:
             self.defer(os.chdir, os.getcwd())
@@ -106,9 +106,7 @@ class TestGetConfig(utils.TestWithEnvClean):
     def test_piglit_root(self):
         """ get_config() finds "piglit root"/piglit.conf """
         self.__unset_config()
-        if os.path.exists('piglit.conf'):
-            shutil.move('piglit.conf', 'piglit.conf.restore')
-            self.defer(shutil.move, 'piglit.conf.restore', 'piglit.conf')
+        self.__move_local()
 
         with open('piglit.conf', 'w') as f:
             f.write(CONF_FILE)
-- 
2.0.4



More information about the Piglit mailing list