mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 16:42:42 +01:00
test_config_command: use TestHelper to manage temp dir
Due to some weird race conditions the temporary directories were not getting torn down for four of the tests. I failed to figure out why, and I found that using TestHelper to manage the temporary directory somehow fixes this.
This commit is contained in:
parent
0682d0d030
commit
12730aa8d9
1 changed files with 6 additions and 9 deletions
|
|
@ -1,32 +1,29 @@
|
||||||
import os
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
from shutil import rmtree
|
|
||||||
from tempfile import mkdtemp
|
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
from beets import config, ui
|
from beets import config, ui
|
||||||
from beets.library import Library
|
|
||||||
from beets.test.helper import TestHelper
|
from beets.test.helper import TestHelper
|
||||||
|
|
||||||
|
|
||||||
class ConfigCommandTest(unittest.TestCase, TestHelper):
|
class ConfigCommandTest(unittest.TestCase, TestHelper):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.lib = Library(":memory:")
|
self.setup_beets()
|
||||||
self.temp_dir = mkdtemp()
|
|
||||||
for k in ("VISUAL", "EDITOR"):
|
for k in ("VISUAL", "EDITOR"):
|
||||||
if k in os.environ:
|
if k in os.environ:
|
||||||
del os.environ[k]
|
del os.environ[k]
|
||||||
|
|
||||||
os.environ["BEETSDIR"] = self.temp_dir
|
temp_dir = self.temp_dir.decode()
|
||||||
self.config_path = os.path.join(self.temp_dir, "config.yaml")
|
|
||||||
|
self.config_path = os.path.join(temp_dir, "config.yaml")
|
||||||
with open(self.config_path, "w") as file:
|
with open(self.config_path, "w") as file:
|
||||||
file.write("library: lib\n")
|
file.write("library: lib\n")
|
||||||
file.write("option: value\n")
|
file.write("option: value\n")
|
||||||
file.write("password: password_value")
|
file.write("password: password_value")
|
||||||
|
|
||||||
self.cli_config_path = os.path.join(self.temp_dir, "cli_config.yaml")
|
self.cli_config_path = os.path.join(temp_dir, "cli_config.yaml")
|
||||||
with open(self.cli_config_path, "w") as file:
|
with open(self.cli_config_path, "w") as file:
|
||||||
file.write("option: cli overwrite")
|
file.write("option: cli overwrite")
|
||||||
|
|
||||||
|
|
@ -35,7 +32,7 @@ class ConfigCommandTest(unittest.TestCase, TestHelper):
|
||||||
config._materialized = False
|
config._materialized = False
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
rmtree(self.temp_dir)
|
self.teardown_beets()
|
||||||
|
|
||||||
def _run_with_yaml_output(self, *args):
|
def _run_with_yaml_output(self, *args):
|
||||||
output = self.run_with_output(*args)
|
output = self.run_with_output(*args)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue