Skip to content

Commit af26d30

Browse files
committed
Port mesh tests to pytest
1 parent 6e4c61b commit af26d30

6 files changed

Lines changed: 49 additions & 30 deletions

File tree

nbodykit/source/mesh/tests/test_array.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
from runtests.mpi import MPITest
21
from nbodykit.lab import *
32
from nbodykit import setup_logging
43

54
from numpy.testing import assert_allclose, assert_array_equal
5+
from mpi4py import MPI
66

77
setup_logging()
88

9-
@MPITest([1, 4])
9+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
10+
@pytest.mark.mpi
1011
def test_paint(comm):
1112

1213
from pmesh.pm import ParticleMesh

nbodykit/source/mesh/tests/test_bigfile.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
from runtests.mpi import MPITest
21
from nbodykit.lab import *
32
from nbodykit import setup_logging
4-
3+
from mpi4py import MPI
54
import shutil
65
from numpy.testing import assert_array_equal, assert_allclose
76

87
setup_logging()
98

10-
@MPITest([1,4])
9+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
10+
@pytest.mark.mpi
1111
def test_bigfile_grid(comm):
1212

1313
import tempfile

nbodykit/source/mesh/tests/test_catalogmesh.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
from runtests.mpi import MPITest
21
from nbodykit.lab import *
32
from nbodykit import set_options
43
from nbodykit import setup_logging
54
from numpy.testing import assert_array_equal, assert_allclose
65
import pytest
7-
6+
from mpi4py import MPI
87
# debug logging
98
setup_logging("debug")
109

11-
@MPITest([1])
10+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
11+
@pytest.mark.mpi
1212
def test_tsc_interlacing(comm):
1313

1414
source = UniformCatalog(nbar=3e-4, BoxSize=512., seed=42, comm=comm)
@@ -22,7 +22,8 @@ def test_tsc_interlacing(comm):
2222
# skip a few large scale modes that are noisier (fewer modes)
2323
assert_allclose(r.power['power'][5:], 1 / (3e-4), rtol=1e-1)
2424

25-
@MPITest([1])
25+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
26+
@pytest.mark.mpi
2627
def test_paint_empty(comm):
2728

2829
source = UniformCatalog(nbar=3e-4, BoxSize=512., seed=42, comm=comm)
@@ -41,7 +42,8 @@ def test_paint_empty(comm):
4142
real = mesh.to_real_field(normalize=False)
4243
assert_allclose(real, 0.0)
4344

44-
@MPITest([1])
45+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
46+
@pytest.mark.mpi
4547
def test_paint_chunksize(comm):
4648

4749
source = UniformCatalog(nbar=3e-4, BoxSize=512., seed=42, comm=comm)
@@ -57,7 +59,8 @@ def test_paint_chunksize(comm):
5759

5860
assert_allclose(r1, r2)
5961

60-
@MPITest([1, 4])
62+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
63+
@pytest.mark.mpi
6164
def test_shotnoise(comm):
6265

6366
source = UniformCatalog(nbar=3e-4, BoxSize=512., seed=42, comm=comm)
@@ -78,7 +81,8 @@ def test_shotnoise(comm):
7881
assert_allclose(r1.attrs['shotnoise'], SN, rtol=1e-2)
7982
assert_allclose(r2.attrs['shotnoise'], SN, rtol=1e-2)
8083

81-
@MPITest([1])
84+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
85+
@pytest.mark.mpi
8286
def test_cic_interlacing(comm):
8387

8488
source = UniformCatalog(nbar=3e-4, BoxSize=512., seed=42, comm=comm)
@@ -90,7 +94,8 @@ def test_cic_interlacing(comm):
9094
# if the compensation worked
9195
r = FFTPower(mesh, mode='1d', kmin=0.02)
9296

93-
@MPITest([1])
97+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
98+
@pytest.mark.mpi
9499
def test_setters(comm):
95100

96101
source = UniformCatalog(nbar=3e-4, BoxSize=512., seed=42, comm=comm)
@@ -110,7 +115,8 @@ def test_setters(comm):
110115
mesh.window = 'tsc'
111116
assert mesh.window == 'tsc'
112117

113-
@MPITest([1])
118+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
119+
@pytest.mark.mpi
114120
def test_bad_window(comm):
115121

116122
source = UniformCatalog(nbar=3e-4, BoxSize=512., seed=42, comm=comm)
@@ -122,7 +128,8 @@ def test_bad_window(comm):
122128
with pytest.raises(Exception):
123129
mesh.window = "BAD"
124130

