3232
3333runner = CliRunner ()
3434
35+ # log format strings produced by the fremor group callback (cli.py / fremor)
36+ LOG_INFO_LINE = '[ INFO: cli.py: fremor] fre_file_handler added to base_fre_logger\n ' # pylint: disable=line-too-long
37+ LOG_DEBUG_LINE = '[DEBUG: cli.py: fremor] click entry-point function call done.\n ' # pylint: disable=line-too-long
38+
3539
3640# ── setup ──────────────────────────────────────────────────────────────────
3741
@@ -53,57 +57,39 @@ def test_cli_fremor_help():
5357 result = runner .invoke (fremor , args = ["--help" ])
5458 assert result .exit_code == 0
5559
56- def test_cli_fremor_help_and_debuglog ():
57- ''' fremor -vv -l TEST_FOO_LOG.log yaml --help (logs created by group callback) '''
58- if Path ("TEST_FOO_LOG.log" ).exists ():
59- Path ("TEST_FOO_LOG.log" ).unlink ()
60- assert not Path ("TEST_FOO_LOG.log" ).exists ()
60+ def test_cli_fremor_help_and_debuglog (tmp_path ):
61+ ''' fremor -vv -l LOG yaml --help (logs created by group callback) '''
62+ log_file = tmp_path / 'TEST_FOO_LOG.log'
6163
62- result = runner .invoke (fremor , args = ["-vv" , "-l" , "TEST_FOO_LOG.log" , "yaml" , "--help" ])
64+ result = runner .invoke (fremor , args = ["-vv" , "-l" , str ( log_file ) , "yaml" , "--help" ])
6365 assert result .exit_code == 0
64- assert Path ("TEST_FOO_LOG.log" ).exists ()
65-
66- log_text_line_1 = '[ INFO: cli.py: fremor] fre_file_handler added to base_fre_logger\n ' # pylint: disable=line-too-long
67- log_text_line_2 = '[DEBUG: cli.py: fremor] click entry-point function call done.\n ' # pylint: disable=line-too-long
68- with open ( "TEST_FOO_LOG.log" , 'r' , encoding = 'utf-8' ) as log_text :
69- line_list = log_text .readlines ()
70- assert log_text_line_1 in line_list [0 ]
71- assert log_text_line_2 in line_list [1 ]
66+ assert log_file .exists ()
7267
73- Path ("TEST_FOO_LOG.log" ).unlink ()
68+ line_list = log_file .read_text (encoding = 'utf-8' ).splitlines (keepends = True )
69+ assert LOG_INFO_LINE in line_list [0 ]
70+ assert LOG_DEBUG_LINE in line_list [1 ]
7471
75- def test_cli_fremor_help_and_infolog ():
76- ''' fremor -v -l TEST_FOO_LOG.log yaml --help '''
77- if Path ("TEST_FOO_LOG.log" ).exists ():
78- Path ("TEST_FOO_LOG.log" ).unlink ()
79- assert not Path ("TEST_FOO_LOG.log" ).exists ()
72+ def test_cli_fremor_help_and_infolog (tmp_path ):
73+ ''' fremor -v -l LOG yaml --help '''
74+ log_file = tmp_path / 'TEST_FOO_LOG.log'
8075
81- result = runner .invoke (fremor , args = ["-v" , "-l" , "TEST_FOO_LOG.log" , "yaml" , "--help" ])
76+ result = runner .invoke (fremor , args = ["-v" , "-l" , str ( log_file ) , "yaml" , "--help" ])
8277 assert result .exit_code == 0
83- assert Path ( "TEST_FOO_LOG.log" ) .exists ()
78+ assert log_file .exists ()
8479
85- log_text_line_1 = '[ INFO: cli.py: fremor] fre_file_handler added to base_fre_logger\n ' # pylint: disable=line-too-long
86- with open ( "TEST_FOO_LOG.log" , 'r' , encoding = 'utf-8' ) as log_text :
87- line_list = log_text .readlines ()
88- assert log_text_line_1 in line_list [0 ]
80+ line_list = log_file .read_text (encoding = 'utf-8' ).splitlines (keepends = True )
81+ assert LOG_INFO_LINE in line_list [0 ]
8982
90- Path ("TEST_FOO_LOG.log" ).unlink ()
83+ def test_cli_fremor_help_and_quietlog (tmp_path ):
84+ ''' fremor -q -l LOG yaml --help '''
85+ log_file = tmp_path / 'TEST_FOO_LOG.log'
9186
92- def test_cli_fremor_help_and_quietlog ():
93- ''' fremor -q -l TEST_FOO_LOG.log yaml --help '''
94- if Path ("TEST_FOO_LOG.log" ).exists ():
95- Path ("TEST_FOO_LOG.log" ).unlink ()
96- assert not Path ("TEST_FOO_LOG.log" ).exists ()
97-
98- result = runner .invoke (fremor , args = ["-q" , "-l" , "TEST_FOO_LOG.log" , "yaml" , "--help" ])
87+ result = runner .invoke (fremor , args = ["-q" , "-l" , str (log_file ), "yaml" , "--help" ])
9988 assert result .exit_code == 0
100- assert Path ("TEST_FOO_LOG.log" ).exists ()
101-
102- with open ( "TEST_FOO_LOG.log" , 'r' , encoding = 'utf-8' ) as log_text :
103- line_list = log_text .readlines ()
104- assert line_list == []
89+ assert log_file .exists ()
10590
106- Path ("TEST_FOO_LOG.log" ).unlink ()
91+ line_list = log_file .read_text (encoding = 'utf-8' ).splitlines (keepends = True )
92+ assert line_list == []
10793
10894def test_cli_fremor_opt_dne ():
10995 ''' fremor optionDNE '''
0 commit comments