Skip to content

Commit 198cbb3

Browse files
authored
Clean Tests & Includes (#211)
Issues seen with `pyflakes` and `ruff`.
1 parent 00d21ef commit 198cbb3

21 files changed

+35
-51
lines changed

src/amrex/ArrayOfStructs.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
Authors: Axel Huebl
66
License: BSD-3-Clause-LBNL
77
"""
8-
from collections import namedtuple
98

109

1110
def aos_to_numpy(self, copy=False):
@@ -65,10 +64,6 @@ def aos_to_cupy(self, copy=False):
6564
"""
6665
import cupy as cp
6766

68-
SoA_cp = namedtuple(type(self).__name__ + "_cp", ["real", "int"])
69-
70-
soa_view = SoA_cp([], [])
71-
7267
if self.size() == 0:
7368
raise ValueError("AoS is empty.")
7469

src/amrex/StructOfArrays.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ def soa_to_numpy(self, copy=False):
2525
A tuple with real and int components that are each lists
2626
of 1D numpy arrays.
2727
"""
28-
import numpy as np
29-
3028
SoA_np = namedtuple(type(self).__name__ + "_np", ["real", "int"])
3129

3230
soa_view = SoA_np([], [])
@@ -65,8 +63,6 @@ def soa_to_cupy(self, copy=False):
6563
ImportError
6664
Raises an exception if cupy is not installed
6765
"""
68-
import cupy as cp
69-
7066
SoA_cp = namedtuple(type(self).__name__ + "_cp", ["real", "int"])
7167

7268
soa_view = SoA_cp([], [])

src/amrex/space1d/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ def d_decl(x, y, z):
3737

3838
def Print(*args, **kwargs):
3939
"""Wrap amrex::Print() - only the IO processor writes"""
40-
if not initialized():
40+
if not initialized(): # noqa
4141
print("warning: Print all - AMReX not initialized")
4242
print(*args, **kwargs)
43-
elif ParallelDescriptor.IOProcessor():
43+
elif ParallelDescriptor.IOProcessor(): # noqa
4444
print(*args, **kwargs)
4545

4646

src/amrex/space2d/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ def d_decl(x, y, z):
3737

3838
def Print(*args, **kwargs):
3939
"""Wrap amrex::Print() - only the IO processor writes"""
40-
if not initialized():
40+
if not initialized(): # noqa
4141
print("warning: Print all - AMReX not initialized")
4242
print(*args, **kwargs)
43-
elif ParallelDescriptor.IOProcessor():
43+
elif ParallelDescriptor.IOProcessor(): # noqa
4444
print(*args, **kwargs)
4545

4646

src/amrex/space3d/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ def d_decl(x, y, z):
3737

3838
def Print(*args, **kwargs):
3939
"""Wrap amrex::Print() - only the IO processor writes"""
40-
if not initialized():
40+
if not initialized(): # noqa
4141
print("warning: Print all - AMReX not initialized")
4242
print(*args, **kwargs)
43-
elif ParallelDescriptor.IOProcessor():
43+
elif ParallelDescriptor.IOProcessor(): # noqa
4444
print(*args, **kwargs)
4545

4646

tests/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
except ImportError:
1717
raise ImportError("AMReX: No 1D, 2D or 3D module found!")
1818

19+
# Import calls MPI_Initialize, if not called already
1920
if amr.Config.have_mpi:
20-
from mpi4py import MPI
21+
from mpi4py import MPI # noqa
2122

2223
# base path for input files
2324
basepath = os.getcwd()

tests/test_aos.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# -*- coding: utf-8 -*-
22

33
import numpy as np
4-
import pytest
54

65
import amrex.space3d as amr
76

@@ -85,6 +84,9 @@ def test_array_interface():
8584
print(arr)
8685
print(aos[0], aos[1])
8786
print("-------")
87+
aos[0] = p4
88+
assert aos[0].x == 0
89+
assert aos[0].y == -5
8890
aos[0] = p3
8991
print("array:", arr)
9092
print("aos[0]:", aos[0], "aos[1]:", aos[1])

tests/test_array4.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ def test_array4_numba():
8787
) # type: numpy.ndarray
8888