125-
@MPITest([1])
131+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
132+
@pytest.mark.mpi
126133
def test_no_compensation(comm):
127134

128135
source = UniformCatalog(nbar=3e-4, BoxSize=512., seed=42, comm=comm)
@@ -137,7 +144,8 @@ def test_no_compensation(comm):
137144
with pytest.raises(ValueError):
138145
actions = mesh.actions
139146

140-
@MPITest([4])
147+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
148+
@pytest.mark.mpi
141149
def test_odd_chunksize(comm):
142150
# no errors shall occur. This is a regression test.
143151

@@ -147,11 +155,12 @@ def test_odd_chunksize(comm):
147155

148156
# make the mesh
149157
mesh = source.to_mesh(resampler='cic', Nmesh=64, interlaced=True, compensated=True)
150-
158+
151159
with set_options(paint_chunk_size=1111):
152160
mesh.compute()
153161

154-
@MPITest([1, 4])
162+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
163+
@pytest.mark.mpi
155164
def test_view(comm):
156165

157166
# the CatalogSource
@@ -172,7 +181,8 @@ def test_view(comm):
172181
for k in mesh.attrs:
173182
assert k in view.attrs
174183

175-
@MPITest([1, 4])
184+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
185+
@pytest.mark.mpi
176186
def test_apply_nocompensation(comm):
177187

178188
# the CatalogSource
@@ -201,7 +211,8 @@ def raisefunc(k, v):
201211
for k in mesh.attrs:
202212
assert k in view.attrs
203213

204-
@MPITest([1])
214+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
215+
@pytest.mark.mpi
205216
def test_apply_compensated(comm):
206217

207218
# the CatalogSource

nbodykit/source/mesh/tests/test_field.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
from runtests.mpi import MPITest
21
from nbodykit.lab import *
32
from nbodykit import setup_logging
43
from numpy.testing import assert_allclose, assert_array_equal
4+
from mpi4py import MPI
55

66
setup_logging()
77

8-
@MPITest([1,4])
8+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
9+
@pytest.mark.mpi
910
def test_paint(comm):
1011
from pmesh.pm import ParticleMesh
1112

nbodykit/source/mesh/tests/test_linear.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
from runtests.mpi import MPITest
21
from nbodykit.lab import *
32
from nbodykit import setup_logging
43

54
from numpy.testing import assert_allclose
5+
from mpi4py import MPI
66

77
setup_logging()
88

9-
@MPITest([1,4])
9+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
10+
@pytest.mark.mpi
1011
def test_paint(comm):
1112

1213
cosmo = cosmology.Planck15

nbodykit/source/mesh/tests/test_species.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
from runtests.mpi import MPITest
21
from nbodykit.lab import *
32
from nbodykit import setup_logging
43

54
from numpy.testing import assert_array_equal, assert_allclose
65
import pytest
6+
from mpi4py import MPI
77

88
setup_logging()
99

10-
@MPITest([1])
10+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
11+
@pytest.mark.mpi
1112
def test_boxsize_nmesh(comm):
1213

1314
# the catalog
@@ -28,7 +29,8 @@ def test_boxsize_nmesh(comm):
2829
with pytest.raises(ValueError):
2930
mesh = cat.to_mesh(Nmesh=32)
3031

31-
@MPITest([1, 4])
32+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
33+
@pytest.mark.mpi
3234
def test_getitem(comm):
3335

3436
# the catalog
@@ -43,7 +45,8 @@ def test_getitem(comm):
4345
submesh = mesh[name] # should be equal to source
4446
assert submesh.source is cat[name]
4547

46-
@MPITest([1, 4])
48+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
49+
@pytest.mark.mpi
4750
def test_compute(comm):
4851

4952
# the catalog
@@ -71,7 +74,8 @@ def test_compute(comm):
7174
# must be the same
7275
assert_allclose(combined.value, (real1.value + real2.value)/norm, atol=1e-5)
7376

74-
@MPITest([1, 4])
77+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
78+
@pytest.mark.mpi
7579
def test_actions_compensated(comm):
7680

7781
# the test case fails only if there is enough particles to trigger
@@ -88,7 +92,8 @@ def test_actions_compensated(comm):
8892
mesh = cat.to_mesh(Nmesh=32, compensated=True)
8993
assert len(mesh.actions) > 0
9094

91-
@MPITest([1, 4])
95+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
96+
@pytest.mark.mpi
9297
def test_paint_interlaced(comm):
9398

9499
# the test case fails only if there is enough particles to trigger

0 commit comments

Comments
 (0)