2727from beets import config , plugins , ui
2828from beets .test import _common
2929from beets .test .helper import BeetsTestCase , IOMixin , PluginTestCase
30- from beets .ui import commands
30+ from beets .ui import _open_library , commands
3131from beets .util import syspath
3232
3333
@@ -126,6 +126,12 @@ def setUp(self):
126126
127127 self ._reset_config ()
128128
129+ def run_command (self , * args , ** kwargs ):
130+ # We need to reload the lib based on the
131+ # current config
132+ self .lib = _open_library (self .config )
133+ super ().run_command (* args , ** kwargs )
134+
129135 def tearDown (self ):
130136 self .env_patcher .stop ()
131137 commands .default_commands .pop ()
@@ -155,7 +161,7 @@ def test_paths_section_respected(self):
155161 with self .write_config_file () as config :
156162 config .write ("paths: {x: y}" )
157163
158- self .run_command ("test" , lib = None )
164+ self .run_command ("test" )
159165 key , template = self .test_cmd .lib .path_formats [0 ]
160166 assert key == "x"
161167 assert template .original == "y"
@@ -166,7 +172,7 @@ def test_default_paths_preserved(self):
166172 self ._reset_config ()
167173 with self .write_config_file () as config :
168174 config .write ("paths: {x: y}" )
169- self .run_command ("test" , lib = None )
175+ self .run_command ("test" )
170176 key , template = self .test_cmd .lib .path_formats [0 ]
171177 assert key == "x"
172178 assert template .original == "y"
@@ -178,36 +184,36 @@ def test_nonexistant_db(self):
178184
179185 self .io .addinput ("n" )
180186 with pytest .raises (ui .UserError ):
181- self .run_command ("test" , lib = None )
187+ self .run_command ("test" )
182188
183189 def test_user_config_file (self ):
184190 with self .write_config_file () as file :
185191 file .write ("anoption: value" )
186192
187- self .run_command ("test" , lib = None )
193+ self .run_command ("test" )
188194 assert config ["anoption" ].get () == "value"
189195
190196 def test_replacements_parsed (self ):
191197 with self .write_config_file () as config :
192198 config .write ("replace: {'[xy]': z}" )
193199
194- self .run_command ("test" , lib = None )
200+ self .run_command ("test" )
195201 replacements = self .test_cmd .lib .replacements
196202 repls = [(p .pattern , s ) for p , s in replacements ] # Compare patterns.
197203 assert repls == [("[xy]" , "z" )]
198204
199205 def test_multiple_replacements_parsed (self ):
200206 with self .write_config_file () as config :
201207 config .write ("replace: {'[xy]': z, foo: bar}" )
202- self .run_command ("test" , lib = None )
208+ self .run_command ("test" )
203209 replacements = self .test_cmd .lib .replacements
204210 repls = [(p .pattern , s ) for p , s in replacements ]
205211 assert repls == [("[xy]" , "z" ), ("foo" , "bar" )]
206212
207213 def test_cli_config_option (self ):
208214 with open (self .cli_config_path , "w" ) as file :
209215 file .write ("anoption: value" )
210- self .run_command ("--config" , self .cli_config_path , "test" , lib = None )
216+ self .run_command ("--config" , self .cli_config_path , "test" )
211217 assert config ["anoption" ].get () == "value"
212218
213219 def test_cli_config_file_overwrites_user_defaults (self ):
@@ -216,7 +222,7 @@ def test_cli_config_file_overwrites_user_defaults(self):
216222
217223 with open (self .cli_config_path , "w" ) as file :
218224 file .write ("anoption: cli overwrite" )
219- self .run_command ("--config" , self .cli_config_path , "test" , lib = None )
225+ self .run_command ("--config" , self .cli_config_path , "test" )
220226 assert config ["anoption" ].get () == "cli overwrite"
221227
222228 def test_cli_config_file_overwrites_beetsdir_defaults (self ):
@@ -226,7 +232,7 @@ def test_cli_config_file_overwrites_beetsdir_defaults(self):
226232
227233 with open (self .cli_config_path , "w" ) as file :
228234 file .write ("anoption: cli overwrite" )
229- self .run_command ("--config" , self .cli_config_path , "test" , lib = None )
235+ self .run_command ("--config" , self .cli_config_path , "test" )
230236 assert config ["anoption" ].get () == "cli overwrite"
231237
232238 # @unittest.skip('Difficult to implement with optparse')
@@ -241,7 +247,7 @@ def test_cli_config_file_overwrites_beetsdir_defaults(self):
241247 # file.write('second: value')
242248 #
243249 # self.run_command('--config', cli_config_path_1,
244- # '--config', cli_config_path_2, 'test', lib=None )
250+ # '--config', cli_config_path_2, 'test')
245251 # assert config['first'].get() == 'value'
246252 # assert config['second'].get() == 'value'
247253 #
@@ -267,7 +273,7 @@ def test_cli_config_paths_resolve_relative_to_user_dir(self):
267273 file .write ("library: beets.db\n " )
268274 file .write ("statefile: state" )
269275
270- self .run_command ("--config" , self .cli_config_path , "test" , lib = None )
276+ self .run_command ("--config" , self .cli_config_path , "test" )
271277 assert config ["library" ].as_path () == self .user_config_dir / "beets.db"
272278 assert config ["statefile" ].as_path () == self .user_config_dir / "state"
273279
@@ -278,22 +284,22 @@ def test_cli_config_paths_resolve_relative_to_beetsdir(self):
278284 file .write ("library: beets.db\n " )
279285 file .write ("statefile: state" )
280286
281- self .run_command ("--config" , self .cli_config_path , "test" , lib = None )
287+ self .run_command ("--config" , self .cli_config_path , "test" )
282288 assert config ["library" ].as_path () == self .beetsdir / "beets.db"
283289 assert config ["statefile" ].as_path () == self .beetsdir / "state"
284290
285291 def test_command_line_option_relative_to_working_dir (self ):
286292 config .read ()
287293 os .chdir (syspath (self .temp_dir ))
288- self .run_command ("--library" , "foo.db" , "test" , lib = None )
294+ self .run_command ("--library" , "foo.db" , "test" )
289295 assert config ["library" ].as_path () == Path .cwd () / "foo.db"
290296
291297 def test_cli_config_file_loads_plugin_commands (self ):
292298 with open (self .cli_config_path , "w" ) as file :
293299 file .write (f"pluginpath: { _common .PLUGINPATH } \n " )
294300 file .write ("plugins: test" )
295301
296- self .run_command ("--config" , self .cli_config_path , "plugin" , lib = None )
302+ self .run_command ("--config" , self .cli_config_path , "plugin" )
297303 plugs = plugins .find_plugins ()
298304 assert len (plugs ) == 1
299305 assert plugs [0 ].is_test_plugin
@@ -358,7 +364,7 @@ def test_custom_paths_prepend(self):
358364@_common .slow_test ()
359365class PluginTest (TestPluginTestCase ):
360366 def test_plugin_command_from_pluginpath (self ):
361- self .run_command ("test" , lib = None )
367+ self .run_command ("test" )
362368
363369
364370class CommonOptionsParserCliTest (IOMixin , BeetsTestCase ):
0 commit comments