Creating a budget overview from a SuperX export.
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.
 
 
 
 
 

132 lines
4.1 KiB

"""Stub file for testing the project"""
import pytest
def test_check_export_headline():
from superx_budget.exceptions import SuperXParserError
from superx_budget.superx import _check_export_headline
row = ["nomatching header"]
with pytest.raises(SuperXParserError):
_check_export_headline(row)
def test_get_export_metadata_ok():
from datetime import datetime
from superx_budget.superx import _get_export_metadata
value = "Haushaltsjahr: XXX;Stand:31.12.2020;Gruppierung:automatisch"
row = [value]
metadata = _get_export_metadata(row)
assert metadata.account_year == "XXX"
assert metadata.export_date == datetime(2020, 12, 31)
@pytest.mark.parametrize(
"faulty_data",
[
"Haushaltsjahr:XXX;Kein Stand:31.12.2020;Gruppierung:automatisch",
"Kein Haushaltsjahr:XXX;Stand:31.12.2020;Gruppierung:automatisch",
"Kein Haushaltsjahr:XXX;Kein Stand:31.12.2020;Gruppierung:automatisch",
"Haushaltsjahr:XXX;Stand:kein Datum;Gruppierung:automatisch",
"Haushaltsjahr:XXX;Stand:31.12.2020;keine Gruppierung:automatisch",
"Haushaltsjahr:XXX;Stand:31.12.2020;Gruppierung:nicht automatisch",
],
)
def test_get_export_metadata_raises_error(faulty_data):
from superx_budget.superx import _get_export_metadata
row = [faulty_data]
with pytest.raises(ValueError): # noqa: PT011
_get_export_metadata(row)
def test_skip_export_data_until_table_header_ok():
from superx_budget.superx import _skip_export_data_until_table_header
rows = [[""], [""], ["Kostenstelle"], ["Daten"]]
iterator = iter(rows)
_skip_export_data_until_table_header(iterator)
data_line = next(iterator)
assert data_line[0] == "Daten"
def test_skip_export_data_until_table_header_raises_error():
from superx_budget.exceptions import SuperXParserError
from superx_budget.superx import _skip_export_data_until_table_header
rows = [[""], [""], ["Keine Kostenstelle"], ["Daten"]]
iterator = iter(rows)
with pytest.raises(SuperXParserError):
_skip_export_data_until_table_header(iterator)
def test_parse_data_table():
from superx_budget.superx import _parse_data_table
rows = [
["A ", *list("BCDEFGHIJ")],
["" for i in range(10)],
list("qrstuvwxyzX"), # one column more
]
result = _parse_data_table(rows)
first_value, second_value = list(result)
assert first_value.cost_center == "A"
assert first_value.fonds == "B"
assert first_value.actual_value == "J"
assert second_value.cost_center == "q"
assert second_value.actual_value == "z"
def test_parse_export_data(superx_example_workbook):
from datetime import datetime
from superx_budget.superx import parse_export_data
result = parse_export_data(superx_example_workbook.active)
assert result.account_year == "2020"
assert result.export_date == datetime(2020, 3, 18)
assert len(result.data) == 212
first, last = result.data[0], result.data[-1]
assert first.cost_center == "1110200121"
assert first.fonds == "3310"
assert first.project == "1100068704"
assert first.kind == "1 - Personal"
assert first.budget_year is None
assert first.obligo == 0.01
assert first.expenses == 1000
assert first.revenue_actual == 2000
assert first.revenue_target == 3000
assert first.actual_value == 4000
assert last.cost_center == "1110200121"
assert last.fonds == "1123"
assert last.project == "8200062807"
assert last.kind == "KASSENSTAND zum Ende des Betrachungszeitraums"
assert last.budget_year is None
assert last.obligo == 236
assert last.expenses == 1236
assert last.revenue_actual == 2236
assert last.revenue_target == 3236
assert last.actual_value == 4236
def test_parse_exported_file(superx_example_file):
from superx_budget.superx import parse_exported_file
result = parse_exported_file(superx_example_file)
first = result.data[0]
assert len(result.data) == 212
assert first.cost_center == "1110200121"
assert first.fonds == "3310"
assert first.project == "1100068704"
assert first.kind == "1 - Personal"