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

Replace nose with pytest #509

Merged
merged 11 commits into from
Aug 17, 2021
Merged
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
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,8 @@ jobs:
- name: unit all_deps
if: (contains(matrix.os, 'ubuntu') && !startsWith(matrix.python-version, 'py'))
run: tox -e with_all
- name: run coveralls
if: matrix.python-version != '2.7'
env:
github-token: ${{ secrets.GITHUB_TOKEN }}
run: tox -e coveralls
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
*.lock
.ipynb_checkpoints
.vscode
.tox
8 changes: 4 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ignore = E114,
W504,
W605

[nosetests]
verbosity = 2
with-doctest = 1
nologcapture = 1
[tool:pytest]
python_files = test*.py
# Run the doctests found (if any) in the modules of param & numbergen.
addopts = --doctest-modules param numbergen
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def get_setup_version(reponame):
# pip doesn't support tests_require
# (https://github.com/pypa/pip/issues/1197)
'tests': [
'nose',
'pytest',
'pytest-cov',
'flake8',
],
'doc': [
Expand Down
5 changes: 0 additions & 5 deletions tests/API0/testcompositeparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,3 @@ def test_composite_dynamic_generator(self):
# get_value_generator() should give the objects
self.assertEqual(ix(), 2)
self.assertEqual(iy(), 5)


if __name__ == "__main__":
import nose
nose.runmodule()
14 changes: 5 additions & 9 deletions tests/API0/testdefaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import unittest

import pytest

from param.parameterized import add_metaclass
from param import concrete_descendents, Parameter

Expand All @@ -30,12 +32,11 @@
skip.append('Series')


class TestDefaultsMetaclass(type):
class DefaultsMetaclassTest(type):
def __new__(mcs, name, bases, dict_):

def test_skip(*args,**kw):
from nose.exc import SkipTest
raise SkipTest
pytest.skip()

def add_test(p):
def test(self):
Expand All @@ -50,11 +51,6 @@ def test(self):
return type.__new__(mcs, name, bases, dict_)


@add_metaclass(TestDefaultsMetaclass)
@add_metaclass(DefaultsMetaclassTest)
class TestDefaults(unittest.TestCase):
pass


if __name__ == "__main__":
import nose
nose.runmodule()
6 changes: 0 additions & 6 deletions tests/API0/testdynamicparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,6 @@ def test_dynamic_shared_numbergen(self):
self.assertNotEqual(call_1, t12.x)



if __name__ == "__main__":
import nose
nose.runmodule()


# Commented out block in the original doctest version.
# Maybe these are features originally planned but never implemented

Expand Down
4 changes: 0 additions & 4 deletions tests/API0/testlistselector.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,3 @@ class Q(param.Parameterized):

with self.assertRaises(TypeError):
Q.params('r').compute_default()

if __name__ == "__main__":
import nose
nose.runmodule()
4 changes: 0 additions & 4 deletions tests/API0/testnumbergen.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,3 @@ def test_range(self):
for _ in range(_iterations):
value = gen()
self.assertTrue(lbound <= value < ubound)

if __name__ == "__main__":
import nose
nose.runmodule()
5 changes: 0 additions & 5 deletions tests/API0/testnumpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,3 @@ class Z(param.Parameterized):

z = Z(z=numpy.array([1,2]))
_is_array_and_equal(z.z,[1,2])


if __name__ == "__main__":
import nose
nose.runmodule()
5 changes: 0 additions & 5 deletions tests/API0/testobjectselector.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,3 @@ class Q(param.Parameterized):
pass
else:
raise AssertionError("ObjectSelector created without range.")


if __name__ == "__main__":
import nose
nose.runmodule()
48 changes: 19 additions & 29 deletions tests/API0/testparameterizedobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@


import random
from nose.tools import istest, nottest


from param.parameterized import ParamOverrides, shared_parameters

@nottest
class _SomeRandomNumbers(object):
def __call__(self):
return random.random()

@nottest
class TestPO(param.Parameterized):
__test__ = False

inst = param.Parameter(default=[1,2,3],instantiate=True)
notinst = param.Parameter(default=[1,2,3],instantiate=False)
const = param.Parameter(default=1,constant=True)
Expand All @@ -30,24 +28,24 @@ class TestPO(param.Parameterized):

dyn = param.Dynamic(default=1)

@nottest
class AnotherTestPO(param.Parameterized):
instPO = param.Parameter(default=TestPO(),instantiate=True)
notinstPO = param.Parameter(default=TestPO(),instantiate=False)

@nottest
class TestAbstractPO(param.Parameterized):
__test__ = False

__abstract = True

class _AnotherAbstractPO(param.Parameterized):
__abstract = True


@nottest
class TestParamInstantiation(AnotherTestPO):
__test__ = False

instPO = param.Parameter(default=AnotherTestPO(),instantiate=False)

@istest
class TestParameterized(unittest.TestCase):

def test_constant_parameter(self):
Expand Down Expand Up @@ -160,22 +158,22 @@ def test_state_saving(self):

from param import parameterized

@nottest
class some_fn(param.ParameterizedFunction):
num_phase = param.Number(18)
frequencies = param.List([99])
scale = param.Number(0.3)
__test__ = False

num_phase = param.Number(18)
frequencies = param.List([99])
scale = param.Number(0.3)

def __call__(self,**params_to_override):
params = parameterized.ParamOverrides(self,params_to_override)
num_phase = params['num_phase']
frequencies = params['frequencies']
scale = params['scale']
return scale,num_phase,frequencies
def __call__(self,**params_to_override):
params = parameterized.ParamOverrides(self,params_to_override)
num_phase = params['num_phase']
frequencies = params['frequencies']
scale = params['scale']
return scale,num_phase,frequencies

instance = some_fn.instance()

@istest
class TestParameterizedFunction(unittest.TestCase):

def _basic_tests(self,fn):
Expand All @@ -201,12 +199,12 @@ def test_pickle_instance(self):
self.assertEqual(i(),(0.3,18,[10,20,30]))


@nottest
class TestPO1(param.Parameterized):
__test__ = False

x = param.Number(default=numbergen.UniformRandom(lbound=-1,ubound=1,seed=1),bounds=(-1,1))
y = param.Number(default=1,bounds=(-1,1))

@istest
class TestNumberParameter(unittest.TestCase):

def test_outside_bounds(self):
Expand All @@ -231,7 +229,6 @@ def test_outside_bounds_numbergen(self):
assert False, "Should raise ValueError."


@istest
class TestStringParameter(unittest.TestCase):

def setUp(self):
Expand All @@ -256,7 +253,6 @@ def test_handling_of_None(self):



@istest
class TestParamOverrides(unittest.TestCase):

def setUp(self):
Expand Down Expand Up @@ -297,9 +293,3 @@ def test_shared_object(self):
def test_shared_list(self):
self.assertTrue(self.p1.inst is self.p2.inst)
self.assertTrue(self.p1.params('inst').default is not self.p2.inst)



if __name__ == "__main__":
import nose
nose.runmodule()
6 changes: 0 additions & 6 deletions tests/API0/testparameterizedrepr.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,3 @@ def test_qualify(self):

self.assertEqual(obj.pprint(qualify=True),
"tests.API0.testparameterizedrepr."+r)



if __name__ == "__main__":
import nose
nose.runmodule()
18 changes: 5 additions & 13 deletions tests/API0/testtimedependent.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numbergen
import copy

from nose.plugins.skip import SkipTest
import pytest
import fractions

try:
Expand Down Expand Up @@ -81,16 +81,15 @@ def test_time_int_change_type(self):
self.assertEqual(t(), 1)
self.assertEqual(t.time_type, fractions.Fraction)

@pytest.mark.skipif(gmpy is None, reason="gmpy is not installed")
def test_time_init_gmpy(self):
if gmpy is None: raise SkipTest

t = param.Time(time_type=gmpy.mpq)
self.assertEqual(t(), gmpy.mpq(0))
t.advance(gmpy.mpq(0.25))
self.assertEqual(t(), gmpy.mpq(1,4))

@pytest.mark.skipif(gmpy is None, reason="gmpy is not installed")
def test_time_init_gmpy_advanced(self):
if gmpy is None: raise SkipTest
t = param.Time(time_type=gmpy.mpq,
timestep=gmpy.mpq(0.25),
until=1.5)
Expand Down Expand Up @@ -270,12 +269,12 @@ def test_time_hashing_rationals(self):
self.assertEqual(hashfn(pi), hashfn(fractions.Fraction(pi)))


@pytest.mark.skipif(gmpy is None, reason="gmpy is not installed")
def test_time_hashing_integers_gmpy(self):
"""
Check that hashes for gmpy values at the integers also matches
those of ints, fractions and strings.
"""
if gmpy is None: raise SkipTest
hashfn = numbergen.Hash("test", input_count=1)
hash_1 = hashfn(1)
hash_42 = hashfn(42)
Expand All @@ -286,20 +285,13 @@ def test_time_hashing_integers_gmpy(self):
self.assertEqual(hash_42, hashfn(gmpy.mpq(42)))
self.assertEqual(hash_42, hashfn(42))

@pytest.mark.skipif(gmpy is None, reason="gmpy is not installed")
def test_time_hashing_rationals_gmpy(self):
"""
Check that hashes of fractions and gmpy mpqs match for some
reasonable rational numbers.
"""
if gmpy is None: raise SkipTest
pi = "3.141592"
hashfn = numbergen.Hash("test", input_count=1)
self.assertEqual(hashfn(0.5), hashfn(gmpy.mpq(0.5)))
self.assertEqual(hashfn(pi), hashfn(gmpy.mpq(3.141592)))




if __name__ == "__main__":
import nose
nose.runmodule()
5 changes: 0 additions & 5 deletions tests/API1/testcompositeparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,3 @@ def test_composite_dynamic_generator(self):
# get_value_generator() should give the objects
self.assertEqual(ix(), 2)
self.assertEqual(iy(), 5)


if __name__ == "__main__":
import nose
nose.runmodule()
13 changes: 4 additions & 9 deletions tests/API1/testdefaults.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Do all subclasses of Parameter supply a valid default?
"""
import pytest

from param.parameterized import add_metaclass
from param import concrete_descendents, Parameter
Expand All @@ -27,12 +28,11 @@
skip.append('Series')


class TestDefaultsMetaclass(type):
class DefaultsMetaclassTest(type):
def __new__(mcs, name, bases, dict_):

def test_skip(*args,**kw):
from nose.exc import SkipTest
raise SkipTest
pytest.skip()

def add_test(p):
def test(self):
Expand All @@ -47,11 +47,6 @@ def test(self):
return type.__new__(mcs, name, bases, dict_)


@add_metaclass(TestDefaultsMetaclass)
@add_metaclass(DefaultsMetaclassTest)
class TestDefaults(API1TestCase):
pass


if __name__ == "__main__":
import nose
nose.runmodule()
6 changes: 0 additions & 6 deletions tests/API1/testdynamicparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,6 @@ def test_dynamic_shared_numbergen(self):
self.assertNotEqual(call_1, t12.x)



if __name__ == "__main__":
import nose
nose.runmodule()


# Commented out block in the original doctest version.
# Maybe these are features originally planned but never implemented

Expand Down
2 changes: 2 additions & 0 deletions tests/API1/testjsonserialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

class TestSet(param.Parameterized):

__test__ = False

numpy_params = ['r']
pandas_params = ['s','t','u']
conditionally_unsafe = ['f', 'o']
Expand Down
Loading