Skip to content

Commit 510837e

Browse files
committed
Port remaining tests to pytest
1 parent 50c78c9 commit 510837e

13 files changed

Lines changed: 160 additions & 91 deletions

‎nbodykit/tests/test_batch.py‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from runtests.mpi import MPITest
1+
from mpi4py import MPI
22
from nbodykit import setup_logging
33
from nbodykit import CurrentMPIComm
44
from nbodykit.batch import TaskManager
@@ -11,7 +11,8 @@
1111
setup_logging("debug")
1212

1313

14-
@MPITest([1])
14+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
15+
@pytest.mark.mpi
1516
def test_missing_ranks(comm):
1617

1718
with CurrentMPIComm.enter(comm):
@@ -20,7 +21,8 @@ def test_missing_ranks(comm):
2021
with TaskManager(cpus_per_task, debug=True, use_all_cpus=True):
2122
pass
2223

23-
@MPITest([2])
24+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
25+
@pytest.mark.mpi
2426
def test_no_workers(comm):
2527

2628
with CurrentMPIComm.enter(comm):
@@ -30,7 +32,8 @@ def test_no_workers(comm):
3032
pass
3133

3234

33-
@MPITest([2, 4])
35+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
36+
@pytest.mark.mpi
3437
def test_iterate(comm):
3538

3639
cpus_per_task = 2
@@ -54,7 +57,8 @@ def test_iterate(comm):
5457
print(e)
5558
raise
5659

57-
@MPITest([4])
60+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
61+
@pytest.mark.mpi
5862
def test_map(comm):
5963

6064
cpus_per_task = 2

‎nbodykit/tests/test_binned_stat.py‎

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from runtests.mpi import MPITest
1+
from mpi4py import MPI
22
from nbodykit import setup_logging
33
from nbodykit.binned_statistic import BinnedStatistic
44

@@ -12,7 +12,8 @@
1212
setup_logging("debug")
1313

1414

15-
@MPITest([1])
15+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
16+
@pytest.mark.mpi
1617
def test_to_json(comm):
1718

1819
# load from JSON
@@ -30,7 +31,8 @@ def test_to_json(comm):
3031
# cleanup
3132
os.remove(ff.name)
3233

33-
@MPITest([1])
34+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
35+
@pytest.mark.mpi
3436
def test_1d_load(comm):
3537

3638
# load plaintext format
@@ -48,7 +50,8 @@ def test_1d_load(comm):
4850
for name in ds1:
4951
testing.assert_almost_equal(ds1[name], ds2[name])
5052

51-
@MPITest([1])
53+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
54+
@pytest.mark.mpi
5255
def test_2d_load(comm):
5356

5457
# load plaintext format
@@ -62,7 +65,8 @@ def test_2d_load(comm):
6265
for name in ds1:
6366
testing.assert_almost_equal(ds1[name], ds2[name])
6467

65-
@MPITest([1])
68+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
69+
@pytest.mark.mpi
6670
def test_str(comm):
6771

6872
dataset = BinnedStatistic.from_json(os.path.join(data_dir, 'dataset_2d.json'))
@@ -78,7 +82,8 @@ def test_str(comm):
7882
# this is the same as str
7983
r = repr(dataset)
8084

81-
@MPITest([1])
85+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
86+
@pytest.mark.mpi
8287
def test_getitem(comm):
8388

8489
dataset = BinnedStatistic.from_json(os.path.join(data_dir, 'dataset_2d.json'))
@@ -103,7 +108,8 @@ def test_getitem(comm):
103108
with pytest.raises(IndexError):
104109
bad = dataset[0,0]
105110

106-
@MPITest([1])
111+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
112+
@pytest.mark.mpi
107113
def test_array_slice(comm):
108114

109115
dataset = BinnedStatistic.from_json(os.path.join(data_dir, 'dataset_2d.json'))
@@ -121,7 +127,8 @@ def test_array_slice(comm):
121127
assert sliced.dims == ['k', 'mu']
122128

123129

124-
@MPITest([1])
130+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
131+
@pytest.mark.mpi
125132
def test_list_array_slice(comm):
126133

127134
dataset = BinnedStatistic.from_json(os.path.join(data_dir, 'dataset_2d.json'))
@@ -136,7 +143,8 @@ def test_list_array_slice(comm):
136143
testing.assert_array_equal(dataset[var][:,[0,-1]], sliced[var])
137144

