Skip to content

Commit

Permalink
Python 2.6 support
Browse files Browse the repository at this point in the history
- Add argparse to install_requires if necessary
- Add and use unittest2 to get 'with self.assertRaises() as cm:'
- Avoid 'with a, b, c:', use nested with statements
- Reimplement subprocess.check_output inline in the tests

Closes #22
  • Loading branch information
mgedmin committed Jan 30, 2014
1 parent 4ef4a32 commit d317fa9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Changelog
* Friendlier error message when an external command cannot be found
(`issue #21 <https://github.com/mgedmin/check-manifest/issues/21>`__).
* Add suggestion pattern for `.coveragerc`.
* Python 2.6 support
(`issue #22 <https://github.com/mgedmin/check-manifest/issues/22>`__).


0.17 (2013-10-10)
Expand Down
12 changes: 9 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#!/usr/bin/env python
import os, re, ast, email.utils
import os, re, ast, email.utils, sys
from setuptools import setup

if sys.version_info < (2, 6):
sys.exit("Python 2.6 or newer is required for check-manifest")

PY26 = (sys.version_info[:2] == (2, 6))

here = os.path.dirname(__file__)

with open(os.path.join(here, 'README.rst')) as readme:
Expand Down Expand Up @@ -40,6 +45,7 @@
'License :: uhh, dunno',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
Expand All @@ -51,8 +57,8 @@
py_modules=['check_manifest'],
zip_safe=False,
test_suite='tests.test_suite',
install_requires=[],
tests_require=['mock'],
install_requires=['argparse'] if PY26 else [],
tests_require=['mock'] + (['unittest2'] if PY26 else []),
entry_points={
'console_scripts': [
'check-manifest = check_manifest:main',
Expand Down
30 changes: 19 additions & 11 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import sys
import tempfile
import textwrap
import unittest
try:
import unittest2 as unittest # Python 2.6
except ImportError:
import unittest

try:
from cStringIO import StringIO # Python 2.x
Expand Down Expand Up @@ -50,11 +53,14 @@ def test_run_no_such_program(self):
def test_copy_files(self):
from check_manifest import copy_files
actions = []
with mock.patch('os.path.isdir', lambda d: d in ('b', '/dest/dir')), \
mock.patch('os.makedirs', lambda d: actions.append('makedirs %s' % d)), \
mock.patch('os.mkdir', lambda d: actions.append('mkdir %s' % d)), \
mock.patch('shutil.copy2', lambda s, d: actions.append('cp %s %s' % (s, d))):
copy_files(['a', 'b', 'c/d/e'], '/dest/dir')
with mock.patch('os.path.isdir', lambda d: d in ('b', '/dest/dir')):
with mock.patch('os.makedirs',
lambda d: actions.append('makedirs %s' % d)):
with mock.patch('os.mkdir',
lambda d: actions.append('mkdir %s' % d)):
with mock.patch('shutil.copy2',
lambda s, d: actions.append('cp %s %s' % (s, d))):
copy_files(['a', 'b', 'c/d/e'], '/dest/dir')
self.assertEqual(
actions,
[
Expand Down Expand Up @@ -385,12 +391,14 @@ def tearDown(self):
shutil.rmtree(self.tmpdir)

def _run(self, *command):
try:
subprocess.check_output(command, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
p = subprocess.Popen(command, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
stdout, stderr = p.communicate()
rc = p.wait()
if rc:
print(' '.join(command))
print(e.output)
raise
print(stdout)
raise subprocess.CalledProcessError(rc, command[0], output=stdout)

def _create_file(self, filename):
assert not os.path.isabs(filename)
Expand Down
7 changes: 6 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
[tox]
envlist =
py27,py32,py33,pypy
py26,py27,py32,py33,pypy

[testenv]
deps =
mock
commands =
python setup.py test -q

[testenv:py26]
deps =
{[testenv]deps}
unittest2

[testenv:coverage]
deps =
{[testenv]deps}
Expand Down

0 comments on commit d317fa9

Please sign in to comment.