Skip to content

Commit

Permalink
Add VUV W analyser reader test
Browse files Browse the repository at this point in the history
  • Loading branch information
k-collie committed Aug 14, 2023
1 parent 3646b3f commit 5ef22f2
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 1 deletion.
32 changes: 32 additions & 0 deletions tests/unit/readers/ppf_samples.json
Original file line number Diff line number Diff line change
Expand Up @@ -3623,5 +3623,37 @@
"min": 0,
"max": 0.5,
"dtype": "float64"
},
"cwuv/n_w": {
"shape": [
33
],
"min": 0,
"max": 1000,
"dtype": "float64"
},
"cwuv/c_w": {
"shape": [
33
],
"min": 0,
"max": 1,
"dtype": "float64"
},
"cwup/n_w": {
"shape": [
33
],
"min": 0,
"max": 1000,
"dtype": "float64"
},
"cwup/c_w": {
"shape": [
33
],
"min": 0,
"max": 1,
"dtype": "float64"
}
}
71 changes: 70 additions & 1 deletion tests/unit/readers/test_ppf_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,74 @@ def test_get_bremsstrahlung_spectroscopy(
)


@given(
integers(28792, 99999),
times,
errors,
max_freqs,
just("jetppf"),
sampled_from(["cwup", "cwuv"]),
revisions,
edited_revisions,
lists(
sampled_from(list(PPFReader.available_quantities("cwup").keys())),
min_size=1,
unique=True,
).map(set),
)
def test_get_vuv_w_analyser(
pulse,
time_range,
error,
freq,
uid,
instrument,
revision,
available_revisions,
quantities,
):
"""
Test data returned by _get_vuv_w_analyser is correct.
"""
reader = patched_ppf_reader(
pulse,
*time_range,
default_error=error,
max_freq=freq,
selector=MagicMock(),
session=MagicMock(),
)
mock_surf = MagicMock(
return_value=(
np.array([0]),
np.array([0]),
np.array([1]),
np.array([1]),
np.array([0]),
np.array([0]),
)
)
reader._client._revisions = available_revisions
bad_rev = revision != 0 and revision < available_revisions[0]

with patch("indica.readers.surf_los.read_surf_los", mock_surf), pytest.raises(
sal.core.exception.NodeNotFound
) if bad_rev else nullcontext():
results = reader._get_vuv_w_analyser(uid, instrument, revision, quantities)
if bad_rev:
return

assert results["machine_dims"] == ((1.83, 3.9), (-1.75, 2.0))
for q in quantities:
signal = reader._client.construct_signal(f"{instrument}/{q}")
assert np.all(results[q] == signal.data)
assert np.all(results["times"] == signal.dimensions[0].data)
assert results[q + "_xstart"].shape == (1,)
assert results[q + "_xstop"].shape == (1,)
assert results[q + "_zstart"].shape == (1,)
assert results[q + "_zstop"].shape == (1,)


@given(
pulses,
times,
Expand All @@ -654,7 +722,7 @@ def test_get_bremsstrahlung_spectroscopy(
text(min_size=1),
sampled_from(sorted(PPFReader.INSTRUMENT_METHODS.keys())),
revisions,
lists(text(), min_size=1, unique=True).map(set),
lists(text(min_size=1), min_size=1, unique=True).map(set),
)
def test_general_get(
pulse, time_range, error, freq, uid, instrument, revision, quantities
Expand All @@ -668,6 +736,7 @@ def test_general_get(
get_cyclotron_emissions=DEFAULT,
get_radiation=DEFAULT,
get_bremsstrahlung_spectroscopy=DEFAULT,
get_vuv_w_analyser=DEFAULT,
), patch("indica.readers.ppfreader.SALClient", JETFakeSALClient):
reader = PPFReader(
pulse,
Expand Down

0 comments on commit 5ef22f2

Please sign in to comment.