Skip to content

Commit 4327a32

Browse files
committed
starting transition to pytest and flake8
1 parent b732df7 commit 4327a32

File tree

7 files changed

+32
-86
lines changed

7 files changed

+32
-86
lines changed

pySDC/core/Sweeper.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ def compute_residual(self):
264264

265265
# get current level and problem description
266266
L = self.level
267-
P = L.prob
268267

269268
# check if there are new values (e.g. from a sweep)
270269
# assert L.status.updated

pySDC/implementations/problem_classes/acoustic_helpers/standard_integrators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import math
2-
from decimal import *
2+
from decimal import Decimal
33

44
import numpy as np
55
import scipy.sparse as sp

pySDC/implementations/problem_classes/boussinesq_helpers/standard_integrators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import math
2-
from decimal import *
2+
from decimal import Decimal
33

44
import numpy as np
55
import scipy.sparse as sp

pySDC/tests/test_Q_transfer.py

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,17 @@
1-
import nose
1+
import pytest
22
import numpy as np
33
from numpy.polynomial.polynomial import polyval
44

55
import pySDC.helpers.transfer_helper as th
66
from pySDC.core.Collocation import CollBase
77
from pySDC.tests.test_helpers import get_derived_from_in_package
88

9-
classes = []
9+
classes = get_derived_from_in_package(CollBase, 'pySDC/implementations/collocation_classes')
10+
t_start = np.random.rand(1) * 0.2
11+
t_end = 0.8 + np.random.rand(1) * 0.2
1012

11-
def setup():
12-
global classes, t_start, t_end
13-
14-
# generate random boundaries for the time slice with 0.0 <= t_start < 0.2 and 0.8 <= t_end < 1.0
15-
t_start = np.random.rand(1) * 0.2
16-
t_end = 0.8 + np.random.rand(1) * 0.2
17-
classes = get_derived_from_in_package(CollBase, 'pySDC/implementations/collocation_classes')
18-
19-
@nose.tools.with_setup(setup)
20-
def test_Q_transfer():
21-
for collclass in classes:
22-
yield check_Q_transfer, collclass
23-
24-
def check_Q_transfer(collclass):
13+
@pytest.mark.parametrize("collclass", classes)
14+
def test_Q_transfer(collclass):
2515
"""
2616
A simple test program to check the order of the Q interpolation/restriction
2717
"""
@@ -61,13 +51,8 @@ def check_Q_transfer(collclass):
6151
else:
6252
assert err_inter > 2E-15, "ERROR: Q-interpolation order is higher than expected, got %s" % polyorder
6353

64-
65-
@nose.tools.with_setup(setup)
66-
def test_Q_transfer_minimal():
67-
for collclass in classes:
68-
yield check_Q_transfer_minimal, collclass
69-
70-
def check_Q_transfer_minimal(collclass):
54+
@pytest.mark.parametrize("collclass", classes)
55+
def test_Q_transfer_minimal(collclass):
7156
"""
7257
A simple test program to check the order of the Q interpolation/restriction for only 2 coarse nodes
7358
"""

pySDC/tests/test_collocation.py

Lines changed: 16 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,23 @@
1-
import nose
1+
import pytest
22
import numpy as np
33

44
from pySDC.core.Collocation import CollBase
55
from pySDC.tests.test_helpers import get_derived_from_in_package
66

7-
classes = []
8-
t_start = None
9-
t_end = None
7+
classes = get_derived_from_in_package(CollBase, 'pySDC/implementations/collocation_classes')
8+
t_start = np.random.rand(1) * 0.2
9+
t_end = 0.8 + np.random.rand(1) * 0.2
1010

11-
def setup():
12-
global classes, t_start, t_end
13-
14-
# generate random boundaries for the time slice with 0.0 <= t_start < 0.2 and 0.8 <= t_end < 1.0
15-
t_start = np.random.rand(1)[0] * 0.2
16-
t_end = 0.8 + np.random.rand(1)[0] * 0.2
17-
classes = get_derived_from_in_package(CollBase, 'pySDC/implementations/collocation_classes')
18-
19-
20-
# TEST 1:
21-
# Check that the quadrature rule integrates polynomials up to order p-1 exactly
22-
# -----------------------------------------------------------------------------
23-
@nose.tools.with_setup(setup)
24-
def test_canintegratepolynomials():
25-
for collclass in classes:
26-
yield check_canintegratepolynomials, collclass, t_start, t_end
27-
28-
def check_canintegratepolynomials(collclass,t_start,t_end):
11+
@pytest.mark.parametrize("collclass", classes)
12+
def test_canintegratepolynomials(collclass):
2913

3014
for M in range(2,13):
3115

3216
coll = collclass(M, t_start, t_end)
3317

3418
# some basic consistency tests
35-
assert np.size(coll.nodes)==np.size(coll.weights), "For node type " + type[0] + ", number of entries in nodes and weights is different"
36-
assert np.size(coll.nodes)==M, "For node type " + type[0] + ", requesting M nodes did not produce M entries in nodes and weights"
19+
assert np.size(coll.nodes)==np.size(coll.weights), "For node type " + coll.__class__.__name__ + ", number of entries in nodes and weights is different"
20+
assert np.size(coll.nodes)==M, "For node type " + coll.__class__.__name__ + ", requesting M nodes did not produce M entries in nodes and weights"
3721