138145

139-
@MPITest([1])
146+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
147+
@pytest.mark.mpi
140148
def test_variable_set(comm):
141149

142150
dataset = BinnedStatistic.from_json(os.path.join(data_dir, 'dataset_2d.json'))
@@ -155,15 +163,17 @@ def test_variable_set(comm):
155163
dataset['TEST'] = 10.
156164

157165

158-
@MPITest([1])
166+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
167+
@pytest.mark.mpi
159168
def test_copy(comm):
160169

161170
dataset = BinnedStatistic.from_json(os.path.join(data_dir, 'dataset_2d.json'))
162171
copy = dataset.copy()
163172
for var in dataset:
164173
testing.assert_array_equal(dataset[var], copy[var])
165174

166-
@MPITest([1])
175+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
176+
@pytest.mark.mpi
167177
def test_rename_variable(comm):
168178

169179
dataset = BinnedStatistic.from_json(os.path.join(data_dir, 'dataset_2d.json'))
@@ -174,7 +184,8 @@ def test_rename_variable(comm):
174184
assert 'renamed_test' in dataset
175185
assert 'test' not in dataset
176186

177-
@MPITest([1])
187+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
188+
@pytest.mark.mpi
178189
def test_sel(comm):
179190

180191
dataset = BinnedStatistic.from_json(os.path.join(data_dir, 'dataset_2d.json'))
@@ -200,7 +211,8 @@ def test_sel(comm):
200211
assert sliced.shape[1] == 1
201212
assert numpy.all((sliced['k'] >= 0.02)&(sliced['k'] <= 0.15))
202213

203-
@MPITest([1])
214+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
215+
@pytest.mark.mpi
204216
def test_take(comm):
205217

206218
dataset = BinnedStatistic.from_json(os.path.join(data_dir, 'dataset_2d.json'))
@@ -222,7 +234,8 @@ def test_take(comm):
222234
dataset.take(dataset['k'] < 0.3)
223235
assert len(sliced.dims) == 2
224236

225-
@MPITest([1])
237+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
238+
@pytest.mark.mpi
226239
def test_squeeze(comm):
227240

228241
dataset = BinnedStatistic.from_json(os.path.join(data_dir, 'dataset_2d.json'))
@@ -242,7 +255,8 @@ def test_squeeze(comm):
242255
assert squeezed.shape[0] == sliced.shape[0]
243256

244257

245-
@MPITest([1])
258+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
259+
@pytest.mark.mpi
246260
def test_average(comm):
247261
import warnings
248262

@@ -274,7 +288,8 @@ def test_average(comm):
274288
testing.assert_allclose(x, avg[var])
275289

276290

277-
@MPITest([1])
291+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
292+
@pytest.mark.mpi
278293
def test_reindex(comm):
279294
import warnings
280295

@@ -297,7 +312,8 @@ def test_reindex(comm):
297312
new = dataset.reindex('mu', 0.4, force=False)
298313
new = dataset.reindex('mu', 0.4, force=True)
299314

300-
@MPITest([1])
315+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
316+
@pytest.mark.mpi
301317
def test_subclass_copy_sel(comm):
302318
# this test asserts the sel returns instance of subclass.
303319
# and the copy method can change the class.

‎nbodykit/tests/test_cache.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from nbodykit import GlobalCache
22
from nbodykit.lab import UniformCatalog
33

4-
from runtests.mpi import MPITest
4+
from mpi4py import MPI
55

6-
@MPITest([1])
6+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
7+
@pytest.mark.mpi
78
def test_cache(comm):
89
cat = UniformCatalog(nbar=10000, BoxSize=1.0, comm=comm)
910
cat['test'] = cat['Position'] ** 5

‎nbodykit/tests/test_distributed.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
from runtests.mpi import MPITest
1+
from mpi4py import MPI
22
from nbodykit import use_distributed, use_mpi
33
from numpy.testing import assert_array_equal
44
from nbodykit.lab import UniformCatalog
5+
import pytest
56

67
def setup():
78
# only initializes the local cluster this on the root rank.
89
# all unit tests in this file must be protected by MPITest([1]).
9-
from mpi4py import MPI
1010
if MPI.COMM_WORLD.rank == 0:
1111
from distributed import LocalCluster, Client
1212
cluster = LocalCluster(n_workers=1, threads_per_worker=1, processes=False)
1313
use_distributed(Client(cluster))
1414

