Skip to content

Commit b482833

Browse files
committed
add print-stats test and fixture with test fixtures
1 parent f842d42 commit b482833

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

rechnung/tests/fixtures/settings.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
company: Westnetz and Reudnetz Software
2+
company_address: "Karl-Heine-Str. 93, 04229 Leipzig"
3+
company_bank: "Volksbank Leipzig"
24
contract_mail_subject: "Your new contract"
35
insecure: true
46
invoice_mail_subject: "Your new invoice"

rechnung/tests/test_cli.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
import click
21
import pytest
32
import rechnung.cli as cli
43
import rechnung.settings as settings
54

65
from click.testing import CliRunner
6+
from shutil import copytree
77
from pathlib import Path
8-
from mock import patch
9-
import os
108

119

1210
@pytest.fixture
1311
def cli_path(tmp_path):
1412
"""
1513
Returnes the click.CommandGroup of cli.py holding all executeable commands,
16-
but with the module withe variable "cwd" overwritten to a temporary path. This is
14+
but with the module withe variable "cwd" overwritten to a temporary path. This is
1715
required as the current working directory is determined by os.getcwd() on import
1816
olf rechnung.cli
1917
"""
@@ -31,10 +29,23 @@ def initialized_path(tmp_path_factory):
3129
tmp_path.mkdir()
3230
cli.cwd = tmp_path
3331
runner = CliRunner()
34-
result = runner.invoke(cli.cli1, ["init"])
32+
runner.invoke(cli.cli1, ["init"])
3533
return tmp_path
3634

3735

36+
@pytest.fixture(scope="session")
37+
def cli_test_data_path(tmp_path_factory):
38+
"""
39+
Returns a path where rechnung is initialized in order to verify correct creation
40+
of directories and files
41+
"""
42+
tmp_path = tmp_path_factory.getbasetemp()
43+
cli_path = tmp_path / "rechnung_test_data"
44+
copytree(Path("rechnung/tests/fixtures"), cli_path)
45+
cli.cwd = cli_path
46+
return cli.cli1, cli_path
47+
48+
3849
def test_init_exit_code(cli_path):
3950
"""
4051
Tests if the initialization function returns the correct exit codes.
@@ -57,6 +68,15 @@ def test_init_files_directories(initialized_path):
5768
if setting_k.endswith("_dir"):
5869
expected_elements.append(setting_v)
5970
for element in initialized_path.iterdir():
60-
print(f"x: {element.name}")
6171
expected_elements.remove(element.name)
6272
assert not len(expected_elements)
73+
74+
75+
def test_print_stats(cli_test_data_path):
76+
cli1, path = cli_test_data_path
77+
runner = CliRunner()
78+
result = runner.invoke(cli1, ["print-stats"])
79+
assert "108.66" in result.output
80+
81+
82+
# assert False

0 commit comments

Comments
 (0)