climate-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject [3/8] git commit: CLIMATE-416 - Fix test working directory issues
Date Sat, 10 May 2014 19:13:50 GMT
CLIMATE-416 - Fix test working directory issues

- Move working directory creation to package wide setup.
- Remove all working directory clean up calls from tests. The working
  directory used in the tests overlaps with the one used by the toolkit
  during actual evaluations. We can't remove the working directory if
  there are actual run results present, so instead cleanup is performed
  only on the additional artifacts that we create in the working
  directory.
- Fix bad directory tests. Many of the result listings were testing an
  older format that was no longer valid.
- Add a helper for cleaning the results listing responses to exclude any
  possible run folders from actual toolkit evaluations. Other tests that
  exercise the toolkit are also writing test results to this directory.
  Now any folders that are appropriated named are removed before the
  results listing is tested.
- Move WORK_DIR definition out of specific classes an into the module in
  test_directory_helpers.


Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/829c95dc
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/829c95dc
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/829c95dc

Branch: refs/heads/master
Commit: 829c95dcd644d24fc7742ccb1d5d9969a00adffe
Parents: e8ed85b
Author: Michael Joyce <joyce@apache.org>
Authored: Fri May 9 11:23:17 2014 -0700
Committer: Michael Joyce <joyce@apache.org>
Committed: Fri May 9 11:23:17 2014 -0700

----------------------------------------------------------------------
 ocw-ui/backend/tests/__init__.py               |  3 +
 ocw-ui/backend/tests/test_directory_helpers.py | 68 ++++++++++++---------
 ocw-ui/backend/tests/test_run_webservices.py   |  3 +-
 3 files changed, 43 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/829c95dc/ocw-ui/backend/tests/__init__.py
----------------------------------------------------------------------
diff --git a/ocw-ui/backend/tests/__init__.py b/ocw-ui/backend/tests/__init__.py
index 13a4ffd..9383cc6 100644
--- a/ocw-ui/backend/tests/__init__.py
+++ b/ocw-ui/backend/tests/__init__.py
@@ -11,3 +11,6 @@ def setup_package():
 
     if not os.path.exists('/tmp/d2.nc'):
         urlretrieve(FILE_LEADER + FILE_2, '/tmp/d2.nc')
+
+    if not os.path.exists('/tmp/ocw'):
+        os.mkdir('/tmp/ocw')

http://git-wip-us.apache.org/repos/asf/climate/blob/829c95dc/ocw-ui/backend/tests/test_directory_helpers.py
----------------------------------------------------------------------
diff --git a/ocw-ui/backend/tests/test_directory_helpers.py b/ocw-ui/backend/tests/test_directory_helpers.py
index b396d32..b2a8b22 100644
--- a/ocw-ui/backend/tests/test_directory_helpers.py
+++ b/ocw-ui/backend/tests/test_directory_helpers.py
@@ -1,4 +1,5 @@
 import os
+import re
 import unittest
 from webtest import TestApp
 
@@ -6,6 +7,7 @@ from ..run_webservices import app
 from ..directory_helpers import _get_clean_directory_path
 
 test_app = TestApp(app)
+WORK_DIR = '/tmp/ocw'
 
 class TestDirectoryPathList(unittest.TestCase):
     PATH_LEADER = '/usr/local/ocw'
@@ -43,62 +45,70 @@ class TestDirectoryPathList(unittest.TestCase):
         self.assertDictEqual(response.json, expected_return)
 
 class TestResultDirectoryList(unittest.TestCase):
-    WORK_DIR = '/tmp/ocw'
-
     def setUp(self):
-        if not os.path.exists(self.WORK_DIR): os.mkdir(self.WORK_DIR)
-        if not os.path.exists(self.WORK_DIR + '/foo'): os.mkdir(self.WORK_DIR + '/foo')
-        if not os.path.exists(self.WORK_DIR + '/bar'): os.mkdir(self.WORK_DIR + '/bar')
+        if not os.path.exists(WORK_DIR + '/foo'): os.mkdir(WORK_DIR + '/foo')
+        if not os.path.exists(WORK_DIR + '/bar'): os.mkdir(WORK_DIR + '/bar')
 
     @classmethod
     def tearDownClass(self):
-        if os.path.exists(self.WORK_DIR + '/foo'): os.rmdir(self.WORK_DIR + '/foo')
-        if os.path.exists(self.WORK_DIR + '/bar'): os.rmdir(self.WORK_DIR + '/bar')
-        if os.path.exists(self.WORK_DIR): os.rmdir(self.WORK_DIR)
+        if os.path.exists(WORK_DIR + '/foo'): os.rmdir(WORK_DIR + '/foo')
+        if os.path.exists(WORK_DIR + '/bar'): os.rmdir(WORK_DIR + '/bar')
 
     def test_result_listing(self):
-        expected_return = {'listing': ['/bar', '/foo']}
+        expected_return = {'listing': ['bar', 'foo']}
         response = test_app.get('http://localhost:8082/dir/results/')
-        self.assertDictEqual(response.json, expected_return)
+        response_json = self.clean_result_listing_json(response.json)
+        self.assertDictEqual(response_json, expected_return)
 
     def test_missing_work_dir_listing(self):
