Skip to content

Commit

Permalink
Move to pytest for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
boxed committed Oct 30, 2018
1 parent a4620f6 commit b39ca01
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 26 deletions.
8 changes: 6 additions & 2 deletions Makefile
Expand Up @@ -6,13 +6,17 @@ init:

test:
rm -f .coverage
nosetests $(NOSE_ARGS) ./tests/
pytest

travis:
nosetests --with-coverage ./tests/
pytest --cov

tdaemon:
tdaemon -t nose ./tests/ --custom-args="--with-growl"

publish:
python setup.py sdist bdist_wheel upload

venv:
virtualenv venv
venv/bin/pip install -r requirements.txt
5 changes: 3 additions & 2 deletions requirements.txt
@@ -1,5 +1,6 @@
coverage==3.7.1
coverage
pytest-coverage
coveralls
mock
nose
pytest
maya; python_version == '2.7' or python_version >= '3.6'
6 changes: 3 additions & 3 deletions tests/test_asyncio.py
@@ -1,7 +1,7 @@
import datetime
from textwrap import dedent
from unittest import SkipTest

from nose.plugins import skip

from freezegun import freeze_time

Expand All @@ -13,7 +13,7 @@

def test_time_freeze_coroutine():
if not asyncio:
raise skip.SkipTest('asyncio required')
raise SkipTest('asyncio required')
@asyncio.coroutine
@freeze_time('1970-01-01')
def frozen_coroutine():
Expand All @@ -26,7 +26,7 @@ def test_time_freeze_async_def():
try:
exec('async def foo(): pass')
except SyntaxError:
raise skip.SkipTest('async def not supported')
raise SkipTest('async def not supported')
else:
exec(dedent('''
@freeze_time('1970-01-01')
Expand Down
15 changes: 8 additions & 7 deletions tests/test_datetimes.py
Expand Up @@ -3,9 +3,9 @@
import unittest
import locale
import sys
from unittest import SkipTest

from nose.plugins import skip
from nose.tools import assert_raises
import pytest
from tests import utils

from freezegun import freeze_time
Expand Down Expand Up @@ -33,7 +33,7 @@ def __enter__(self):
except locale.Error:
pass
msg = 'could not set locale to any of: %s' % ', '.join(self.targets)
raise skip.SkipTest(msg)
raise SkipTest(msg)

def __exit__(self, *args):
locale.setlocale(locale.LC_ALL, self.old)
Expand Down Expand Up @@ -316,12 +316,13 @@ def test_generator_object():
with freeze_time(frozen_datetimes):
assert datetime.datetime(2011, 1, 1) == datetime.datetime.now()

assert_raises(StopIteration, freeze_time, frozen_datetimes)
with pytest.raises(StopIteration):
freeze_time(frozen_datetimes)


def test_maya_datetimes():
if not maya:
raise skip.SkipTest("maya is optional since it's not supported for "
raise SkipTest("maya is optional since it's not supported for "
"enough python versions")

with freeze_time(maya.when("October 2nd, 1997")):
Expand Down Expand Up @@ -392,12 +393,12 @@ def test_class_decorator_ignores_nested_class(self):

def test_class_decorator_skips_callable_object_py2(self):
if sys.version_info[0] != 2:
raise skip.SkipTest("test target is Python2")
raise SkipTest("test target is Python2")
assert self.a_mock.__class__ == Callable

def test_class_decorator_wraps_callable_object_py3(self):
if sys.version_info[0] != 3:
raise skip.SkipTest("test target is Python3")
raise SkipTest("test target is Python3")
assert self.a_mock.__wrapped__.__class__ == Callable

@staticmethod
Expand Down
7 changes: 4 additions & 3 deletions tests/test_utils.py
@@ -1,5 +1,6 @@
from unittest import SkipTest

import mock
from nose.plugins import skip

from freezegun import api
from tests import utils
Expand All @@ -20,7 +21,7 @@ def test_should_not_skip_cpython():
function_mock = mock.MagicMock(__name__='function')
try:
utils.cpython_only(function_mock)()
except skip.SkipTest:
except SkipTest:
raise AssertionError("Test was skipped in CPython")
assert function_mock.called

Expand All @@ -32,7 +33,7 @@ def test_should_skip_non_cpython():
function_mock = mock.MagicMock(__name__='function', skipped=False)
try:
utils.cpython_only(function_mock)()
except skip.SkipTest:
except SkipTest:
function_mock.skipped = True
assert not function_mock.called
assert function_mock.skipped
10 changes: 4 additions & 6 deletions tests/test_uuid.py
Expand Up @@ -2,8 +2,6 @@
import datetime
import uuid

from nose.tools import assert_equal

from freezegun import freeze_time


Expand All @@ -25,11 +23,11 @@ def test_uuid1_future():
"""
future_target = datetime.datetime(2056, 2, 6, 14, 3, 21)
with freeze_time(future_target):
assert_equal(time_from_uuid(uuid.uuid1()), future_target)
assert time_from_uuid(uuid.uuid1()) == future_target

past_target = datetime.datetime(1978, 7, 6, 23, 6, 31)
with freeze_time(past_target):
assert_equal(time_from_uuid(uuid.uuid1()), past_target)
assert time_from_uuid(uuid.uuid1()) == past_target


def test_uuid1_past():
Expand All @@ -39,8 +37,8 @@ def test_uuid1_past():
"""
past_target = datetime.datetime(1978, 7, 6, 23, 6, 31)
with freeze_time(past_target):
assert_equal(time_from_uuid(uuid.uuid1()), past_target)
assert time_from_uuid(uuid.uuid1()) == past_target

future_target = datetime.datetime(2056, 2, 6, 14, 3, 21)
with freeze_time(future_target):
assert_equal(time_from_uuid(uuid.uuid1()), future_target)
assert time_from_uuid(uuid.uuid1()) == future_target
5 changes: 2 additions & 3 deletions tests/utils.py
@@ -1,6 +1,5 @@
from functools import wraps

from nose.plugins import skip
from unittest import SkipTest

from freezegun.api import FakeDate, FakeDatetime, _is_cpython

Expand All @@ -17,6 +16,6 @@ def cpython_only(func):
@wraps(func)
def wrapper(*args):
if not _is_cpython:
raise skip.SkipTest("Requires CPython")
raise SkipTest("Requires CPython")
return func(*args)
return wrapper

0 comments on commit b39ca01

Please sign in to comment.