Skip to content

Commit

Permalink
Retry added flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
giadarol committed Jan 22, 2023
1 parent 67e32fb commit 38efad9
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions tests/test_pencil_with_absolute_cut.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import xtrack as xt
import xobjects as xo
from xobjects.test_helpers import for_all_test_contexts
from xpart.test_helpers import flaky_assertions, retry

@for_all_test_contexts
@retry()
def test_pencil_with_absolute_cut(test_context):

num_particles = 10000
Expand Down Expand Up @@ -94,25 +96,26 @@ def test_pencil_with_absolute_cut(test_context):
sigma_v = np.sqrt(betv*nemitt_v
/particles._xobject.beta0[0]/particles._xobject.gamma0[0])

assert(np.isclose(np.min(np.abs(v)), abs(absolute_cut), atol=1e-7))
assert(np.isclose(np.max(np.abs(v)), abs(absolute_cut) + sigma_v*pencil_dr_sigmas,
rtol=1e-3, atol=0))
with flaky_assertions():
assert(np.isclose(np.min(np.abs(v)), abs(absolute_cut), atol=1e-7))
assert(np.isclose(np.max(np.abs(v)), abs(absolute_cut) + sigma_v*pencil_dr_sigmas,
rtol=1e-3, atol=0))

i_tip = np.argmax(np.abs(v))
assert np.isclose(pv[i_tip]/v[i_tip], -alfv/betv, atol=5e-4)
i_tip = np.argmax(np.abs(v))
assert np.isclose(pv[i_tip]/v[i_tip], -alfv/betv, atol=5e-4)

if side == '+':
assert np.all(v >= 0)
else:
assert np.all(v <= 0)
if side == '+':
assert np.all(v >= 0)
else:
assert np.all(v <= 0)

other_plane = {'x': 'y', 'y': 'x'}[plane]
w_norm = getattr(norm_coords, other_plane+'_norm')
pw_norm = getattr(norm_coords, 'p'+other_plane+'_norm')
other_plane = {'x': 'y', 'y': 'x'}[plane]
w_norm = getattr(norm_coords, other_plane+'_norm')
pw_norm = getattr(norm_coords, 'p'+other_plane+'_norm')

assert np.allclose(w_in_sigmas, w_norm, 1e-12)
assert np.allclose(pw_in_sigmas, pw_norm, 1e-12)
assert np.allclose(w_in_sigmas, w_norm, 1e-12)
assert np.allclose(pw_in_sigmas, pw_norm, 1e-12)

assert(np.allclose(zeta, particles.zeta, atol=1e-12))
assert(np.allclose(delta, particles.delta, atol=1e-12))
assert(np.allclose(zeta, particles.zeta, atol=1e-12))
assert(np.allclose(delta, particles.delta, atol=1e-12))

0 comments on commit 38efad9

Please sign in to comment.