# HG changeset patch # User Dan Buch # Date 1323440032 18000 # Node ID f325a4ed20c3c8db0767ca66cfa0f1a095bb71a6 # Parent 20d09e2642ae52f59aaaae72f93328cca4419ea7 Filling in more actual testing in the smoke test, touching up setup script along the way diff -r 20d09e2642ae52f59aaaae72f93328cca4419ea7 -r f325a4ed20c3c8db0767ca66cfa0f1a095bb71a6 .hgignore --- a/.hgignore Wed Dec 07 09:08:43 2011 -0500 +++ b/.hgignore Fri Dec 09 09:13:52 2011 -0500 @@ -1,4 +1,4 @@ -.*\.pyc +.*\.(pyc|log) ^build$ ^dist$ ^MANIFEST.*$ diff -r 20d09e2642ae52f59aaaae72f93328cca4419ea7 -r f325a4ed20c3c8db0767ca66cfa0f1a095bb71a6 devscripts/smoketest.py --- a/devscripts/smoketest.py Wed Dec 07 09:08:43 2011 -0500 +++ b/devscripts/smoketest.py Fri Dec 09 09:13:52 2011 -0500 @@ -4,19 +4,21 @@ import logging import os import sys +import time import unittest -from os.path import dirname, abspath, join as pathjoin -from subprocess import check_call, PIPE, CalledProcessError +from os import mkdir +from os.path import dirname, abspath, isdir, join as pathjoin +from shutil import rmtree, copytree +from subprocess import check_call, Popen, PIPE, CalledProcessError +from tempfile import mkdtemp 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') -INPUTS_DIR = pathjoin(TOP, 'devscripts', 'inputs') +ORIG_SYSPATH = sys.path[:] +ORIG_PYTHONPATH = os.environ.get('PYTHONPATH', '') +ORIG_PATH = os.environ.get('PATH', '') +ORIG_CWD = os.getcwd() _LOGSETUP = {'done': False} @@ -24,28 +26,99 @@ if _LOGSETUP['done']: return - logging.basicConfig(file='./smoketest.log') + logging.basicConfig(filename=pathjoin(ORIG_CWD, 'reindent-smoketest.log'), + level=logging.DEBUG) _LOGSETUP['done'] = True class TestReindentSystemVersion(unittest.TestCase): _version = '' + _tempdir = '' def setUp(self): if not self._has_version(): raise Exception('Cannot test version {0}'.format(self._version)) - self.log = logging.getLogger('smoketest') + self.log = logging.getLogger() + + self.log.info('Setting up for `{0}`'.format(self._exe)) + self._set_up_tempdir() + os.chdir(self._code_root) + self._install_in_tempdir() + os.chdir(self._tempdir) + + sys.path.insert(0, self._install_lib) + os.environ['PYTHONPATH'] = \ + ORIG_PYTHONPATH + ':{0}'.format(self._install_lib) + os.environ['PATH'] = ORIG_PATH + ':{0}'.format(self._install_scripts) def tearDown(self): + self.log.info('Tearing down up for `{0}`'.format(self._exe)) self._clean_up_tempdir() + sys.path[:] = ORIG_SYSPATH + os.environ['PYTHONPATH'] = ORIG_PYTHONPATH + os.environ['PATH'] = ORIG_PATH + + def _set_up_tempdir(self): + self._tempdir = mkdtemp( + prefix='reindent-smoketest-{0}-{1}-'.format( + self._version, time.time() + ) + ) + if not isdir(self._code_root): + copytree(TOP, self._code_root) + if not isdir(self._install_root): + mkdir(self._install_root) + mkdir(self._install_lib) + mkdir(self._install_scripts) + + def _install_in_tempdir(self): + try: + check_call([ + self._exe, self._setup_script, 'install', + '--install-lib', self._install_lib, + '--install-scripts', self._install_scripts, + ], stdout=PIPE, stderr=PIPE + ) + except CalledProcessError: + self.log.exception('Failed to install') + self.assertTrue(False, 'Can install') + def _clean_up_tempdir(self): - pass + rmtree(self._tempdir) @property def _exe(self): return 'python{0}'.format(self._version) + @property + def _setup_script(self): + return pathjoin(self._code_root, 'setup.py') + + @property + def _reindent_script(self): + return pathjoin(self._install_scripts, 'reindent') + + @property + def _inputs_dir(self): + return pathjoin(self._code_root, 'devscripts', 'inputs') + + @property + def _code_root(self): + return pathjoin(self._tempdir, 'code-root') + + @property + def _install_root(self): + return pathjoin(self._tempdir, 'install-root') + + @property + def _install_lib(self): + return pathjoin(self._install_root, 'lib') + + @property + def _install_scripts(self): + return pathjoin(self._install_root, 'bin') + def _has_version(self): try: check_call([self._exe, '-c', 'import sys'], @@ -56,23 +129,39 @@ def test_version_can_execute_script(self): try: - check_call([self._exe, REINDENT_SCRIPT, '-h'], - stdout=PIPE, stderr=PIPE) + command = [self._exe, self._reindent_script, '-h'] + self.log.info('Executing %s', ' '.join(command)) + check_call(command, stdout=PIPE, stderr=PIPE) except CalledProcessError: self.log.exception('Failed to execute script') self.assertTrue(False, 'Can execute script') - def test_version_can_reindent_twospaces(self): - pass + def test_is_importing_correct_library(self): + try: + job = Popen([self._exe, '-c', + 'import reindent, sys;' + + 'sys.stdout.write(reindent.__file__.replace(".pyc", ".py"))'], + stdout=PIPE, stderr=PIPE + ) + expected_lib = pathjoin(self._install_lib, 'reindent', '__init__.py') + self.log.debug('Expected library path is %s', expected_lib) + out = job.communicate()[0] + self.assertEqual(expected_lib, out.strip(), 'Is importing correct library') + except CalledProcessError: + self.log.exception('Failed to import library') + self.assertTrue(False, 'Can import library') - def test_version_can_reindent_tabs(self): - pass + #def test_version_can_reindent_twospaces(self): + #pass - def test_version_can_reindent_non_python(self): - pass + #def test_version_can_reindent_tabs(self): + #pass - def test_version_can_reindent_hot_mess(self): - pass + #def test_version_can_reindent_non_python(self): + #pass + + #def test_version_can_reindent_hot_mess(self): + #pass class TestReindentVersion23(TestReindentSystemVersion): diff -r 20d09e2642ae52f59aaaae72f93328cca4419ea7 -r f325a4ed20c3c8db0767ca66cfa0f1a095bb71a6 setup.py --- a/setup.py Wed Dec 07 09:08:43 2011 -0500 +++ b/setup.py Fri Dec 09 09:13:52 2011 -0500 @@ -4,32 +4,45 @@ from distutils.core import setup +SETUP_ARGS = dict( + name='Reindent', + version='0.2.0', + author='Tim Peters', + author_email='nottimsemail@notadomain.foo', + scripts=['./scripts/reindent'], + packages=[ + 'reindent', + 'reindent.v23', + 'reindent.v24', + 'reindent.v25', + 'reindent.v26', + 'reindent.v27', + 'reindent.v30', + 'reindent.v31', + 'reindent.v32', + ], + maintainer='Dan Buch', + maintainer_email='dan@meatballhat.com', + description='reindent script by Tim Peters', + keywords=['reindent', 'pep8', 'syntax', 'lint', 'tab', 'space'], + classifiers=[ + 'Development Status :: 6 - Mature', + 'Environment :: Console', + 'Intended Audience :: Developers', + 'License :: Public Domain', + 'Natural Language :: English', + 'Programming Language :: Python', + 'Topic :: Software Development :: Quality Assurance', + ], + long_description='', + platforms=['any'], + license='Public Domain' +) + + def main(): - setup( - name='Reindent', - version='0.2.0', - author="Tim Peters", - author_email='nottimsemail@notadomain.foo', - scripts=['./scripts/reindent'], - packages=['reindent'], - maintainer="Dan Buch", - maintainer_email="dan@meatballhat.com", - description='reindent script by Tim Peters', - keywords=['reindent', 'pep8', 'syntax', 'lint', 'tab', 'space'], - classifiers=[ - "Development Status :: 6 - Mature", - "Environment :: Console", - "Intended Audience :: Developers", - "License :: Public Domain", - "Natural Language :: English", - "Programming Language :: Python", - "Topic :: Software Development :: Quality Assurance", - ], - long_description=open('README.txt').read(), - platforms=['any'], - license="Public Domain" - ) - + SETUP_ARGS['long_description'] = open('README.txt').read() + setup(**SETUP_ARGS) return 0