Skip to content

Commit

Permalink
use six library + fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
akolpakov committed Mar 14, 2016
1 parent 8f71d70 commit 92d6514
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 41 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
# add your dependencies here
# remember to use 'package-name>=x.y.z,<x.y+1.0' notation (this way you get bugfixes)
'django>=1.6,<1.9',
'six',
],
extras_require={
'tests': tests_require,
Expand Down
5 changes: 4 additions & 1 deletion tests/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
34 changes: 13 additions & 21 deletions tests/test_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
109 changes: 96 additions & 13 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,101 +7,184 @@

[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

[testenv:py27-1.7.X]
basepython = python2.7
commands =
make setup
make test
make test_no_coverage
deps =
Django>=1.7,<1.8

[testenv:py27-1.8.X]
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

[testenv:py33-1.7.X]
basepython = python3.3
commands =
make setup
make test
make test_no_coverage
deps =
Django>=1.7,<1.8

[testenv:py33-1.8.X]
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

[testenv:py34-1.7.X]
basepython = python3.4
commands =
make setup
make test
make test_no_coverage
deps =
Django>=1.7,<1.8

[testenv:py34-1.8.X]
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

[testenv:pypy-1.7.X]
basepython = pypy
commands =
make setup
make test
make test_no_coverage
deps =
Django>=1.7,<1.8

[testenv:pypy-1.8.X]
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

0 comments on commit 92d6514

Please sign in to comment.