def test_header(): """ Tests if the DataLine class correctly parses section headers. """ header_line = DataLine("ROWS") # empty section header. assert_equal(header_line.first_header_word(), "ROWS") header_line = DataLine("INDEP DISCRETE") # parameterised header. assert_equal(header_line.first_header_word(), "INDEP") assert_equal(header_line.second_header_word(), "DISCRETE")
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)