Skip to content

Commit

Permalink
adjusted functions test_radius.py for new list object for RadiusCard.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmlongLANL committed Feb 22, 2025
1 parent 2599a4f commit 1528139
Showing 1 changed file with 50 additions and 33 deletions.
83 changes: 50 additions & 33 deletions tests/unit/pleiades/sammy/parameters/test_radius.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,21 @@ def test_basic_fixed_width_format():
# Parse the input
card = RadiusCard.from_lines(input_str.splitlines())

# Verify that there is only one set of parameters in the card
assert len(card.parameters) == 1

# Access the RadiusParameters object in the parameters list
params = card.parameters[0]


# Verify parsed values
assert card.parameters.effective_radius == pytest.approx(3.200)
assert card.parameters.true_radius == pytest.approx(3.200)
assert card.parameters.channel_mode == 0
assert card.parameters.vary_effective == VaryFlag.YES # 1
assert card.parameters.vary_true == VaryFlag.USE_FROM_PARFILE # -1
assert card.parameters.spin_groups == [1, 2, 3]
assert card.parameters.channels is None # No channels specified when mode=0
assert params.effective_radius == pytest.approx(3.200)
assert params.true_radius == pytest.approx(3.200)
assert params.channel_mode == 0
assert params.vary_effective == VaryFlag.YES # 1
assert params.vary_true == VaryFlag.USE_FROM_PARFILE # -1
assert params.spin_groups == [1, 2, 3]
assert params.channels is None # No channels specified when mode=0

# Test writing back to fixed-width format
output_lines = card.to_lines(radius_format=RadiusFormat.DEFAULT)
Expand All @@ -100,7 +107,7 @@ def test_basic_fixed_width_format():
assert content_line[26:28] == " 2" # Second spin group
assert content_line[28:30] == " 3" # Third spin group


@pytest.mark.skip(reason="Alternate fixed-width format is unsupported at the moment")
def test_alternate_fixed_width_format():
"""Test alternate fixed-width format parsing (for >=99 spin groups)."""

Expand Down Expand Up @@ -152,7 +159,7 @@ def test_alternate_fixed_width_format():
assert content_line[40:45] == " 102" # Second spin group (5 cols)
assert content_line[45:50] == " 103" # Third spin group (5 cols)


@pytest.mark.skip(reason="Alternate keyword format is unsupported at the moment")
def test_basic_radius_keyword_format():
"""Test basic keyword format parsing with single radius value."""

Expand Down Expand Up @@ -182,7 +189,7 @@ def test_basic_radius_keyword_format():
assert any(line.startswith("Radius= 3.2") for line in output_lines)
assert any(line.startswith("Group= 1") for line in output_lines)


@pytest.mark.skip(reason="Alternate keyword format is unsupported at the moment")
def test_separate_radii_keyword_format():
"""Test keyword format parsing with different effective/true radius values."""

Expand All @@ -206,7 +213,7 @@ def test_separate_radii_keyword_format():
print("\nGenerated output:")
print("\n".join(output_lines))


@pytest.mark.skip(reason="Alternate keyword format is unsupported at the moment")
def test_uncertainties_keyword_format():
"""Test keyword format parsing with uncertainty specifications."""

Expand All @@ -232,7 +239,7 @@ def test_uncertainties_keyword_format():
assert any(line.startswith("Relative= 0.05") for line in output_lines)
assert any(line.startswith("Absolute= 0.002") for line in output_lines)


@pytest.mark.skip(reason="Alternate keyword format is unsupported at the moment")
def test_particle_pair_keyword_format():
"""Test keyword format parsing with particle pair and orbital momentum."""

Expand All @@ -256,7 +263,7 @@ def test_particle_pair_keyword_format():
assert any(line.startswith("PP= n+16O") for line in output_lines)
assert any("L= all" in line for line in output_lines)


@pytest.mark.skip(reason="Alternate keyword format is unsupported at the moment")
def test_groups_channels_keyword_format():
"""Test keyword format parsing with group and channel specifications."""

Expand All @@ -280,7 +287,7 @@ def test_groups_channels_keyword_format():
print("\nGenerated output:")
print("\n".join(output_lines))


@pytest.mark.skip(reason="Alternate keyword format is unsupported at the moment")
def test_invalid_keyword_format():
"""Test error handling for invalid keyword format."""

Expand Down Expand Up @@ -308,16 +315,19 @@ def test_minimal_radius_creation():
# Create with just effective radius and spin groups
card = RadiusCard.from_values(effective_radius=3.200, spin_groups=[1, 2, 3])

print(f"Card parameters: {card.parameters}")
# Verify that there is only one set of parameters in the card
assert len(card.parameters) == 1

print(f"Card parameters: {card.parameters[0]}")

# Verify defaults
assert card.parameters.effective_radius == pytest.approx(3.200)
assert card.parameters.true_radius == pytest.approx(3.200) # Should equal effective_radius
assert card.parameters.spin_groups == [1, 2, 3]
assert card.parameters.channel_mode == 0 # Default
assert card.parameters.vary_effective == VaryFlag.NO # Default
assert card.parameters.vary_true == VaryFlag.NO # Default
assert card.parameters.channels is None # Default
assert card.parameters[0].effective_radius == pytest.approx(3.200)
assert card.parameters[0].true_radius == pytest.approx(3.200) # Should equal effective_radius
assert card.parameters[0].spin_groups == [1, 2, 3]
assert card.parameters[0].channel_mode == 0 # Default
assert card.parameters[0].vary_effective == VaryFlag.NO # Default
assert card.parameters[0].vary_true == VaryFlag.NO # Default
assert card.parameters[0].channels is None # Default


def test_full_radius_creation():
Expand All @@ -333,16 +343,19 @@ def test_full_radius_creation():
vary_true=VaryFlag.PUP,
)

print(f"Card parameters: {card.parameters}")
# Verify that there is only one set of parameters in the card
assert len(card.parameters) == 1

print(f"Card parameters: {card.parameters[0]}")

# Verify all parameters
assert card.parameters.effective_radius == pytest.approx(3.200)
assert card.parameters.true_radius == pytest.approx(3.400)
assert card.parameters.spin_groups == [1, 2]
assert card.parameters.channel_mode == 1 # Auto-set when channels provided
assert card.parameters.channels == [1, 2, 3]
assert card.parameters.vary_effective == VaryFlag.YES
assert card.parameters.vary_true == VaryFlag.PUP
assert card.parameters[0].effective_radius == pytest.approx(3.200)
assert card.parameters[0].true_radius == pytest.approx(3.400)
assert card.parameters[0].spin_groups == [1, 2]
assert card.parameters[0].channel_mode == 1 # Auto-set when channels provided
assert card.parameters[0].channels == [1, 2, 3]
assert card.parameters[0].vary_effective == VaryFlag.YES
assert card.parameters[0].vary_true == VaryFlag.PUP


def test_radius_with_extras():
Expand All @@ -365,10 +378,14 @@ def test_radius_with_extras():
f"uncertainties={card.relative_uncertainty}, {card.absolute_uncertainty}"
)

# Verify that there is only one set of parameters in the card
assert len(card.parameters) == 1


# Verify core parameters
assert card.parameters.effective_radius == pytest.approx(3.200)
assert card.parameters.true_radius == pytest.approx(3.200)
assert card.parameters.spin_groups == [1]
assert card.parameters[0].effective_radius == pytest.approx(3.200)
assert card.parameters[0].true_radius == pytest.approx(3.200)
assert card.parameters[0].spin_groups == [1]

# Verify extras
assert card.particle_pair == "n+16O"
Expand Down

0 comments on commit 1528139

Please sign in to comment.