fix(tests): stop test_whispercpp_advanced_persistence clobbering the real config (#694)
TestTypedAccessors builds its ConfigManager with __new__ and, unlike TestConfigManager, never patches CONFIG_DIR/CONFIG_FILE. That is fine for the accessor tests, but test_whispercpp_advanced_persistence calls save_config(), which writes the synthetic fixture from setUp over the developer's real ~/.config/vocalinux/config.json — running the suite silently wiped every personal setting. Caught by making the real file read-only and running the suite with live logging; it is the only write to the real path in the entire suite. Redirect the paths to a temp directory for this test, the same way TestConfigManager's setUp already does. Co-authored-by: Jatin K Malik <jatinkrmalik@gmail.com>
This commit is contained in:
co-authored by
Jatin K Malik
parent
5a978d9875
commit
23ca16e317
@@ -604,13 +604,23 @@ class TestTypedAccessors(unittest.TestCase):
|
||||
self.assertEqual(advanced["whispercpp_n_threads"], 0)
|
||||
|
||||
def test_whispercpp_advanced_persistence(self):
|
||||
self.config_manager.set("advanced", "whispercpp_temperature", 0.5)
|
||||
self.config_manager.set("advanced", "whispercpp_no_timestamps", False)
|
||||
self.config_manager.set("advanced", "whispercpp_initial_prompt", "Meeting notes")
|
||||
self.config_manager.save_config()
|
||||
# This class skips ConfigManager.__init__, so unlike TestConfigManager
|
||||
# nothing has redirected CONFIG_FILE: without the patches below this
|
||||
# save_config() overwrites the developer's real ~/.config/vocalinux/
|
||||
# config.json with the synthetic fixture from setUp.
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
temp_file = os.path.join(temp_dir, "config.json")
|
||||
with (
|
||||
patch("vocalinux.ui.config_manager.CONFIG_DIR", temp_dir),
|
||||
patch("vocalinux.ui.config_manager.CONFIG_FILE", temp_file),
|
||||
):
|
||||
self.config_manager.set("advanced", "whispercpp_temperature", 0.5)
|
||||
self.config_manager.set("advanced", "whispercpp_no_timestamps", False)
|
||||
self.config_manager.set("advanced", "whispercpp_initial_prompt", "Meeting notes")
|
||||
self.config_manager.save_config()
|
||||
|
||||
new_manager = ConfigManager()
|
||||
advanced = new_manager.get_settings().get("advanced", {})
|
||||
self.assertEqual(advanced["whispercpp_temperature"], 0.5)
|
||||
self.assertFalse(advanced["whispercpp_no_timestamps"])
|
||||
self.assertEqual(advanced["whispercpp_initial_prompt"], "Meeting notes")
|
||||
new_manager = ConfigManager()
|
||||
advanced = new_manager.get_settings().get("advanced", {})
|
||||
self.assertEqual(advanced["whispercpp_temperature"], 0.5)
|
||||
self.assertFalse(advanced["whispercpp_no_timestamps"])
|
||||
self.assertEqual(advanced["whispercpp_initial_prompt"], "Meeting notes")
|
||||
|
||||
Reference in New Issue
Block a user