Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix parse record error verbiage #177

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <manuel.holtgrewe@bihealth.de>"

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
Loading