1515
def teardown():
16-
from mpi4py import MPI
1716
use_mpi(MPI.COMM_WORLD)
1817

19-
@MPITest([1])
18+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
19+
@pytest.mark.mpi
2020
def test_pickle(comm):
2121
import pickle
2222
cat = UniformCatalog(1e-3, 512, comm=comm)
@@ -25,8 +25,8 @@ def test_pickle(comm):
2525

2626
assert_array_equal(cat['Position'], cat2['Position'])
2727

28-
29-
@MPITest([1])
28+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
29+
@pytest.mark.mpi
3030
def test_save(comm):
3131
cat = UniformCatalog(1e-3, 512, comm=comm)
3232

‎nbodykit/tests/test_filters.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
from nbodykit import cosmology
22
from nbodykit import setup_logging
3-
from runtests.mpi import MPITest
3+
import pytest
44
from nbodykit.base.mesh import MeshFilter
55
from nbodykit.filters import TopHat
66
from nbodykit.source.mesh import LinearMesh
7+
from mpi4py import MPI
78

89
# debug logging
910
setup_logging("debug")
1011

11-
@MPITest([1])
12+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
13+
@pytest.mark.mpi
1214
def test_tophat(comm):
1315
cosmo = cosmology.Planck15
1416

‎nbodykit/tests/test_lab.py‎

Lines changed: 9 additions & 5 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, set_options, GlobalCache
3+
from mpi4py import MPI
44

55
# debug logging
66
setup_logging("debug")
77

8-
@MPITest([1, 4])
8+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
9+
@pytest.mark.mpi
910
def test_fftpower(comm):
1011
cosmo = cosmology.Planck15
1112

@@ -24,7 +25,8 @@ def test_fftpower(comm):
2425
output = "./test_fftpower-%d.json" % comm.size
2526
result.save(output)
2627

27-
@MPITest([1, 4])
28+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
29+
@pytest.mark.mpi
2830
def test_compute(comm):
2931
cosmo = cosmology.Planck15
3032

@@ -52,14 +54,16 @@ def filter(k, v):
5254
source.save(output="./test_paint-real-%d.bigfile" % comm.size, mode='real')
5355
source.save(output="./test_paint-complex-%d.bigfile" % comm.size, mode='complex')
5456

55-
@MPITest([1, 4])
57+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
58+
@pytest.mark.mpi
5659
def test_current_mpicomm(comm):
5760
cosmo = cosmology.Planck15
5861

5962
with CurrentMPIComm.enter(comm):
6063
pass
6164

62-
@MPITest([1, 4])
65+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
66+
@pytest.mark.mpi
6367
def test_set_options(comm):
6468

6569
with CurrentMPIComm.enter(comm):

‎nbodykit/tests/test_meshtools.py‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from runtests.mpi import MPITest
1+
from mpi4py import MPI
22
import numpy
33
from nbodykit import setup_logging
44
from nbodykit.meshtools import SlabIterator
@@ -10,7 +10,8 @@
1010
# debug logging
1111
setup_logging("debug")
1212

13-
@MPITest([1])
13+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
14+
@pytest.mark.mpi
1415
def test_wrong_ndim(comm):
1516

1617
numpy.random.seed(42)
@@ -25,7 +26,8 @@ def test_wrong_ndim(comm):
2526
for slab in SlabIterator([rfield.x[0]], axis=0, symmetry_axis=None):
2627
pass
2728

28-
@MPITest([1])
29+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
30+
@pytest.mark.mpi
2931
def test_wrong_coords_shape(comm):
3032

3133
numpy.random.seed(42)
@@ -43,7 +45,8 @@ def test_wrong_coords_shape(comm):
4345
pass
4446

4547

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

4952
numpy.random.seed(42)
@@ -60,7 +63,8 @@ def test_2d_slab(comm):
6063
assert_array_equal(slab.hermitian_weights, numpy.ones(slab.shape))
6164
assert_array_equal(rfield[slab.index], data[i])
6265

63-
@MPITest([1, 4])
66+
@pytest.mark.parametrize("comm", [MPI.COMM_WORLD,])
67+
@pytest.mark.mpi
6468
def test_hermitian_weights(comm):
6569

6670
numpy.random.seed(42)

0 commit comments

Comments
 (0)