3822
# generate random set of polynomial coefficients
3923
poly_coeff = np.random.rand(coll.order-1)
@@ -49,37 +33,22 @@ def check_canintegratepolynomials(collclass,t_start,t_end):
4933
assert abs(int_ex - int_coll) < 1e-13, "For node type " + coll.__class__.__name__ + ", failed to integrate polynomial of degree " + str(coll.order-1) + " exactly. Error: %5.3e" % abs(int_ex - int_coll)
5034

5135

52-
# TEST 2:
53-
# Check that the Qmat entries are equal to the sum of Smat entries
54-
# ----------------------------------------------------------------
55-
@nose.tools.with_setup(setup)
56-
def test_relateQandSmat():
57-
for collclass in classes:
58-
yield check_relateQandSmat, collclass, t_start, t_end
59-
60-
61-
def check_relateQandSmat(collclass,t_start,t_end):
36+
@pytest.mark.parametrize("collclass", classes)
37+
def test_relateQandSmat(collclass):
6238
for M in range(2, 13):
6339
coll = collclass(M, t_start, t_end)
6440
Q = coll.Qmat[1:,1:]
6541
S = coll.Smat[1:,1:]
66-
assert np.shape(Q) == np.shape(S), "For node type " + type[0] + ", Qmat and Smat have different shape"
42+
assert np.shape(Q) == np.shape(S), "For node type " + coll.__class__.__name__ + ", Qmat and Smat have different shape"
6743
shape = np.shape(Q)
68-
assert shape[0] == shape[1], "For node type " + type[0] + ", Qmat / Smat are not quadratic"
44+
assert shape[0] == shape[1], "For node type " + coll.__class__.__name__ + ", Qmat / Smat are not quadratic"
6945
SSum = np.cumsum(S[:,:],axis=0)
7046
for i in range(0,M):
7147
assert np.linalg.norm( Q[i,:] - SSum[i,:] ) < 1e-15, "For node type " + coll.__class__.__name__ + ", Qmat and Smat did not satisfy the expected summation property."
7248

7349

74-
# TEST 3:
75-
# Check that the partial quadrature rules from Qmat entries have order equal to number of nodes M
76-
# -----------------------------------------------------------------------------------------------
77-
@nose.tools.with_setup(setup)
78-
def test_partialquadrature():
79-
for collclass in classes:
80-
yield check_partialquadraturewithQ, collclass, t_start, t_end
81-
82-
def check_partialquadraturewithQ(collclass, t_start, t_end):
50+
@pytest.mark.parametrize("collclass", classes)
51+
def test_partialquadraturewithQ(collclass):
8352
for M in range(2, 13):
8453
coll = collclass(M, t_start, t_end)
8554
Q = coll.Qmat[1:,1:]
@@ -93,15 +62,9 @@ def check_partialquadraturewithQ(collclass, t_start, t_end):
9362
int_coll = np.dot(poly_vals, Q[i,:])
9463
assert abs(int_ex - int_coll)<1e-12, "For node type " + coll.__class__.__name__ + ", partial quadrature from Qmat rule failed to integrate polynomial of degree M-1 exactly for M = " + str(M)
9564

96-
# TEST 3:
97-
# Check that the partial quadrature rules from Smat entries have order equal to number of nodes M
98-
# -----------------------------------------------------------------------------------------------
99-
@nose.tools.with_setup(setup)
100-
def test_partialquadraturewithS():
101-
for collclass in classes:
102-
yield check_partialquadraturewithS, collclass, t_start, t_end
10365

104-
def check_partialquadraturewithS(collclass, t_start, t_end):
66+
@pytest.mark.parametrize("collclass", classes)
67+
def test_partialquadraturewithS(collclass):
10568
for M in range(2, 13):
10669
coll = collclass(M, t_start, t_end)
10770
S = coll.Smat[1:,1:]

pySDC/tests/test_pep8.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
# coding=utf-8
22
import os
33
import os.path
4+
import pytest
45

56
import nose.tools
67
import pep8
78

8-
BASE_PATH = os.path.abspath(os.path.join(__file__, '..', '..', '..'))
9+
dir = ['pySDC/core', 'pySDC/implementations', 'pySDC/helpers', 'pySDC/tutorial', 'pySDC/projects']
910

11+
@pytest.mark.parametrize("dir", dir)
12+
def test_files(dir):
13+
BASE_PATH = os.path.abspath(os.path.join(__file__, '..', '..', '..'))
1014

11-
def check_files(dir):
1215
style = pep8.StyleGuide()
1316
style.options.max_line_length = 120
1417
style.options.ignore = 'E402'
@@ -21,7 +24,3 @@ def check_files(dir):
2124
report.print_statistics()
2225
nose.tools.assert_equal(report.total_errors, 0, "File %s has some PEP8 errors: %d" % (file, report.total_errors))
2326

24-
25-
def test_pep8():
26-
for dir in ['pySDC/core', 'pySDC/implementations', 'pySDC/helpers', 'pySDC/tutorial', 'pySDC/projects']:
27-
yield check_files, dir

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ dill>=0.2.6
66
matplotlib>=1.5.3
77
numba>=0.35
88
sympy>=1.0
9-
nose>=1.3.7
9+
pytest
1010
pep8
1111
# These packages are required for some of the more involved examples (and data types etc.), can be omitted
1212
petsc4py>=3.10.0

0 commit comments

Comments
 (0)