# HG changeset patch # User Dan Buch # Date 1323234034 18000 # Node ID 7fc2c4bb264a05f5ef48232c28a72ac773506f11 # Parent 52c1e50e7525bb22f22c1ee4dc7bef7139bc7258 Converting multi-version testing script to python so that I feel better about myself diff -r 52c1e50e7525bb22f22c1ee4dc7bef7139bc7258 -r 7fc2c4bb264a05f5ef48232c28a72ac773506f11 test-python-versions --- a/test-python-versions Sun Dec 04 08:59:36 2011 -0500 +++ b/test-python-versions Wed Dec 07 00:00:34 2011 -0500 @@ -1,41 +1,52 @@ -#!/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())