From d4a8c04610abb360b93d66a35667275252c20afc Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Mon, 12 Mar 2012 09:34:46 -0700 Subject: [PATCH] Tests pass in py26 now. --- pecan/tests/test_templates.py | 53 ++++++++++++++++++++--------------- setup.py | 3 ++ 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/pecan/tests/test_templates.py b/pecan/tests/test_templates.py index 2e0f514..225378a 100644 --- a/pecan/tests/test_templates.py +++ b/pecan/tests/test_templates.py @@ -1,14 +1,19 @@ import os +import sys import tempfile import shutil import subprocess -import unittest import pkg_resources import httplib import urllib2 import time import pecan +if sys.version_info < (2, 7): + import unittest2 as unittest +else: + import unittest + def has_internet(): try: @@ -27,34 +32,26 @@ class TestTemplateBuilds(unittest.TestCase): install_dir = tempfile.mkdtemp() cwd = os.getcwd() - @classmethod - @unittest.skipUnless(has_internet(), 'Internet connectivity unavailable.') - @unittest.skipUnless( - getattr(pecan, '__run_all_tests__', False) is True, - 'Skipping (really slow). To run, `$ python setup.py test --functional.`' - ) - def setUpClass(cls): + def setUp(self): # Make a temp install location and record the cwd - cls.install() + self.install() - @classmethod - def tearDownClass(cls): - shutil.rmtree(cls.install_dir) - os.chdir(cls.cwd) + def tearDown(self): + shutil.rmtree(self.install_dir) + os.chdir(self.cwd) - @classmethod - def install(cls): + def install(self): # Create a new virtualenv in the temp install location import virtualenv virtualenv.create_environment( - cls.install_dir, + self.install_dir, site_packages=False ) # chdir into the pecan source os.chdir(pkg_resources.get_distribution('pecan').location) - py_exe = os.path.join(cls.install_dir, 'bin', 'python') - pecan_exe = os.path.join(cls.install_dir, 'bin', 'pecan') + py_exe = os.path.join(self.install_dir, 'bin', 'python') + pecan_exe = os.path.join(self.install_dir, 'bin', 'pecan') # env/bin/python setup.py develop (pecan) subprocess.check_call([ @@ -63,7 +60,7 @@ class TestTemplateBuilds(unittest.TestCase): 'develop' ]) # create the templated project - os.chdir(cls.install_dir) + os.chdir(self.install_dir) subprocess.check_call([pecan_exe, 'create', 'Testing123']) # move into the new project directory and install @@ -87,8 +84,12 @@ class TestTemplateBuilds(unittest.TestCase): raise RuntimeError("pecan serve config.py didn't start.") @unittest.skipUnless(has_internet(), 'Internet connectivity unavailable.') + @unittest.skipUnless( + getattr(pecan, '__run_all_tests__', False) is True, + 'Skipping (really slow). To run, `$ python setup.py test --functional.`' + ) def test_project_pecan_serve_command(self): - pecan_exe = os.path.join(self.__class__.install_dir, 'bin', 'pecan') + pecan_exe = os.path.join(self.install_dir, 'bin', 'pecan') # Start the server proc = subprocess.Popen([ @@ -110,9 +111,13 @@ class TestTemplateBuilds(unittest.TestCase): proc.terminate() @unittest.skipUnless(has_internet(), 'Internet connectivity unavailable.') + @unittest.skipUnless( + getattr(pecan, '__run_all_tests__', False) is True, + 'Skipping (really slow). To run, `$ python setup.py test --functional.`' + ) def test_project_pecan_shell_command(self): from pecan.testing import load_test_app - pecan_exe = os.path.join(self.__class__.install_dir, 'bin', 'pecan') + pecan_exe = os.path.join(self.install_dir, 'bin', 'pecan') # Start the server proc = subprocess.Popen([ @@ -139,8 +144,12 @@ class TestTemplateBuilds(unittest.TestCase): pass @unittest.skipUnless(has_internet(), 'Internet connectivity unavailable.') + @unittest.skipUnless( + getattr(pecan, '__run_all_tests__', False) is True, + 'Skipping (really slow). To run, `$ python setup.py test --functional.`' + ) def test_project_tests_command(self): - py_exe = os.path.join(self.__class__.install_dir, 'bin', 'python') + py_exe = os.path.join(self.install_dir, 'bin', 'python') # Run the tests proc = subprocess.Popen([ diff --git a/setup.py b/setup.py index feda8aa..e79e2f0 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,4 @@ +import sys from setuptools import setup, command, find_packages from setuptools.command.test import test as TestCommand @@ -26,6 +27,8 @@ except: requirements.append("simplejson >= 2.1.1") tests_require = requirements + ['virtualenv'] +if sys.version_info < (2, 7): + tests_require += ['unittest2'] class test(TestCommand):