Skip to content

Commit 55093eb

Browse files
Switch to temporary paths in FieldsIO tests (#556)
1 parent 266a973 commit 55093eb

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

pySDC/tests/test_helpers/test_fieldsIO.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
@pytest.mark.base
1515
@pytest.mark.parametrize("dtypeIdx", DTYPES.keys())
1616
@pytest.mark.parametrize("dim", range(4))
17-
def testHeader(dim, dtypeIdx):
17+
def testHeader(tmpdir, dim, dtypeIdx):
1818
from pySDC.helpers.fieldsIO import FieldsIO, Scalar, Rectilinear
1919

20-
fileName = "testHeader.pysdc"
20+
fileName = f"{tmpdir}/testHeader.pysdc"
2121
dtype = DTYPES[dtypeIdx]
2222

2323
coords = [np.linspace(0, 1, num=256, endpoint=False) for n in [256, 64, 32]]
@@ -67,10 +67,10 @@ def testHeader(dim, dtypeIdx):
6767
@pytest.mark.parametrize("dtypeIdx", DTYPES.keys())
6868
@pytest.mark.parametrize("nSteps", [1, 2, 10, 100])
6969
@pytest.mark.parametrize("nVar", [1, 2, 5])
70-
def testScalar(nVar, nSteps, dtypeIdx):
70+
def testScalar(tmpdir, nVar, nSteps, dtypeIdx):
7171
from pySDC.helpers.fieldsIO import FieldsIO, Scalar
7272

73-
fileName = "testScalar.pysdc"
73+
fileName = f'{tmpdir}/testScalar.pySDC'
7474
dtype = DTYPES[dtypeIdx]
7575

7676
f1 = Scalar(dtype, fileName)
@@ -110,10 +110,10 @@ def testScalar(nVar, nSteps, dtypeIdx):
110110
@pytest.mark.parametrize("nSteps", [1, 2, 5, 10])
111111
@pytest.mark.parametrize("nVar", [1, 2, 5])
112112
@pytest.mark.parametrize("dim", [1, 2, 3])
113-
def testRectilinear(dim, nVar, nSteps, dtypeIdx):
113+
def testRectilinear(tmpdir, dim, nVar, nSteps, dtypeIdx):
114114
from pySDC.helpers.fieldsIO import FieldsIO, Rectilinear, DTYPES
115115

116-
fileName = f"testRectilinear{dim}D.pysdc"
116+
fileName = f"{tmpdir}/testRectilinear{dim}D.pysdc"
117117
dtype = DTYPES[dtypeIdx]
118118

119119
for gridSizes in itertools.product(*[[5, 10, 16]] * dim):
@@ -161,13 +161,13 @@ def testRectilinear(dim, nVar, nSteps, dtypeIdx):
161161
@pytest.mark.parametrize("nY", [1, 5, 16])
162162
@pytest.mark.parametrize("nX", [1, 5, 16])
163163
@pytest.mark.parametrize("nVar", [1, 2, 3])
164-
def testToVTR(nVar, nX, nY, nZ, nSteps):
164+
def testToVTR(tmpdir, nVar, nX, nY, nZ, nSteps):
165165

166166
from pySDC.helpers.fieldsIO import Rectilinear
167167
from pySDC.helpers.vtkIO import readFromVTR
168168

169169
coords = [np.linspace(0, 1, num=n, endpoint=False) for n in [nX, nY, nZ]]
170-
file = Rectilinear(np.float64, "testToVTR.pysdc")
170+
file = Rectilinear(np.float64, f"{tmpdir}/testToVTR.pysdc")
171171
file.setHeader(nVar=nVar, coords=coords)
172172
file.initialize()
173173
u0 = np.random.rand(nVar, nX, nY, nZ).astype(file.dtype)
@@ -176,13 +176,9 @@ def testToVTR(nVar, nX, nY, nZ, nSteps):
176176
ut = (u0 * t).astype(file.dtype)
177177
file.addField(t, ut)
178178

179-
# Cleaning after eventuall other tests ...
180-
for f in glob.glob("testToVTR*.vtr"):
181-
os.remove(f)
179+
file.toVTR(f"{tmpdir}/testToVTR", varNames=[f"var{i}" for i in range(nVar)])
182180

183-
file.toVTR("testToVTR", varNames=[f"var{i}" for i in range(nVar)])
184-
185-
vtrFiles = glob.glob("testToVTR*.vtr")
181+
vtrFiles = glob.glob(f"{tmpdir}/testToVTR*.vtr")
186182
assert len(vtrFiles) == file.nFields
187183

188184
vtrFiles.sort(key=lambda name: int(name.split("_")[-1][:-4]))
@@ -201,11 +197,11 @@ def testToVTR(nVar, nX, nY, nZ, nSteps):
201197
@pytest.mark.parametrize("dtypeIdx", [0, 1])
202198
@pytest.mark.parametrize("nProcs", [2, 4])
203199
@pytest.mark.parametrize("dim", [2, 3])
204-
def testRectilinear_MPI(dim, nProcs, dtypeIdx, algo, nSteps, nVar):
200+
def testRectilinear_MPI(tmpdir, dim, nProcs, dtypeIdx, algo, nSteps, nVar):
205201

206202
import subprocess
207203

208-
fileName = f"testRectilinear{dim}D_MPI.pysdc"
204+
fileName = f"{tmpdir}/testRectilinear{dim}D_MPI.pysdc"
209205

210206
for gridSizes in itertools.product(*[[61, 16]] * dim):
211207

0 commit comments

Comments
 (0)