-        if os.path.exists(self.WORK_DIR + '/foo'): os.rmdir(self.WORK_DIR + '/foo')
-        if os.path.exists(self.WORK_DIR + '/bar'): os.rmdir(self.WORK_DIR + '/bar')
-        if os.path.exists(self.WORK_DIR): os.rmdir(self.WORK_DIR)
+        if os.path.exists(WORK_DIR + '/foo'): os.rmdir(WORK_DIR + '/foo')
+        if os.path.exists(WORK_DIR + '/bar'): os.rmdir(WORK_DIR + '/bar')
 
         expected_return = {'listing': []}
         response = test_app.get('http://localhost:8082/dir/results/')
-        self.assertDictEqual(response.json, expected_return)
+        response_json = self.clean_result_listing_json(response.json)
+        self.assertDictEqual(response_json, expected_return)
+
+    def clean_result_listing_json(self, response_json):
+        # The working directory that is being pulled for results is the actual directory
+        # that OCW uses when running evaluations on the system. It's possible that these
+        # tests are being run on a system where actual results are run. If that's the case,
+        # the listings for actual runs need to be removed before the results are check. The
+        # standard form for a result directory is a timestamp of YYYY-MM-DD_HH-MM-SS.
+        valid_directory = re.compile(r"\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}", re.UNICODE)
+        response_json['listing'] = [folder
+                                    for folder in response_json['listing']
+                                    if not re.search(valid_directory, folder)]
+        return response_json
 
 class TestResultResultRetrieval(unittest.TestCase):
-    WORK_DIR = '/tmp/ocw'
-
     @classmethod
     def setUpClass(self):
-        if not os.path.exists(self.WORK_DIR): os.mkdir(self.WORK_DIR)
-        if not os.path.exists(self.WORK_DIR + '/foo'): os.mkdir(self.WORK_DIR + '/foo')
+        if not os.path.exists(WORK_DIR + '/foo'): os.mkdir(WORK_DIR + '/foo')
 
-        if not os.path.exists(self.WORK_DIR + '/foo/baz.txt'):
-            open(self.WORK_DIR + '/foo/baz.txt', 'a').close()
-        if not os.path.exists(self.WORK_DIR + '/foo/test.txt'):
-            open(self.WORK_DIR + '/foo/test.txt', 'a').close()
+        if not os.path.exists(WORK_DIR + '/foo/baz.txt'):
+            open(WORK_DIR + '/foo/baz.txt', 'a').close()
+        if not os.path.exists(WORK_DIR + '/foo/test.txt'):
+            open(WORK_DIR + '/foo/test.txt', 'a').close()
 
     @classmethod
     def tearDownClass(self):
-        os.remove(self.WORK_DIR + '/foo/baz.txt')
-        os.remove(self.WORK_DIR + '/foo/test.txt')
-        os.rmdir(self.WORK_DIR + '/foo')
-        os.rmdir(self.WORK_DIR)
+        os.remove(WORK_DIR + '/foo/baz.txt')
+        os.remove(WORK_DIR + '/foo/test.txt')
+        os.rmdir(WORK_DIR + '/foo')
 
     def test_no_test_directory_retreival(self):
         expected_return = {'listing': []}
         response = test_app.get('http://localhost:8082/dir/results//bar')
-        self.assertDictEqual(response.json, expected_return)
+
+        response_json = response.json
+        self.assertDictEqual(response_json, expected_return)
 
     def test_results_retreival(self):
-        expected_return = {'listing': ['/foo/baz.txt', '/foo/test.txt']}
+        expected_return = {'listing': ['foo/baz.txt', 'foo/test.txt']}
         response = test_app.get('http://localhost:8082/dir/results//foo')
-        self.assertDictEqual(response.json, expected_return)
+        response_json = response.json
+        self.assertDictEqual(response_json, expected_return)
 
 class TestDirectoryPathCleaner(unittest.TestCase):
     PATH_LEADER = '/tmp/foo'

http://git-wip-us.apache.org/repos/asf/climate/blob/829c95dc/ocw-ui/backend/tests/test_run_webservices.py
----------------------------------------------------------------------
diff --git a/ocw-ui/backend/tests/test_run_webservices.py b/ocw-ui/backend/tests/test_run_webservices.py
index 492646c..c0d754b 100644
--- a/ocw-ui/backend/tests/test_run_webservices.py
+++ b/ocw-ui/backend/tests/test_run_webservices.py
@@ -15,18 +15,17 @@ class TestInitialization(unittest.TestCase):
 class TestStaticEvalResults(unittest.TestCase):
     @classmethod
     def setUpClass(self):
-        if not os.path.exists('/tmp/ocw'): os.mkdir('/tmp/ocw')
         if not os.path.exists('/tmp/ocw/foo.txt'): 
             open('/tmp/ocw/foo.txt', 'a').close()
 
     @classmethod
     def tearDownClass(self):
         os.remove('/tmp/ocw/foo.txt')
-        os.rmdir('/tmp/ocw')
 
     def test_static_eval_results_return(self):
         response = test_app.get('/static/eval_results//foo.txt')
 
         self.assertEqual(response.status_int, 200)
+
 if __name__ == '__main__':
     unittest.main()


Mime
View raw message