@@ -444,3 +444,62 @@ def test_ignore_patterns_files(
444444 else :
445445 parse_ig_from_dict .assert_not_called ()
446446 mock_parse_ig_f .assert_not_called ()
447+
448+
449+ @pytest .mark .parametrize (
450+ ["paths" , "path_contains_py" ],
451+ [
452+ pytest .param ([SAMPLES_DIR ], True , id = "samples_dir_x1" ),
453+ pytest .param ([SAMPLES_A .documented ], True , id = "files_x1" ),
454+ pytest .param ([SAMPLES_A .empty , SAMPLES_A .partial ], True , id = "files_x2" ),
455+ pytest .param ([SAMPLES_A .dirpath , SAMPLES_B .dirpath ], True , id = "dirs_x2" ),
456+ pytest .param (
457+ [SAMPLES_A .empty , SAMPLES_A .partial , SAMPLES_B .dirpath ], True , id = "files_x2+dir_x1"
458+ ),
459+ pytest .param ([os .path .join ("sample_files" , "subdir_a" )], True , id = "rel_dir_x1" ),
460+ pytest .param (
461+ [os .path .join ("config_files" , "docstr_ignore.txt" )], False , id = "file_with_no_python"
462+ ),
463+ pytest .param ([os .path .join (CWD , "config_files" )], False , id = "folder_with_no_python" ),
464+ ],
465+ )
466+ @pytest .mark .parametrize (
467+ ["accept_empty_flag" , "accept_empty_value" ],
468+ [
469+ pytest .param ([], False , id = "no_accept_empty" ),
470+ pytest .param (["-a" ], True , id = "short_accept_empty" ),
471+ pytest .param (["--accept-empty" ], True , id = "long_accept_empty" ),
472+ ],
473+ )
474+ @pytest .mark .usefixtures ("cd_tests_dir_fixture" )
475+ def test_accept_empty (
476+ paths : List [str ],
477+ path_contains_py : bool ,
478+ accept_empty_flag : List [str ],
479+ accept_empty_value : bool ,
480+ runner : CliRunner ,
481+ ):
482+ """Test that the `--accept-empty`/`-a` flag leads to the correct exit codes
483+
484+ Parameters
485+ ----------
486+ paths: List[str]
487+ Path arguments provided to CLI. These should be made absolute before they are passed to
488+ :func:`docstr_coverage.cli.collect_filepaths`
489+ path_contains_py: bool
490+ True iff the passed paths point (directly or indirectly via dir) to at least one .py file
491+ accept_empty_flag: List[str]
492+ Flag under test
493+ accept_empty_value: bool
494+ True iff the flag under test specifies to return exit code 0 if no .py file was found
495+ runner: CliRunner
496+ Click utility to invoke command line scripts"""
497+
498+ dont_fail_due_to_coverage = ["--fail-under=5" ]
499+
500+ run_result = runner .invoke (execute , paths + accept_empty_flag + dont_fail_due_to_coverage )
501+
502+ if accept_empty_flag or path_contains_py :
503+ assert run_result .exit_code == 0
504+ else :
505+ assert run_result .exit_code == 1
0 commit comments