Skip to content

Commit

Permalink
fix: Fix parse record error verbiage
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Myslinski committed Jun 24, 2024
1 parent 1d9a36e commit 5f87a81
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions tests/test_parser_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

import io
import sys
import pytest

from vcfpy import parser
from vcfpy import exceptions

__author__ = "Manuel Holtgrewe <[email protected]>"

Expand Down Expand Up @@ -178,3 +180,16 @@ def test_missing_pass(recwarn):
RESULT = p.parse_next_record()
assert str(RESULT) == EXPECTED
assert list(recwarn) == []


def test_parse_line_invalid_number_of_fields():
"""Test parsing VCF file exception message"""
HEADER = "##fileformat=VCFv4.2\n#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\tFORMAT\n"
LINES = "20\t1\t.\tC\tG\t.\tPASS\t.\tGT\n"
EXPECTED = "The line contains an invalid number of fields. Was 9 but expected 8"
p = parser.Parser(io.StringIO(HEADER + LINES), "<builtin>")
p.parse_header()
with pytest.raises(exceptions.InvalidRecordException) as record_error:
p.parse_next_record()

assert EXPECTED in str(record_error.value)
2 changes: 1 addition & 1 deletion vcfpy/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ def _split_line(self, line_str):
raise exceptions.InvalidRecordException(
(
"The line contains an invalid number of fields. Was "
"{} but expected {}\n{}".format(len(arr), 9 + len(self.samples.names), line_str)
"{} but expected {}\n{}".format(len(arr), self.expected_fields, line_str)
)
)
return arr
Expand Down

0 comments on commit 5f87a81

Please sign in to comment.