Skip to content

Commit

Permalink
Fix missing argument zero in mocked argv
Browse files Browse the repository at this point in the history
Refactor tests for directory cleaning
  • Loading branch information
bittner committed May 7, 2019
1 parent 56eefef commit 4f8d8a6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
21 changes: 12 additions & 9 deletions tests/test_directory.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
"""
Tests for the cleaning logic on folders
"""
import os
import platform
import pytest
import sys

import pyclean.cli

from helpers import ArgvContext


@pytest.mark.skipif(sys.version_info >= (3,), reason="requires Python 2")
def test_directory_py2():
"""
Does traversing directories for cleaning work for Python 2?
"""
exit_status = os.system('pyclean foo')
assert exit_status == 0
with ArgvContext('pyclean', 'foo'):
pyclean.cli.pyclean()


@pytest.mark.skipif(sys.version_info < (3,), reason="requires Python 3")
def test_directory_py3():
"""
Does traversing directories for cleaning work for Python 3?
"""
exit_status = os.system('py3clean foo')
assert exit_status == 0
with ArgvContext('py3clean', 'foo'):
pyclean.cli.py3clean()


@pytest.mark.skipif(platform.python_implementation() != 'PyPy'
Expand All @@ -32,8 +35,8 @@ def test_directory_pypy():
"""
Does traversing directories for cleaning work for PyPy?
"""
exit_status = os.system('pypyclean foo')
assert exit_status == 0
with ArgvContext('pypyclean', 'foo'):
pyclean.cli.pypyclean()


@pytest.mark.skipif(platform.python_implementation() != 'PyPy'
Expand All @@ -43,5 +46,5 @@ def test_directory_pypy3():
"""
Does traversing directories for cleaning work for PyPy3?
"""
exit_status = os.system('pypyclean foo')
assert exit_status == 0
with ArgvContext('pypyclean', 'foo'):
pyclean.cli.pypyclean()
23 changes: 17 additions & 6 deletions tests/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
import pytest
import sys

try:
from unittest.mock import patch
except ImportError: # Python 2.7, PyPy2
from mock import patch

import pyclean.cli

from helpers import ArgvContext
Expand All @@ -15,7 +20,7 @@ def test_package_py2():
"""
Does collecting/traversing packages for cleaning work for Python 2?
"""
with ArgvContext('-p', 'python-apt'):
with ArgvContext('pyclean', '-p', 'python-apt'):
pyclean.cli.pyclean()


Expand All @@ -24,27 +29,33 @@ def test_package_py3():
"""
Does collecting/traversing packages for cleaning work for Python 3?
"""
with ArgvContext('-p', 'python-apt'):
with ArgvContext('py3clean', '-p', 'python-apt'):
pyclean.cli.py3clean()


@pytest.mark.skipif(platform.python_implementation() != 'PyPy'
or sys.version_info >= (3,),
reason="requires PyPy2")
def test_package_pypy():
@patch('pyclean.pypyclean.installed_namespaces', return_value={})
def test_package_pypy(mock_namespaces):
"""
Does collecting/traversing packages for cleaning work for PyPy?
"""
with ArgvContext('-p', 'python-apt'):
with ArgvContext('pypyclean', '-p', 'python-apt'):
pyclean.cli.pypyclean()

assert mock_namespaces.called


@pytest.mark.skipif(platform.python_implementation() != 'PyPy'
or sys.version_info < (3,),
reason="requires PyPy3")
def test_package_pypy3():
@patch('pyclean.pypyclean.installed_namespaces', return_value={})
def test_package_pypy3(mock_namespaces):
"""
Does collecting/traversing packages for cleaning work for PyPy3?
"""
with ArgvContext('-p', 'python-apt'):
with ArgvContext('pypyclean', '-p', 'python-apt'):
pyclean.cli.pypyclean()

assert mock_namespaces.called
8 changes: 4 additions & 4 deletions tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_filterversion_py2():
"""
Does filtering by Python version work when run with Python 2?
"""
with ArgvContext('-V', '2.7', '-p', 'python-apt'):
with ArgvContext('pyclean', '-V', '2.7', '-p', 'python-apt'):
pyclean.cli.pyclean()


Expand All @@ -29,7 +29,7 @@ def test_filterversion_py3():
"""
Does filtering by Python version work when run with Python 3?
"""
with ArgvContext('-V', '3.5', '-p', 'python-apt'):
with ArgvContext('py3clean', '-V', '3.5', '-p', 'python-apt'):
pyclean.cli.py3clean()


Expand All @@ -41,7 +41,7 @@ def test_filterversion_pypy(mock_namespaces):
"""
Does filtering by Python version work when run with PyPy?
"""
with ArgvContext('-V', '2.7', '-p', 'python-apt'):
with ArgvContext('pypyclean', '-V', '2.7', '-p', 'python-apt'):
pyclean.cli.pypyclean()

assert mock_namespaces.called
Expand All @@ -55,7 +55,7 @@ def test_filterversion_pypy3(mock_namespaces):
"""
Does filtering by Python version work when run with PyPy3?
"""
with ArgvContext('-V', '3.5', '-p', 'python-apt'):
with ArgvContext('pypyclean', '-V', '3.5', '-p', 'python-apt'):
pyclean.cli.pypyclean()

assert mock_namespaces.called

0 comments on commit 4f8d8a6

Please sign in to comment.