33
44import pytest
55
6- from licensecheck .io .cli import main
6+ from licensecheck .io .cli import ExitCode , main
77from licensecheck .models .config import LC_Config
88
99
@@ -29,6 +29,28 @@ def config() -> LC_Config:
2929 )
3030
3131
32+ @pytest .fixture
33+ def config_invalid_fmt () -> LC_Config :
34+ return LC_Config (
35+ requirements_paths = {"requirements.txt" },
36+ file = None ,
37+ license = "MIT" ,
38+ pypi_api = None ,
39+ groups = set (),
40+ extras = set (),
41+ ignore_packages = set (),
42+ fail_packages = set (),
43+ ignore_licenses = set (),
44+ fail_licenses = set (),
45+ only_licenses = set (),
46+ skip_dependencies = set (),
47+ hide_output_parameters = set (),
48+ format = "invalid_format" ,
49+ show_only_failing = False ,
50+ zero = False ,
51+ )
52+
53+
3254def test_main_success (
3355 config : LC_Config ,
3456 monkeypatch ,
@@ -48,14 +70,13 @@ def test_main_success(
4870 lambda * _args , ** _kwargs : "output" ,
4971 )
5072
51- assert main (config ) == 0
73+ assert main (config ) == ExitCode . SUCCESS
5274
5375
5476def test_main_invalid_format (
55- config : LC_Config ,
77+ config_invalid_fmt : LC_Config ,
5678 monkeypatch ,
5779) -> None :
58- config .format = "does-not-exist"
5980
6081 monkeypatch .setattr (
6182 "licensecheck.io.cli.checker.check" ,
@@ -67,16 +88,16 @@ def test_main_invalid_format(
6788 {},
6889 )
6990
70- assert main (config ) == 2
91+ assert main (config_invalid_fmt ) == ExitCode . SUCCESS
7192
7293
7394@pytest .mark .parametrize (
7495 ("zero" , "incompatible" , "expected" ),
7596 [
76- (False , False , 0 ),
77- (False , True , 0 ),
78- (True , False , 0 ),
79- (True , True , 1 ),
97+ (False , False , ExitCode . SUCCESS ),
98+ (False , True , ExitCode . SUCCESS ),
99+ (True , False , ExitCode . NO_PACKAGES ),
100+ (True , True , ExitCode . INCOMPATIBLE_LICENSE ),
80101 ],
81102)
82103def test_main_exit_code_zero_mode (
@@ -155,7 +176,7 @@ def test_main_valid_hidden_parameters(
155176 lambda * _args , ** _kwargs : "" ,
156177 )
157178
158- assert main (config ) == 0
179+ assert main (config ) == ExitCode . SUCCESS
159180
160181
161182def test_main_passes_args_to_checker (
@@ -214,5 +235,5 @@ def test_main_closes_output_file(
214235 lambda * _args , ** _kwargs : "hello" ,
215236 )
216237
217- assert main (config ) == 0
238+ assert main (config ) == ExitCode . SUCCESS
218239 assert output .read_text () == "hello\n "
0 commit comments