From 92d6514609c9bd0ce128a59e7414edd1de5c5ed2 Mon Sep 17 00:00:00 2001 From: Andrey Kolpakov Date: Mon, 14 Mar 2016 12:43:56 +0100 Subject: [PATCH] use six library + fix tests --- Makefile | 3 + .../commands/cleanup_unused_media.py | 8 +- setup.py | 1 + tests/runtests.py | 5 +- tests/test_cleanup.py | 34 +++--- tox.ini | 109 +++++++++++++++--- 6 files changed, 119 insertions(+), 41 deletions(-) diff --git a/Makefile b/Makefile index bd7b0c2..ba5cddc 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,9 @@ unit: coverage-html: unit @coverage html +test_no_coverage: + python ./tests/runtests.py + # run tests against all supported python versions tox: @tox diff --git a/django_unused_media/management/commands/cleanup_unused_media.py b/django_unused_media/management/commands/cleanup_unused_media.py index 8a172de..041565e 100644 --- a/django_unused_media/management/commands/cleanup_unused_media.py +++ b/django_unused_media/management/commands/cleanup_unused_media.py @@ -2,6 +2,7 @@ from django.conf import settings from django.core.management.base import BaseCommand +import six.moves from django_unused_media.cleanup import get_unused_media, remove_empty_dirs @@ -41,14 +42,9 @@ def handle(self, *args, **options): for f in unused_media: self.stdout.write(f) - # raw_input for python2 and input for python3 - - try: input = raw_input - except NameError: pass - # ask user - if input('Are you sure you want to remove %s unused files? (Y/n)' % len(unused_media)) != 'Y': + if six.moves.input('Are you sure you want to remove %s unused files? (Y/n)' % len(unused_media)) != 'Y': self.stdout.write('Interrupted by user. Exit.') return diff --git a/setup.py b/setup.py index fca8a5c..11eadf1 100755 --- a/setup.py +++ b/setup.py @@ -59,6 +59,7 @@ # add your dependencies here # remember to use 'package-name>=x.y.z,=1.6,<1.9', + 'six', ], extras_require={ 'tests': tests_require, diff --git a/tests/runtests.py b/tests/runtests.py index 92812bd..b85d278 100644 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -8,4 +8,7 @@ if __name__ == '__main__': - NoseTestSuiteRunner(verbosity=1).run_tests(['tests']) + if NoseTestSuiteRunner(verbosity=1).run_tests(['tests']) > 0: + exit(1) + else: + exit(0) diff --git a/tests/test_cleanup.py b/tests/test_cleanup.py index c956a23..6032a26 100644 --- a/tests/test_cleanup.py +++ b/tests/test_cleanup.py @@ -163,33 +163,25 @@ def test_command_not_interactive(self): expect(exists_media_path('file.txt')).to_be_false() - def _patch_row_input(self, value): - if _ver >= (3, 0): - builtins_raw_input = 'builtins.input' - else: - builtins_raw_input = '__builtin__.raw_input' - - return mock.patch(builtins_raw_input, return_value=value) - - def test_command_interactive_n(self): + @mock.patch('six.moves.input', return_value='n') + def test_command_interactive_n(self, mock_input): create_file_and_write('file.txt') - with self._patch_row_input('n'): - cmd = Command() - cmd.handle(interactive=True) - expect(cmd.stdout.getvalue().split('\n'))\ - .to_include('Interrupted by user. Exit.') + cmd = Command() + cmd.handle(interactive=True) + expect(cmd.stdout.getvalue().split('\n'))\ + .to_include('Interrupted by user. Exit.') expect(exists_media_path('file.txt')).to_be_true() - def test_command_interactive_y(self): + @mock.patch('six.moves.input', return_value='Y') + def test_command_interactive_y(self, mock_input): create_file_and_write('file.txt') - with self._patch_row_input('Y'): - cmd = Command() - cmd.handle(interactive=True) - expect(cmd.stdout.getvalue().split('\n'))\ - .to_include('Remove file.txt')\ - .to_include('Done. 1 unused files have been removed') + cmd = Command() + cmd.handle(interactive=True) + expect(cmd.stdout.getvalue().split('\n'))\ + .to_include('Remove file.txt')\ + .to_include('Done. 1 unused files have been removed') expect(exists_media_path('file.txt')).to_be_false() diff --git a/tox.ini b/tox.ini index 0646703..1e26131 100644 --- a/tox.ini +++ b/tox.ini @@ -7,14 +7,33 @@ [tox] envlist = - py27-1.6.X, py27-1.7.X, py27-1.8.X, py33-1.6.X, py33-1.7.X, py33-1.8.X, py34-1.6.X, py34-1.7.X, py34-1.8.X, pypy-1.6.X, pypy-1.7.X, pypy-1.8.X + py27-1.6.X, + py27-1.7.X, + py27-1.8.X, + py27-1.9.X, + py33-1.6.X, + py33-1.7.X, + py33-1.8.X, + py33-1.9.X, + py34-1.6.X, + py34-1.7.X, + py34-1.8.X, + py34-1.9.X, + py35-1.6.X, + py35-1.7.X, + py35-1.8.X, + py35-1.9.X, + pypy-1.6.X, + pypy-1.7.X, + pypy-1.8.X, + pypy-1.9.X downloadcache = .tox/_download/ [testenv:py27-1.6.X] basepython = python2.7 commands = make setup - make test + make test_no_coverage deps = Django>=1.6,<1.7 @@ -22,7 +41,7 @@ deps = basepython = python2.7 commands = make setup - make test + make test_no_coverage deps = Django>=1.7,<1.8 @@ -30,15 +49,23 @@ deps = basepython = python2.7 commands = make setup - make test + make test_no_coverage deps = Django>=1.8,<1.9 +[testenv:py27-1.9.X] +basepython = python2.7 +commands = + make setup + make test_no_coverage +deps = + Django>=1.9,<1.10 + [testenv:py33-1.6.X] basepython = python3.3 commands = make setup - make test + make test_no_coverage deps = Django>=1.6,<1.7 @@ -46,7 +73,7 @@ deps = basepython = python3.3 commands = make setup - make test + make test_no_coverage deps = Django>=1.7,<1.8 @@ -54,15 +81,23 @@ deps = basepython = python3.3 commands = make setup - make test + make test_no_coverage deps = Django>=1.8,<1.9 +[testenv:py33-1.9.X] +basepython = python3.3 +commands = + make setup + make test_no_coverage +deps = + Django>=1.9,<1.10 + [testenv:py34-1.6.X] basepython = python3.4 commands = make setup - make test + make test_no_coverage deps = Django>=1.6,<1.7 @@ -70,7 +105,7 @@ deps = basepython = python3.4 commands = make setup - make test + make test_no_coverage deps = Django>=1.7,<1.8 @@ -78,15 +113,55 @@ deps = basepython = python3.4 commands = make setup - make test + make test_no_coverage deps = Django>=1.8,<1.9 +[testenv:py34-1.9.X] +basepython = python3.4 +commands = + make setup + make test_no_coverage +deps = + Django>=1.9,<1.10 + +[testenv:py35-1.6.X] +basepython = python3.5 +commands = + make setup + make test_no_coverage +deps = + Django>=1.6,<1.7 + +[testenv:py35-1.7.X] +basepython = python3.5 +commands = + make setup + make test_no_coverage +deps = + Django>=1.7,<1.8 + +[testenv:py35-1.8.X] +basepython = python3.5 +commands = + make setup + make test_no_coverage +deps = + Django>=1.8,<1.9 + +[testenv:py35-1.9.X] +basepython = python3.5 +commands = + make setup + make test_no_coverage +deps = + Django>=1.9,<1.10 + [testenv:pypy-1.6.X] basepython = pypy commands = make setup - make test + make test_no_coverage deps = Django>=1.6,<1.7 @@ -94,7 +169,7 @@ deps = basepython = pypy commands = make setup - make test + make test_no_coverage deps = Django>=1.7,<1.8 @@ -102,6 +177,14 @@ deps = basepython = pypy commands = make setup - make test + make test_no_coverage deps = Django>=1.8,<1.9 + +[testenv:pypy-1.9.X] +basepython = pypy +commands = + make setup + make test_no_coverage +deps = + Django>=1.9,<1.10