Exemplo n.º 1
0
 def parse_content(self, content):
     if not self.columns:
         raise NotImplementedError("Please override the columns attribute.")
     start_index = calc_offset(content, self.columns, require_all=True)
     valid_lines = content[start_index:]
     reader = DictReader(os.linesep.join(valid_lines).splitlines(True))
     for row in reader:
         self.append(row)
     if not self:
         raise SkipException("There is no data in the table.")
Exemplo n.º 2
0
def test_calc_offset():
    assert calc_offset(OFFSET_CONTENT_1.splitlines(), target=[]) == 0
    assert calc_offset(OFFSET_CONTENT_1.splitlines(), target=[None]) == 0
    assert calc_offset(OFFSET_CONTENT_1.splitlines(), target=['data ']) == 0
    with pytest.raises(ValueError):
        calc_offset(OFFSET_CONTENT_1.splitlines(), target=['xdata '])
    with pytest.raises(ValueError):
        calc_offset(OFFSET_CONTENT_1.splitlines(),
                    target=['data '],
                    invert_search=True)
    assert calc_offset(OFFSET_CONTENT_1.splitlines(),
                       target=['Trailing', 'Blank', 'Another '],
                       invert_search=True) == 0
    assert calc_offset(OFFSET_CONTENT_2.splitlines(), target=[]) == 0
    assert calc_offset(OFFSET_CONTENT_2.splitlines(), target=['data ']) == 3
    assert calc_offset(reversed(OFFSET_CONTENT_2.splitlines()),
                       target=['Trailing', 'Blank', 'Another ', 'Yet'],
                       invert_search=True) == 6