Skip to content

Commit

Permalink
chore: get to 100% test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
clintval committed Jan 10, 2025
1 parent 0c5a14f commit 88d6452
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion fgpyo/sam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,7 @@ def set_tag(
rec.set_tag(tag, value)

def with_aux_alignments(self) -> "Template":
"""Rebuild this template by adding auxiliary alignments from primary alignment tags."""
"""Rebuild this template by adding auxiliary alignments from the primary alignment tags."""
r1_aux = iter([]) if self.r1 is None else AuxAlignment.many_pysam_from_rec(self.r1)
r2_aux = iter([]) if self.r2 is None else AuxAlignment.many_pysam_from_rec(self.r2)
return self.build(recs=chain(self.all_recs(), r1_aux, r2_aux))
Expand Down
18 changes: 18 additions & 0 deletions tests/fgpyo/sam/test_aux_alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,30 @@ def test_from_tag_value_invalid_number_of_commas(tag: str) -> None:
AuxAlignment.from_tag_value(tag, "chr9,104599381")


def test_from_tag_value_raises_invalid_multi_value() -> None:
"""Test that we raise an exception if we receive a multi-value."""
with pytest.raises(
ValueError,
match=(
r"Cannot parse a multi-value string! Found: "
+ r"chr3,\+170653467,49M,4;chr3,\+170653467,49M,4 for tag XA"
),
):
AuxAlignment.from_tag_value("XA", "chr3,+170653467,49M,4;chr3,+170653467,49M,4")


def test_from_tag_value_raises_invalid_tag() -> None:
"""Test that we raise an exception if we receive an unsupported SAM tag."""
with pytest.raises(ValueError, match="Tag XF is not one of SA, XA, XB!"):
AuxAlignment.from_tag_value("XF", "chr3,+170653467,49M,4")


def test_from_tag_value_raises_for_invalid_sa_strand() -> None:
"""Test that we raise an exception when strand is malformed for an SA value."""
with pytest.raises(ValueError, match=r"The strand field is not either '\+' or '-': !"):
AuxAlignment.from_tag_value("SA", "chr3,2000,!,49M,60,4")


@pytest.mark.parametrize("stranded_start", ["!1", "1"])
def test_from_tag_value_raises_for_invalid_xa_stranded_start(stranded_start: str) -> None:
"""Test that we raise an exception when stranded start is malformed for an XA value."""
Expand Down

0 comments on commit 88d6452

Please sign in to comment.