|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"input,expected",
|
|
|
|
[
|
|
|
|
("a", False),
|
|
|
|
("", True),
|
|
|
|
(" ", True),
|
|
|
|
(" a ", False),
|
|
|
|
(None, True),
|
|
|
|
(0, False),
|
|
|
|
(2.2, False),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_is_empty_excel_value(input, expected):
|
|
|
|
from superx_budget.helpers import is_empty_excel_value
|
|
|
|
|
|
|
|
result = is_empty_excel_value(input)
|
|
|
|
|
|
|
|
assert result == expected
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"input,expected",
|
|
|
|
[
|
|
|
|
("a", "a"),
|
|
|
|
("", ""),
|
|
|
|
(" ", ""),
|
|
|
|
(" a ", "a"),
|
|
|
|
(None, None),
|
|
|
|
(1, 1),
|
|
|
|
(2.2, 2.2),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_strip_excel_value(input, expected):
|
|
|
|
from superx_budget.helpers import strip_excel_value
|
|
|
|
|
|
|
|
result = strip_excel_value(input)
|
|
|
|
|
|
|
|
assert result == expected
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_sheet_of_file_first(budget_example_file):
|
|
|
|
from superx_budget.helpers import get_sheet_of_file
|
|
|
|
|
|
|
|
sheet = get_sheet_of_file(budget_example_file) # sheet=None
|
|
|
|
first_row = next(sheet.values)
|
|
|
|
first_cell = first_row[0]
|
|
|
|
|
|
|
|
assert first_cell.strip() == "Nr."
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_sheet_of_file_named(budget_example_file):
|
|
|
|
from superx_budget.helpers import get_sheet_of_file
|
|
|
|
|
|
|
|
sheet = get_sheet_of_file(budget_example_file, sheet="Übersicht")
|
|
|
|
first_row = next(sheet.values)
|
|
|
|
first_cell = first_row[0]
|
|
|
|
|
|
|
|
assert first_cell.strip() == "Nr."
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"input,expected",
|
|
|
|
[
|
|
|
|
(None, 0),
|
|
|
|
("", 0),
|
|
|
|
("a", 0),
|
|
|
|
("1", 1.0),
|
|
|
|
("2.4", 2.4),
|
|
|
|
(1, 1),
|
|
|
|
(2.4, 2.4),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_excel_value_as_number(input, expected):
|
|
|
|
from superx_budget.helpers import excel_value_as_number
|
|
|
|
|
|
|
|
result = excel_value_as_number(input)
|
|
|
|
|
|
|
|
assert result == expected
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"name,expected",
|
|
|
|
[
|
|
|
|
("budget-2019.xlsx", True),
|
|
|
|
("budget-template-2020.xlsx", True),
|
|
|
|
("budget-2018.xlsx", False),
|
|
|
|
("xxxxxx-2019.xlsx", False),
|
|
|
|
("budget-2019.xxxx", False),
|
|
|
|
("budget-2x19.xlsx", False),
|
|
|
|
("budget_2019.xlsx", False),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_is_budget_file_name(name, expected):
|
|
|
|
from superx_budget.helpers import is_budget_file_name
|
|
|
|
|
|
|
|
result = is_budget_file_name(name)
|
|
|
|
|
|
|
|
assert result == expected
|
|
|
|
|
|
|
|
|
|
|
|
def test_list_budget_files(example_root):
|
|
|
|
from superx_budget.helpers import list_budget_files
|
|
|
|
|
|
|
|
result = list_budget_files(example_root)
|
|
|
|
|
|
|
|
assert sorted(r.name for r in result) == [
|
|
|
|
"Budget-Vorlage-2019.xlsx",
|
|
|
|
"Budget-Vorlage-2020.xlsx",
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
def test_find_budget_file_found(example_root):
|
|
|
|
from superx_budget.helpers import find_budget_file
|
|
|
|
|
|
|
|
result = find_budget_file(example_root, 2020)
|
|
|
|
|
|
|
|
assert result.name == "Budget-Vorlage-2020.xlsx"
|
|
|
|
|
|
|
|
|
|
|
|
def test_find_budget_file_not_found(example_root):
|
|
|
|
from superx_budget.helpers import find_budget_file
|
|
|
|
|
|
|
|
result = find_budget_file(example_root, 1999)
|
|
|
|
|
|
|
|
assert result is None
|
|
|
|
|
|
|
|
|
|
|
|
def test_find_recipients_ok(example_root):
|
|
|
|
from superx_budget.helpers import find_recipients
|
|
|
|
|
|
|
|
result = find_recipients(example_root, "recipients.txt")
|
|
|
|
|
|
|
|
assert result == [
|
|
|
|
"frey@imtek.de",
|
|
|
|
"imtek@holgerfrey.de",
|
|
|
|
"superx@holgerfrey.de",
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
def test_find_recipients_default(example_root):
|
|
|
|
from superx_budget.helpers import find_recipients
|
|
|
|
|
|
|
|
result = find_recipients(example_root, "unknown file")
|
|
|
|
|
|
|
|
assert result == ["frey@imtek.de"]
|