def _transition(self, data_line: DataLine) -> bool: """ Transitions to parsing the next section, defined by this line. Parameters ---------- data_line : DataLine The section header line. Returns ------- bool True if after transitioning this line should be skipped, False otherwise. """ assert data_line.is_header() header = data_line.first_header_word() if header == self._state: # This is the initial state, which has a name attribute that should # be parsed. return False if header in self._steps or header == "ENDATA": logger.info(f"Now parsing the {header} section.") self._state = header return True msg = f"Section {header} is not understood - skipping its entries." warnings.warn(msg) logger.warning(msg) self._state = "SKIP" return True
def test_first_header_word(line, expected): """ The first word field on a header line is the 1-14 column range (inclusive). """ header_line = DataLine(line) assert_(header_line.is_header()) assert_equal(header_line.first_header_word(), expected)
def test_second_header_word(line, expected): """ The second word field on a header line is the 15-72 column range (inclusive). """ padding = "NAME" + " " * 10 # second data word starts at column 15. header_line = DataLine(padding + line) assert_(header_line.is_header()) assert_equal(header_line.second_header_word(), expected)
def test_is_header(line, expected): """ Tests if the DataLine class correctly detects section headers. """ data_line = DataLine(line) assert_equal(data_line.is_header(), expected)