11"""Test Configuration"""
22# pylint: disable=missing-function-docstring
33
4+ from contextlib import contextmanager
45from distutils .dir_util import copy_tree
56from pathlib import Path
67
@@ -125,7 +126,7 @@ def test_class_prefix_doesnt_match(self):
125126 assert cf ().filter (f ) is False
126127
127128
128- class TestDefaultConfig :
129+ class DefaultHelpers :
129130 def check_default_config (self , expected_name ):
130131 assert appmap .enabled ()
131132
@@ -137,6 +138,8 @@ def check_default_config(self, expected_name):
137138 {"path" : "test" },
138139 ]
139140
141+
142+ class TestDefaultConfig (DefaultHelpers ):
140143 def test_created (self , git , data_dir , monkeypatch ):
141144 repo_root = git .cwd
142145 copy_tree (data_dir / "config" , str (repo_root ))
@@ -205,3 +208,43 @@ def test_not_created_if_missing_and_not_enabled(self, git, data_dir, monkeypatch
205208
206209 c = Config ()
207210 assert not path .is_file ()
211+
212+
213+ class TestEmpty (DefaultHelpers ):
214+ @pytest .fixture (autouse = True )
215+ def setup_config (self , data_dir , monkeypatch , tmpdir ):
216+ copy_tree (data_dir / "config" , str (tmpdir ))
217+ monkeypatch .chdir (tmpdir )
218+
219+ @contextmanager
220+ def incomplete_config (self ):
221+ # pylint: disable=protected-access
222+ with open ("appmap-incomplete.yml" , mode = "w" , buffering = 1 ) as f :
223+ print ("# Incomplete file" , file = f )
224+ yield f
225+
226+ def test_empty (self , tmpdir ):
227+ with self .incomplete_config ():
228+ appmap ._implementation .initialize (
229+ cwd = tmpdir ,
230+ env = {"APPMAP" : "true" , "APPMAP_CONFIG" : "appmap-incomplete.yml" },
231+ )
232+ self .check_default_config (Path (tmpdir ).name )
233+
234+ def test_missing_name (self , tmpdir ):
235+ with self .incomplete_config () as f :
236+ print ('packages: [{"path": "package"}, {"path": "test"}]' , file = f )
237+ appmap ._implementation .initialize (
238+ cwd = tmpdir ,
239+ env = {"APPMAP" : "true" , "APPMAP_CONFIG" : "appmap-incomplete.yml" },
240+ )
241+ self .check_default_config (Path (tmpdir ).name )
242+
243+ def test_missing_packages (self , tmpdir ):
244+ with self .incomplete_config () as f :
245+ print (f"name: { Path (tmpdir ).name } " , file = f )
246+ appmap ._implementation .initialize (
247+ cwd = tmpdir ,
248+ env = {"APPMAP" : "true" , "APPMAP_CONFIG" : "appmap-incomplete.yml" },
249+ )
250+ self .check_default_config (Path (tmpdir ).name )
0 commit comments