@@ -54,14 +54,18 @@ def test_create_profile_nested_conflict(tmp_path: Path):
5454
5555
5656def test_create_config (tmp_path : Path ):
57+ (tmp_path / "config.py" ).touch ()
5758 profile = Profile ("test" , tmp_path )
5859 config_dir = profile .root / "config"
5960 config_dir .mkdir (parents = True )
60- profiles .create_config (profile , tmp_path , "" )
61- assert list (config_dir .iterdir ()) == [config_dir / "config.py" ]
61+ profiles .create_config (profile , tmp_path , "{source_config_py}" )
62+ config = config_dir / "config.py"
63+ assert list (config_dir .iterdir ()) == [config ]
64+ assert str (tmp_path / "config.py" ) in config .read_text ()
6265
6366
6467def test_overwrite_config (tmp_path : Path ):
68+ (tmp_path / "config.py" ).touch ()
6569 profile = Profile ("test" , tmp_path )
6670 url = "http://example.com"
6771 config_dir = profile .root / "config"
@@ -76,6 +80,41 @@ def test_overwrite_config(tmp_path: Path):
7680 raise AssertionError ()
7781
7882
83+ def test_link_autoconfig (tmp_path : Path ):
84+ profile = Profile ("test" , tmp_path )
85+ config_dir = profile .root / "config"
86+ config_dir .mkdir (parents = True )
87+ (tmp_path / "autoconfig.yml" ).touch ()
88+ profiles .link_autoconfig (profile , tmp_path , False )
89+ config = config_dir / "autoconfig.yml"
90+ assert list (config_dir .iterdir ()) == [config ]
91+ assert config .resolve ().parent == tmp_path
92+
93+
94+ def test_autoconfig_present (tmp_path : Path ):
95+ profile = Profile ("test" , tmp_path )
96+ config_dir = profile .root / "config"
97+ config_dir .mkdir (parents = True )
98+ (tmp_path / "autoconfig.yml" ).touch ()
99+ profiles .link_autoconfig (profile , tmp_path , False )
100+ profiles .link_autoconfig (profile , tmp_path , False )
101+ config = config_dir / "autoconfig.yml"
102+ assert list (config_dir .iterdir ()) == [config ]
103+ assert config .resolve ().parent == tmp_path
104+
105+
106+ def test_overwrite_autoconfig (tmp_path : Path ):
107+ profile = Profile ("test" , tmp_path )
108+ config_dir = profile .root / "config"
109+ config_dir .mkdir (parents = True )
110+ (config_dir / "autoconfig.yml" ).touch ()
111+ (tmp_path / "autoconfig.yml" ).touch ()
112+ profiles .link_autoconfig (profile , tmp_path , True )
113+ config = config_dir / "autoconfig.yml"
114+ assert set (config_dir .iterdir ()) == {config , config_dir / "autoconfig.yml.bak" }
115+ assert config .resolve ().parent == tmp_path
116+
117+
79118def test_new_profile (tmp_path : Path ):
80119 (tmp_path / "config.py" ).touch ()
81120 profile = Profile ("test" , tmp_path / "test" )
@@ -86,16 +125,41 @@ def test_new_profile(tmp_path: Path):
86125 check_new_profile (profile )
87126
88127
128+ def test_new_profile_autoconfig (tmp_path : Path ):
129+ (tmp_path / "autoconfig.yml" ).touch ()
130+ profile = Profile ("test" , tmp_path / "test" )
131+ config = Config .load (None )
132+ config .qutebrowser_config_directory = tmp_path
133+ config .generate_desktop_file = False
134+ config .symlink_autoconfig = True
135+ profiles .new_profile (profile , config )
136+ config_dir = profile .root / "config"
137+ assert set (config_dir .iterdir ()) == {config_dir / "autoconfig.yml" }
138+
139+
140+ def test_new_profile_both (tmp_path : Path ):
141+ (tmp_path / "config.py" ).touch ()
142+ (tmp_path / "autoconfig.yml" ).touch ()
143+ profile = Profile ("test" , tmp_path / "test" )
144+ config = Config .load (None )
145+ config .qutebrowser_config_directory = tmp_path
146+ config .generate_desktop_file = False
147+ config .symlink_autoconfig = True
148+ profiles .new_profile (profile , config )
149+ assert len (set ((profile .root / "config" ).iterdir ())) == 2 # noqa: PLR2004
150+
151+
89152def test_config_template (tmp_path : Path ):
153+ (tmp_path / "config.py" ).touch ()
90154 profile = Profile ("test" , tmp_path )
155+ config_dir = profile .root / "config"
156+ config_dir .mkdir (parents = True )
91157 template = "# Profile: {profile_name}\n config.source('{source_config_py}')"
92-
93158 profiles .create_profile (profile )
94- profiles .create_config (profile , tmp_path / "config" , template )
95-
159+ profiles .create_config (profile , tmp_path , template )
96160 config_content = (profile .root / "config" / "config.py" ).read_text ()
97161 assert "# Profile: test" in config_content
98- assert f"config.source('{ tmp_path / 'config' / 'config .py'} ')" in config_content
162+ assert f"config.source('{ tmp_path / 'config.py' } ')" in config_content
99163
100164
101165def test_missing_qb_config (tmp_path : Path ):
0 commit comments