Commits

Dan Buch committed 7fc2c4b

Converting multi-version testing script to python so that I feel better about myself

  • Participants
  • Parent commits 52c1e50

Comments (0)

Files changed (1)

File test-python-versions

-#!/bin/bash
-# This is a very crude version compatibility script that cycles through a bunch
-# of python versions likely to still be in use (a wild guess, really.) The
-# script itself has only been tested on linux, so any feedback from Mac OSX and
-# cygwin users is much appreciated.
+#!/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
 
-HERE=$(dirname $(readlink -f $0))
-HAD_FAILURE=0
+import sys
+import os
+from subprocess import check_call, PIPE
 
-for version in 2.3 2.4 2.5 2.6 2.7 3.0 3.1 3.2
-do
-    "python${version}" -c "import sys" > /dev/null 2>&1
-    if [[ $? -eq 0 ]]
-    then
-        echo -n "Testing python${version}"
-        "python${version}" "${HERE}/scripts/reindent" -h > /dev/null 2>&1
-        if [[ $? -eq 0 ]]
-        then
-            # yes, it is *hilarious* that I'm using tabs in a script to
-            # test `reindent`
-            printf "\t...\tPASS\n"
-        else
-            HAD_FAILURE=1
-            printf "\t...\tFAIL\n"
-        fi
-    else
-        printf "python${version} not detected\t...\tSKIP\n"
-    fi
-done
 
-echo "------------------------------------"
-echo -n "Summary: "
+HERE = os.path.dirname(os.path.abspath(__file__))
+VERSIONS = ['2.3', '2.4', '2.5', '2.6', '2.7', '3.0', '3.1', '3.2']
 
-if [[ $HAD_FAILURE -eq 1 ]]
-then
-    echo "FAIL"
-else
-    echo "PASS"
-fi
 
-exit $HAD_FAILURE
+def main():
+    had_failure = False
+    passes = 0
+    reindent_script = os.path.join(HERE, 'scripts', 'reindent')
+    for version in VERSIONS:
+        exe = 'python{0}'.format(version)
+        try:
+            check_call([exe, '-c', 'import sys'], stdout=PIPE, stderr=PIPE)
+            print('+ Testing {0}'.format(exe), end='')
+            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
+            except OSError:
+                had_failure = True
+                print('\t\tFAIL')
+        except OSError:
+            print('- {0} not detected\tSKIP'.format(exe))
+
+    print('=' * 36)
+    print('Summary: ', end='')
+
+    if had_failure:
+        print('FAIL')
+    else:
+        print('PASS ({0}% awesomeness)'.format(
+            int(100 * (float(passes) / float(len(VERSIONS))))))
+
+
+if __name__ == '__main__':
+    sys.exit(main())