# HG changeset patch # User Dan Buch # Date 1323266424 18000 # Node ID 1d4a8c58002f3a294c33adcab884cd264c337aca # Parent 2c61743a0c5e6d40a50b322b01bcf02f2dcf75e8 Converting test script to use unittest because I want to be a good person diff -r 2c61743a0c5e6d40a50b322b01bcf02f2dcf75e8 -r 1d4a8c58002f3a294c33adcab884cd264c337aca devscripts/smoketest.py --- a/devscripts/smoketest.py Wed Dec 07 08:08:40 2011 -0500 +++ b/devscripts/smoketest.py Wed Dec 07 09:00:24 2011 -0500 @@ -1,58 +1,99 @@ #!/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()