Skip to content

Commit

Permalink
Add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
bhazelton committed Aug 26, 2024
1 parent bb22559 commit afa5f69
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/pyuvdata/uvbeam/beam_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def __eq__(self, other: Any, silent: bool = False) -> bool:
# If analytic, also check that the beam_type is the same
if self.beam.__ne__(other.beam, silent=silent):
if not silent:
print("Beams do not match. ")
print("Beams do not match.")
return False
if not self._isuvbeam and self.beam_type != other.beam_type:
if not silent:
Expand Down
61 changes: 50 additions & 11 deletions tests/uvbeam/test_analytic_beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,29 +291,65 @@ def test_eval_errors(az_za_deg_grid):


@pytest.mark.parametrize(
["compare_beam", "equality", "operation"],
["compare_beam", "equality", "operation", "msg"],
[
[UVBeam(), False, None],
[UniformBeam(), False, None],
[GaussianBeam(sigma=0.05), False, None],
[UVBeam(), False, None, "Classes do not match"],
[UniformBeam(), False, None, "Classes do not match"],
[
GaussianBeam(sigma=0.05),
False,
None,
"attribute sigma does not match. Left is 0.02, right is 0.05.",
],
[
GaussianBeam(sigma=0.02, reference_frequency=100e8, spectral_index=-1.5),
False,
None,
"attribute",
],
[GaussianBeam(sigma=0.02), True, None, None],
[
GaussianBeam(sigma=0.02),
False,
"del_attr",
"Sets of parameters do not match",
],
[
GaussianBeam(sigma=0.02),
False,
"change_attr_type",
"attribute feed_array are not the same types",
],
[
GaussianBeam(sigma=0.02),
False,
"change_array_shape",
"attribute polarization_array do not have the same shapes",
],
[
GaussianBeam(sigma=0.02),
False,
"change_num_array_vals",
"attribute polarization_array does not match",
],
[
GaussianBeam(sigma=0.02),
False,
"change_str_array_vals",
"attribute feed_array does not match after converting string numpy "
"array to list",
],
[GaussianBeam(sigma=0.02), True, None],
[GaussianBeam(sigma=0.02), False, "del_attr"],
[GaussianBeam(sigma=0.02), False, "change_attr_type"],
[GaussianBeam(sigma=0.02), False, "change_array_shape"],
[GaussianBeam(sigma=0.02), False, "change_num_array_vals"],
[GaussianBeam(sigma=0.02), False, "change_str_array_vals"],
],
)
def test_comparison(compare_beam, equality, operation):
def test_comparison(capsys, compare_beam, equality, operation, msg):
"""
Beam __eq__ method
"""
beam = GaussianBeam(sigma=0.02)
beam.name = "Analytic Gaussian"

if isinstance(compare_beam, GaussianBeam):
compare_beam.name = "Analytic Gaussian"

if operation == "del_attr":
del compare_beam.spectral_index
Expand All @@ -330,6 +366,9 @@ def test_comparison(compare_beam, equality, operation):
assert beam == compare_beam
else:
assert beam != compare_beam
assert not beam == compare_beam # noqa SIM201
captured = capsys.readouterr()
assert captured.out.startswith(msg)


@pytest.mark.parametrize(
Expand Down
16 changes: 14 additions & 2 deletions tests/uvbeam/test_beam_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,41 +176,53 @@ def test_beam_interface(


@pytest.mark.parametrize(
["bi1", "bi2", "equality"],
["bi1", "bi2", "equality", "msg"],
[
[
BeamInterface(ShortDipoleBeam(), beam_type="efield"),
BeamInterface(ShortDipoleBeam(), beam_type="efield"),
True,
None,
],
[
BeamInterface(ShortDipoleBeam(), beam_type="efield"),
BeamInterface(ShortDipoleBeam(), beam_type="power"),
False,
"Beam types do not match. Left is efield, right is power.",
],
[
BeamInterface(ShortDipoleBeam(), beam_type="efield"),
BeamInterface(AiryBeam(diameter=14.0), beam_type="efield"),
False,
"Classes do not match",
],
[
BeamInterface(AiryBeam(diameter=12.0), beam_type="efield"),
BeamInterface(AiryBeam(diameter=14.0), beam_type="efield"),
False,
"attribute diameter does not match. Left is 12.0, right is 14.0.\n"
"Beams do not match.",
],
[
BeamInterface(ShortDipoleBeam(), beam_type="efield"),
ShortDipoleBeam(),
False,
"Classes do not match",
],
],
)
def test_beam_interface_equality(bi1, bi2, equality):
def test_beam_interface_equality(capsys, bi1, bi2, equality, msg):
if isinstance(bi1, BeamInterface) and isinstance(bi1.beam, AiryBeam):
bi1.beam.name = "Analytic Airy"
if isinstance(bi2, BeamInterface) and isinstance(bi2.beam, AiryBeam):
bi2.beam.name = "Analytic Airy"
if equality:
assert bi1 == bi2
else:
assert bi1 != bi2
assert not bi1 == bi2 # noqa SIM201
captured = capsys.readouterr()
assert captured.out.startswith(msg)


def test_beam_interface_errors():
Expand Down

0 comments on commit afa5f69

Please sign in to comment.