1- import click
21import pytest
32import rechnung .cli as cli
43import rechnung .settings as settings
54
65from click .testing import CliRunner
6+ from shutil import copytree
77from pathlib import Path
8- from mock import patch
9- import os
108
119
1210@pytest .fixture
1311def 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+
3849def 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