You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
2.4 KiB
97 lines
2.4 KiB
import pytest |
|
|
|
|
|
@pytest.fixture |
|
def example_file(example_root): |
|
return example_root / "Verbrauchsmittel-Toto-2020.xlsx" |
|
|
|
|
|
@pytest.fixture |
|
def example_workbook(example_file): |
|
import openpyxl |
|
|
|
yield openpyxl.open(example_file) |
|
|
|
|
|
@pytest.fixture |
|
def example_sheet(example_workbook): |
|
sheets = example_workbook.sheetnames |
|
first = sheets[0] |
|
yield example_workbook[first] |
|
|
|
|
|
def test_check_table_header_raises_error(): |
|
from superx_budget.budget import _check_table_header, ExcelRow |
|
from superx_budget.exceptions import BudgetParserError |
|
|
|
row = ExcelRow(None, ["not", "the", "expected", "row"]) |
|
|
|
with pytest.raises(BudgetParserError): |
|
_check_table_header(row) |
|
|
|
|
|
def test_skip_empty_lines(): |
|
from superx_budget.budget import _skip_empty_lines, ExcelRow |
|
|
|
rows = [ |
|
ExcelRow(0, [""]), |
|
ExcelRow(1, ["one"]), |
|
ExcelRow(2, [None]), |
|
ExcelRow(3, [""]), |
|
ExcelRow(4, ["two"]), |
|
ExcelRow(5, [""]), |
|
] |
|
|
|
result = _skip_empty_lines(rows) |
|
|
|
assert list(result) == [(1, ["one"]), (4, ["two"])] |
|
|
|
|
|
def test_parse_data_table(): |
|
from superx_budget.budget import _parse_data_table, ExcelRow |
|
|
|
rows = [ |
|
ExcelRow(2, list("ABCDEFG")), |
|
ExcelRow(3, [None for i in range(7)]), |
|
ExcelRow(4, list("tuvwxyzX")), # one item more |
|
] |
|
|
|
result = _parse_data_table(rows) |
|
first, last = list(result) |
|
|
|
assert first.row == 2 |
|
assert first.number == "A" |
|
assert first.rest == "G" |
|
assert last.row == 4 |
|
assert last.number == "t" |
|
assert last.rest == "z" |
|
|
|
|
|
def test_parse_budget_data(example_sheet): |
|
from superx_budget.budget import parse_budget_data |
|
|
|
result = parse_budget_data(example_sheet) |
|
first, last = result[0], result[-1] |
|
|
|
assert len(result) == 18 |
|
assert first.row == 3 |
|
assert first.number == 1 |
|
assert first.project_name == "Safegurard I (neu)" |
|
assert first.rest == "=E3-F3" |
|
assert last.row == 54 |
|
assert last.number == "=A51+1" |
|
assert last.project_name == "ZIM Microcoat II" |
|
assert last.rest == "=E54-F54" |
|
|
|
|
|
def test_parse_budget_file(example_file): |
|
from superx_budget.budget import parse_budget_file |
|
|
|
result = parse_budget_file(example_file) |
|
first = result[0] |
|
|
|
assert len(result) == 18 |
|
assert first.row == 3 |
|
assert first.number == 1 |
|
assert first.project_name == "Safegurard I (neu)" |
|
assert first.rest == "=E3-F3"
|
|
|