8989
# host-to-device copy
90-
x_numba = cuda.to_device(x) # type: numba.cuda.cudadrv.devicearray.DeviceNDArray
91-
# x_cupy = cupy.asarray(x_numba) # type: cupy.ndarray
90+
x_numba = cuda.to_device(x) # noqa
91+
# type is numba.cuda.cudadrv.devicearray.DeviceNDArray
92+
# x_cupy = cupy.asarray(x_numba)
93+
# type is cupy.ndarray
9294

9395
# TODO: Implement __cuda_array_interface__ or DLPack in Array4 constructor
9496
# x_arr = amr.Array4_double(x_numba) # type: amr.Array4_double

tests/test_basefab.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
def test_basefab():
9-
bf = amr.BaseFab_Real()
9+
bf = amr.BaseFab_Real() # noqa
1010

1111

1212
def test_basefab_to_host():

tests/test_coordsys.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# -*- coding: utf-8 -*-
22

3-
import numpy as np
4-
import pytest
5-
63
import amrex.space3d as amr
74

85
# import amrex.space3d as amr.CoordSys.CoordType as CoordType

tests/test_dim3.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# -*- coding: utf-8 -*-
22

33
import numpy as np
4-
import pytest
54

65
import amrex.space3d as amr
76

tests/test_farraybox.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55

66
def test_farraybox():
7-
fab = amr.FArrayBox()
7+
fab = amr.FArrayBox() # noqa
88

99

1010
def test_farraybox_io():
11-
fab = amr.FArrayBox()
11+
fab = amr.FArrayBox() # noqa
1212

1313
# https://docs.python.org/3/library/io.html
1414
# https://gist.github.com/asford/544323a5da7dddad2c9174490eb5ed06#file-test_ostream_example-py

tests/test_geometry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def test_periodic_queries(box, real_box):
115115
is_periodic = [0, 0, 1]
116116
gm = Gm(box, real_box, coord, is_periodic)
117117

118-
pdcity = gm.periodicity()
118+
pdcity = gm.periodicity() # noqa
119119

120120
assert gm.isAnyPeriodic()
121121
assert not gm.isPeriodic(0) and not gm.isPeriodic(1) and gm.isPeriodic(2)

tests/test_multifab.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def set_to_three(array):
175175

176176
# assign 3: loop through boxes and launch kernels
177177
for mfi in mfab_device:
178-
bx = mfi.tilebox().grow(ngv)
178+
bx = mfi.tilebox().grow(ngv) # noqa
179179
marr = mfab_device.array(mfi)
180180
marr_numba = cuda.as_cuda_array(marr)
181181

@@ -208,7 +208,7 @@ def test_mfab_ops_cuda_cupy(make_mfab_device):
208208
# assign 3
209209
with cupyx.profiler.time_range("assign 3 [()]", color_id=0):
210210
for mfi in mfab_device:
211-
bx = mfi.tilebox().grow(ngv)
211+
bx = mfi.tilebox().grow(ngv) # noqa
212212
marr_cupy = mfab_device.array(mfi).to_cupy(order="C")
213213
# print(marr_cupy.shape) # 1, 32, 32, 32
214214
# print(marr_cupy.dtype) # float64
@@ -243,7 +243,7 @@ def set_to_five(mm):
243243
return mm
244244

245245
for mfi in mfab_device:
246-
bx = mfi.tilebox().grow(ngv)
246+
bx = mfi.tilebox().grow(ngv) # noqa
247247
marr_cupy = mfab_device.array(mfi).to_cupy(order="F")
248248
# print(marr_cupy.shape) # 32, 32, 32, 1
249249
# print(marr_cupy.dtype) # float64
@@ -268,7 +268,7 @@ def set_to_seven(x):
268268
x[...] = 7.0
269269

