Dan Buch avatar Dan Buch committed 1d4a8c5

Converting test script to use unittest because I want to be a good person

Comments (0)

Files changed (1)

devscripts/smoketest.py

 #!/usr/bin/env python
-"""
-This is a very crude version compatibility script that cycles through a bunch
-of python versions likely (???) to still be in use.  The script itself has only
-been tested on linux, so any feedback from users on other platforms is much
-appreciated.
-"""
 from __future__ import print_function
 
+import logging
+import os
 import sys
+import unittest
+
 from os.path import dirname, abspath, join as pathjoin
-from subprocess import check_call, PIPE
+from subprocess import check_call, PIPE, CalledProcessError
 
 
-VERSIONS = ['2.3', '2.4', '2.5', '2.6', '2.7', '3.0', '3.1', '3.2']
-REINDENT_SCRIPT = pathjoin(
-    dirname(dirname(abspath(__file__))), 'scripts', 'reindent'
-)
+TOP = dirname(dirname(abspath(__file__)))
+sys.path.insert(0, TOP)
+os.environ['PYTHONPATH'] = \
+    os.environ.get('PYTHONPATH', '') + ':{0}'.format(TOP)
 
+REINDENT_SCRIPT = pathjoin(TOP, 'scripts', 'reindent')
+_LOGSETUP = {'done': False}
 
-def main():
-    had_failure = False
-    passes = 0
 
-    for version in VERSIONS:
-        exe = 'python{0}'.format(version)
+def setup_logging():
+    if _LOGSETUP['done']:
+        return
 
+    logging.basicConfig(file='./smoketest.log')
+    _LOGSETUP['done'] = True
+
+
+class TestReindentSystemVersion(unittest.TestCase):
+    _version = ''
+
+    def setUp(self):
+        if not self._has_version():
+            self.skip()
+        self.log = logging.getLogger('smoketest')
+
+    def tearDown(self):
+        self._clean_up_tempdir()
+
+    def _clean_up_tempdir(self):
+        pass
+
+    @property
+    def _exe(self):
+        return 'python{0}'.format(self._version)
+
+    def _has_version(self):
         try:
-            check_call([exe, '-c', 'import sys'], stdout=PIPE, stderr=PIPE)
-            print('+ Testing {0}'.format(exe), end='')
+            check_call([self._exe, '-c', 'import sys'],
+                       stdout=PIPE, stderr=PIPE)
+            return True
+        except OSError:
+            return False
 
-            try:
-                check_call([exe, REINDENT_SCRIPT, '-h'],
-                           stdout=PIPE, stderr=PIPE)
-                # yes, it is *hilarious* that I'm using tabs in a script to
-                # test `reindent`
-                print('\t\tPASS')
-                passes += 1
+    def test_version_can_execute_script(self):
+        try:
+            check_call([self._exe, REINDENT_SCRIPT, '-h'],
+                       stdout=PIPE, stderr=PIPE)
+        except CalledProcessError:
+            self.log.exception('Failed to execute script')
+            self.assertTrue(False, 'Can execute script')
 
-            except OSError:
-                had_failure = True
-                print('\t\tFAIL')
 
-        except OSError:
-            print('- {0} not detected\tSKIP'.format(exe))
+class TestReindentVersion23(TestReindentSystemVersion):
+    _version = '2.3'
 
-    print('=' * 36)
-    print('Summary: ', end='')
 
-    if had_failure:
-        print('FAIL')
-    else:
-        print('PASS ({0}% awesomeness)'.format(
-            int(100 * (float(passes) / float(len(VERSIONS))))))
+class TestReindentVersion24(TestReindentSystemVersion):
+    _version = '2.4'
+
+
+class TestReindentVersion25(TestReindentSystemVersion):
+    _version = '2.5'
+
+
+class TestReindentVersion26(TestReindentSystemVersion):
+    _version = '2.6'
+
+
+class TestReindentVersion27(TestReindentSystemVersion):
+    _version = '2.7'
+
+
+class TestReindentVersion30(TestReindentSystemVersion):
+    _version = '3.0'
+
+
+class TestReindentVersion31(TestReindentSystemVersion):
+    _version = '3.1'
+
+
+class TestReindentVersion32(TestReindentSystemVersion):
+    _version = '3.2'
 
 
 if __name__ == '__main__':
-    sys.exit(main())
+    setup_logging()
+    unittest.main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.