Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to pytest #47

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ run_test:
@if [ -d tests/$(suite) ]; then \
echo "Running \033[0;32m$(suite)\033[0m test suite"; \
make prepare; \
nosetests --stop --with-coverage --cover-package=$(PACKAGE) \
--cover-branches --verbosity=2 -s tests/$(suite) ; \
pytest --cov=$(PACKAGE) tests/$(suite) ; \
fi

prepare: clean install_deps build_test_stub
Expand Down
3 changes: 2 additions & 1 deletion development.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
-r requirements.txt
nose==1.2.1
pytest
clarete marked this conversation as resolved.
Show resolved Hide resolved
pytest-cov
coverage==3.6
tox==1.4.3
27 changes: 13 additions & 14 deletions tests/unit/test_forbidden_fruit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@
from datetime import datetime
from forbiddenfruit import cursed, curses, curse, reverse
from types import FunctionType
from nose.tools import nottest, istest
import pytest

# Our stub! :)
from . import ffruit



def almost_equal(a, b, e=0.001):
"""Helper method to compare floats"""
return abs(a - b) < e


skip_legacy = nottest if sys.version_info < (3, 3) else istest

def test_cursing_a_builtin_class():

# Given that I have a function that returns *blah*
Expand Down Expand Up @@ -44,7 +41,7 @@ def hello(self):
assert 'hello' in dir(str)


@skip_legacy
@pytest.mark.skipif(sys.version_info < (3,3), reason="requires python3.3")
def test_cursing_a_builtin_class_dunder_with_a_random_callable():
# Given that I have an object that returns *blah*
class Twelver(object):
Expand Down Expand Up @@ -186,10 +183,10 @@ def test_dir_without_args_returns_names_in_local_scope():

# Then I see that `dir()` correctly returns a sorted list of those names
assert 'some_name' in dir()
assert dir() == sorted(locals().keys())
assert 'z' in dir()


@skip_legacy
@pytest.mark.skipif(sys.version_info < (3,3), reason="requires python3.3")
def test_dunder_func_chaining():
"""Overload * (mul) operator to to chaining between functions"""
def matmul_chaining(self, other):
Expand All @@ -213,7 +210,7 @@ def wrapper(*args, **kwargs):
assert squared(i) == i ** 2


@skip_legacy
@pytest.mark.skipif(sys.version_info < (3,3), reason="requires python3.3")
def test_dunder_list_map():
"""Overload * (__mul__) operator to apply function to a list"""
def map_list(func, list_):
Expand All @@ -229,7 +226,7 @@ def map_list(func, list_):
assert list(times_2 * list_) == list(range(0, 20, 2))


@skip_legacy
@pytest.mark.skipif(sys.version_info < (3,3), reason="requires python3.3")
def test_dunder_unary():
"""Overload ~ operator to compute a derivative of function"""
def derive_func(func):
Expand All @@ -251,7 +248,7 @@ def wrapper(x):
assert almost_equal((~f)(10), f_(10))


@skip_legacy
@pytest.mark.skipif(sys.version_info < (3,3), reason="requires python3.3")
def test_sequence_dunder():
def derive_func(func, deriv_grad):
if deriv_grad == 0:
Expand Down Expand Up @@ -279,7 +276,7 @@ def wrapper(x):
assert almost_equal(f_2(x), f[2](x), e=.01)


@skip_legacy
@pytest.mark.skipif(sys.version_info < (3,3), reason="requires python3.3")
def test_dunder_list_revert():
"""Test reversion of a curse with dunders"""
def map_list(func, list_):
Expand Down Expand Up @@ -312,15 +309,17 @@ def test_cursing_a_reversed_curse():
curse(str, 'one', 2)
assert str.one == 2

@skip_legacy

@pytest.mark.skipif(sys.version_info < (3,3), reason="requires python3.3")
def test_dunder_str():
assert str(1) == "1"
def always_one(self):
return 'one'
curse(int, '__str__', always_one)
assert str(1) == "one"

@skip_legacy

@pytest.mark.skipif(sys.version_info < (3,3), reason="requires python3.3")
def test_dunder_reverse():
def type_error_str(self):
return 'type error'
Expand Down Expand Up @@ -348,7 +347,7 @@ def test_cursed_context_manager():
assert "open_box" not in dir(dict)


@skip_legacy
@pytest.mark.skipif(sys.version_info < (3,3), reason="requires python3.3")
def test_cursed_decorator():
"The `cursed` decorator should curse an existing symbols during a function"

Expand Down
5 changes: 3 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
# and then run "tox" from this directory.

[tox]
envlist = py27, py30, py33, py34, py35, py36, py37
envlist = py27, py30, py33, py34, py35, py36, py37, py38

[testenv]
setenv =
FFRUIT_EXTENSION = true
whitelist_externals = make
commands = make
deps =
nose
pytest
pytest-cov
coverage