270270
for mfi in mfab_device:
271-
bx = mfi.tilebox().grow(ngv)
271+
bx = mfi.tilebox().grow(ngv) # noqa
272272
marr_cupy = mfab_device.array(mfi).to_cupy(order="C")
273273

274274
# write and read into the marr_cupy
@@ -306,7 +306,7 @@ def test_mfab_ops_cuda_pytorch(make_mfab_device):
306306
amr.Config.gpu_backend != "CUDA", reason="Requires AMReX_GPU_BACKEND=CUDA"
307307
)
308308
def test_mfab_ops_cuda_cuml(make_mfab_device):
309-
mfab_device = make_mfab_device()
309+
mfab_device = make_mfab_device() # noqa
310310
# https://github.com/rapidsai/cuml
311311
# https://github.com/rapidsai/cudf
312312
# maybe better for particles as a dataframe test

tests/test_parmparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ def test_parmparse():
1313
dt = pp_param.get_real("dt")
1414
dopml = pp_param.get_bool("do_pml")
1515

16-
assert dopml == True
16+
assert dopml
1717
assert dt == 1.0e-5
1818
assert ncell == 100

tests/test_particleContainer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def test_pc_init():
121121
assert pc.TotalNumberOfParticles() == pc.NumberOfParticlesAtLevel(0) == npart
122122
assert pc.OK()
123123

124-
print(f"Finest level = ", pc.finest_level)
124+
print(f"Finest level = {pc.finest_level}")
125125

126126
print("Iterate particle boxes & set values")
127127
# lvl = 0

tests/test_particleTile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def test_ptile_soa():
119119

120120

121121
@pytest.mark.skipif(amr.Config.spacedim != 3, reason="Requires AMREX_SPACEDIM = 3")
122-
def test_ptile_aos():
122+
def test_ptile_aos_3d():
123123
pt = amr.ParticleTile_1_1_2_1_default()
124124
p1 = amr.Particle_1_1()
125125
p2 = amr.Particle_1_1()

tests/test_periodicity.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
# -*- coding: utf-8 -*-
22

3-
import numpy as np
43
import pytest
54

65
import amrex.space3d as amr
76

87

98
def test_periodicity():
109
obj = amr.Periodicity()
11-
assert obj.is_any_periodic == False
12-
assert obj.is_all_periodic == False
13-
assert obj.is_periodic(0) == False
14-
assert obj[0] == False
10+
assert not obj.is_any_periodic
11+
assert not obj.is_all_periodic
12+
assert not obj.is_periodic(0)
13+
assert not obj[0]
1514
# with pytest.raises(IndexError):
1615
# obj[3]
1716

@@ -24,13 +23,13 @@ def test_periodicity_3d():
2423
iv = amr.IntVect(1, 0, 1)
2524
obj = amr.Periodicity(iv)
2625
assert obj.is_any_periodic
27-
assert obj.is_all_periodic == False
26+
assert not obj.is_all_periodic
2827
assert obj.is_periodic(0)
29-
assert obj.is_periodic(1) == False
28+
assert not obj.is_periodic(1)
3029
assert obj.is_periodic(2)
31-
assert obj.is_periodic[2]
30+
assert obj[2]
3231

3332
bx = obj.domain
3433
print(bx)
35-
v_iv = ob.shift_IntVect
34+
v_iv = obj.shift_IntVect
3635
print(v_iv)

tests/test_podvector.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# -*- coding: utf-8 -*-
22

3-
import numpy as np
4-
import pytest
5-
63
import amrex.space3d as amr
74

85

tests/test_realbox.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# -*- coding: utf-8 -*-
22

3-
import numpy as np
4-
import pytest
5-
63
import amrex.space3d as amr
74
from amrex.space3d import RealVect as RV
85
from amrex.space3d import XDim3

tests/test_soa.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# -*- coding: utf-8 -*-
22

33
import numpy as np
4-
import pytest
54

65
import amrex.space3d as amr
76

0 commit comments

Comments
 (0)