22import sys
33import pytest
44
5- import gardenlinux .flavors .__main__ as fm
5+ from gardenlinux .flavors import __main__ as fm
6+ from gardenlinux .git import Git
67
78
89def test_generate_markdown_table ():
@@ -98,22 +99,17 @@ def remove_arch(combinations):
9899 return DummyParser
99100
100101
101- def test_main_exits_when_flavors_missing (tmp_path , monkeypatch ):
102- # Arrange
103- # make Git().root point to a tmp dir that does NOT contain flavors.yaml
102+ def _make_git_class (tmp_path ):
103+ """
104+ Factory to create a fake Parser class
105+ Instances ignore the favors_data passed to __init__.
106+ """
107+
104108 class DummyGit :
105109 def __init__ (self ):
106- self .root = str ( tmp_path )
110+ self .root = tmp_path
107111
108- monkeypatch .setattr (fm , "Git" , DummyGit )
109-
110- # ensure no flavors.yaml
111- monkeypatch .setattr (sys , "argv" , ["prog" ])
112-
113- # Act / Assert
114- with pytest .raises (SystemExit ) as excinfo :
115- fm .main ()
116- assert "does not exist" in str (excinfo .value )
112+ return DummyGit
117113
118114
119115def test_main_json_by_arch_prints_json (tmp_path , monkeypatch , capsys ):
@@ -122,14 +118,11 @@ def test_main_json_by_arch_prints_json(tmp_path, monkeypatch, capsys):
122118 flavors_file = tmp_path / "flavors.yaml"
123119 flavors_file .write_text ("dummy: content" )
124120
125- class DummyGit :
126- def __init__ (self ):
127- self .root = str (tmp_path )
128-
129121 # define combinations and expected grouped mapping
130122 combinations = [("x86" , "linux-x86" ), ("arm" , "android-arm" )]
131123 grouped = {"x86" : ["linux-x86" ], "arm" : ["android-arm" ]}
132124
125+ DummyGit = _make_git_class (str (tmp_path ))
133126 DummyParser = _make_parser_class (filter_result = combinations , group_result = grouped )
134127 monkeypatch .setattr (fm , "Git" , DummyGit )
135128 monkeypatch .setattr (fm , "Parser" , DummyParser )
@@ -151,13 +144,11 @@ def test_main_json_by_arch_with_no_arch_strips_arch_suffix(
151144 flavors_file = tmp_path / "flavors.yaml"
152145 flavors_file .write_text ("dummy: content" )
153146
154- class DummyGit :
155- def __init__ (self ):
156- self .root = str (tmp_path )
157-
158147 combinations = [("x86" , "linux-x86" ), ("arm" , "android-arm" )]
159148 # group_by_arch returns items that include architecture suffixes
160149 grouped = {"x86" : ["linux-x86" ], "arm" : ["android-arm" ]}
150+
151+ DummyGit = _make_git_class (str (tmp_path ))
161152 DummyParser = _make_parser_class (filter_result = combinations , group_result = grouped )
162153
163154 monkeypatch .setattr (fm , "Git" , DummyGit )
@@ -179,11 +170,9 @@ def test_main_markdown_table_branch(tmp_path, monkeypatch, capsys):
179170 flavors_file = tmp_path / "flavors.yaml"
180171 flavors_file .write_text ("dummy: content" )
181172
182- class DummyGit :
183- def __init__ (self ):
184- self .root = str (tmp_path )
185-
186173 combinations = [("x86_64" , "linux-x86_64" ), ("armv7" , "android-armv7" )]
174+
175+ DummyGit = _make_git_class (str (tmp_path ))
187176 DummyParser = _make_parser_class (filter_result = combinations )
188177
189178 monkeypatch .setattr (fm , "Git" , DummyGit )
@@ -205,12 +194,10 @@ def test_main_default_prints_flavors_list(tmp_path, monkeypatch, capsys):
205194 flavors_file = tmp_path / "flavors.yaml"
206195 flavors_file .write_text ("dummy: content" )
207196
208- class DummyGit :
209- def __init__ (self ):
210- self .root = str (tmp_path )
211-
212197 # filter returns tuples; main's default branch prints comb[1] values, sorted unique
213198 combinations = [("x86" , "linux-x86" ), ("arm" , "android-arm" )]
199+
200+ DummyGit = _make_git_class (str (tmp_path ))
214201 DummyParser = _make_parser_class (filter_result = combinations )
215202
216203 monkeypatch .setattr (fm , "Git" , DummyGit )
@@ -224,3 +211,25 @@ def __init__(self):
224211
225212 # Assert
226213 assert sorted (lines ) == sorted (["linux-x86" , "android-arm" ])
214+
215+
216+ def test_main_default_prints_git_flavors_list (tmp_path , monkeypatch , capsys ):
217+ # Arrange
218+ flavors_file = tmp_path / "flavors.yaml"
219+ flavors_file .write_text ("dummy: content" )
220+
221+ # filter returns tuples; main's default branch prints comb[1] values, sorted unique
222+ combinations = [("x86" , "linux-x86" ), ("arm" , "android-arm" )]
223+
224+ DummyParser = _make_parser_class (filter_result = combinations )
225+
226+ monkeypatch .setattr (fm , "Parser" , DummyParser )
227+ monkeypatch .setattr (sys , "argv" , ["prog" ])
228+
229+ # Act
230+ fm .main ()
231+ out = capsys .readouterr ().out
232+ lines = out .strip ().splitlines ()
233+
234+ # Assert
235+ assert sorted (lines ) == sorted (["linux-x86" , "android-arm" ])
0 commit comments