From 18de981076a8b5e6e829919d8820ee32c1f9eb4c Mon Sep 17 00:00:00 2001 From: Thomas Sell Date: Thu, 2 Nov 2023 11:05:08 +0100 Subject: [PATCH] fix: Handle missing section headers at EOF --- altamisa/isatab/parse_investigation.py | 32 +++++++++++++++++--------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/altamisa/isatab/parse_investigation.py b/altamisa/isatab/parse_investigation.py index 5ac8aff..49cdf0e 100644 --- a/altamisa/isatab/parse_investigation.py +++ b/altamisa/isatab/parse_investigation.py @@ -233,7 +233,9 @@ def _read_single_column_section(self, prefix, ref_keys, section_name): def _read_ontology_source_reference(self) -> Iterator[models.OntologyRef]: # Read ONTOLOGY SOURCE REFERENCE header line = self._read_next_line() - if not line[0] == investigation_headers.ONTOLOGY_SOURCE_REFERENCE: # pragma: no cover + if ( + line is None or not line[0] == investigation_headers.ONTOLOGY_SOURCE_REFERENCE + ): # pragma: no cover tpl = "Expected {} but got {}" msg = tpl.format(investigation_headers.ONTOLOGY_SOURCE_REFERENCE, line) raise ParseIsatabException(msg) @@ -259,7 +261,7 @@ def _read_ontology_source_reference(self) -> Iterator[models.OntologyRef]: def _read_basic_info(self) -> models.BasicInfo: # Read INVESTIGATION header line = self._read_next_line() - if not line[0] == investigation_headers.INVESTIGATION: # pragma: no cover + if line is None or not line[0] == investigation_headers.INVESTIGATION: # pragma: no cover tpl = "Expected {} but got {}" msg = tpl.format(investigation_headers.INVESTIGATION, line) raise ParseIsatabException(msg) @@ -286,7 +288,9 @@ def _read_basic_info(self) -> models.BasicInfo: def _read_publications(self) -> Iterator[models.PublicationInfo]: # Read INVESTIGATION PUBLICATIONS header line = self._read_next_line() - if not line[0] == investigation_headers.INVESTIGATION_PUBLICATIONS: # pragma: no cover + if ( + line is None or not line[0] == investigation_headers.INVESTIGATION_PUBLICATIONS + ): # pragma: no cover tpl = "Expected {} but got {}" msg = tpl.format(investigation_headers.INVESTIGATION_PUBLICATIONS, line) raise ParseIsatabException(msg) @@ -311,7 +315,9 @@ def _read_publications(self) -> Iterator[models.PublicationInfo]: def _read_contacts(self) -> Iterator[models.ContactInfo]: # Read INVESTIGATION CONTACTS header line = self._read_next_line() - if not line[0] == investigation_headers.INVESTIGATION_CONTACTS: # pragma: no cover + if ( + line is None or not line[0] == investigation_headers.INVESTIGATION_CONTACTS + ): # pragma: no cover tpl = "Expected {} but got {}" msg = tpl.format(investigation_headers.INVESTIGATION_CONTACTS, line) raise ParseIsatabException(msg) @@ -359,7 +365,7 @@ def _read_studies(self) -> Iterator[models.StudyInfo]: while self._line: # Read STUDY header line = self._read_next_line() - if not line[0] == investigation_headers.STUDY: # pragma: no cover + if line is None or not line[0] == investigation_headers.STUDY: # pragma: no cover tpl = "Expected {} but got {}" msg = tpl.format(investigation_headers.INVESTIGATION, line) raise ParseIsatabException(msg) @@ -399,7 +405,9 @@ def _read_studies(self) -> Iterator[models.StudyInfo]: def _read_study_design_descriptors(self) -> Iterator[models.FreeTextOrTermRef]: # Read STUDY DESIGN DESCRIPTORS header line = self._read_next_line() - if not line[0] == investigation_headers.STUDY_DESIGN_DESCRIPTORS: # pragma: no cover + if ( + line is None or not line[0] == investigation_headers.STUDY_DESIGN_DESCRIPTORS + ): # pragma: no cover tpl = "Expected {} but got {}" msg = tpl.format(investigation_headers.STUDY_DESIGN_DESCRIPTORS, line) raise ParseIsatabException(msg) @@ -419,7 +427,9 @@ def _read_study_design_descriptors(self) -> Iterator[models.FreeTextOrTermRef]: def _read_study_publications(self) -> Iterator[models.PublicationInfo]: # Read STUDY PUBLICATIONS header line = self._read_next_line() - if not line[0] == investigation_headers.STUDY_PUBLICATIONS: # pragma: no cover + if ( + line is None or not line[0] == investigation_headers.STUDY_PUBLICATIONS + ): # pragma: no cover tpl = "Expected {} but got {}" msg = tpl.format(investigation_headers.STUDY_PUBLICATIONS, line) raise ParseIsatabException(msg) @@ -444,7 +454,7 @@ def _read_study_publications(self) -> Iterator[models.PublicationInfo]: def _read_study_factors(self) -> Iterator[models.FactorInfo]: # Read STUDY FACTORS header line = self._read_next_line() - if not line[0] == investigation_headers.STUDY_FACTORS: # pragma: no cover + if line is None or not line[0] == investigation_headers.STUDY_FACTORS: # pragma: no cover tpl = "Expected {} but got {}" msg = tpl.format(investigation_headers.STUDY_FACTORS, line) raise ParseIsatabException(msg) @@ -464,7 +474,7 @@ def _read_study_factors(self) -> Iterator[models.FactorInfo]: def _read_study_assays(self) -> Iterator[models.AssayInfo]: # Read STUDY ASSAYS header line = self._read_next_line() - if not line[0] == investigation_headers.STUDY_ASSAYS: # pragma: no cover + if line is None or not line[0] == investigation_headers.STUDY_ASSAYS: # pragma: no cover tpl = "Expected {} but got {}" msg = tpl.format(investigation_headers.STUDY_ASSAYS, line) raise ParseIsatabException(msg) @@ -517,7 +527,7 @@ def _read_study_assays(self) -> Iterator[models.AssayInfo]: def _read_study_protocols(self) -> Iterator[models.ProtocolInfo]: # Read STUDY PROTOCOLS header line = self._read_next_line() - if not line[0] == investigation_headers.STUDY_PROTOCOLS: # pragma: no cover + if line is None or not line[0] == investigation_headers.STUDY_PROTOCOLS: # pragma: no cover tpl = "Expected {} but got {}" msg = tpl.format(investigation_headers.STUDY_PROTOCOLS, line) raise ParseIsatabException(msg) @@ -581,7 +591,7 @@ def _read_study_protocols(self) -> Iterator[models.ProtocolInfo]: def _read_study_contacts(self) -> Iterator[models.ContactInfo]: # Read STUDY CONTACTS header line = self._read_next_line() - if not line[0] == investigation_headers.STUDY_CONTACTS: # pragma: no cover + if line is None or not line[0] == investigation_headers.STUDY_CONTACTS: # pragma: no cover tpl = "Expected {} but got {}" msg = tpl.format(investigation_headers.STUDY_CONTACTS, line) raise ParseIsatabException(msg)