mirror of
https://github.com/beetbox/beets.git
synced 2025-12-29 20:12:33 +01:00
use util.py3_path for confit and env paths in tests
This commit is contained in:
parent
dd729f0ce8
commit
aa0a0a0f22
5 changed files with 28 additions and 22 deletions
|
|
@ -162,15 +162,18 @@ class TestCase(unittest.TestCase, Assertions):
|
|||
# Direct paths to a temporary directory. Tests can also use this
|
||||
# temporary directory.
|
||||
self.temp_dir = util.bytestring_path(tempfile.mkdtemp())
|
||||
beets.config['statefile'] = os.path.join(self.temp_dir,
|
||||
b'state.pickle')
|
||||
beets.config['library'] = os.path.join(self.temp_dir, b'library.db')
|
||||
beets.config['directory'] = os.path.join(self.temp_dir, b'libdir')
|
||||
|
||||
beets.config['statefile'] = \
|
||||
util.py3_path(os.path.join(self.temp_dir, b'state.pickle'))
|
||||
beets.config['library'] = \
|
||||
util.py3_path(os.path.join(self.temp_dir, b'library.db'))
|
||||
beets.config['directory'] = \
|
||||
util.py3_path(os.path.join(self.temp_dir, b'libdir'))
|
||||
|
||||
# Set $HOME, which is used by confit's `config_dir()` to create
|
||||
# directories.
|
||||
self._old_home = os.environ.get('HOME')
|
||||
os.environ['HOME'] = self.temp_dir
|
||||
os.environ['HOME'] = util.py3_path(self.temp_dir)
|
||||
|
||||
# Initialize, but don't install, a DummyIO.
|
||||
self.io = DummyIO()
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ class TestHelper(object):
|
|||
Make sure you call ``teardown_beets()`` afterwards.
|
||||
"""
|
||||
self.create_temp_dir()
|
||||
os.environ['BEETSDIR'] = self.temp_dir
|
||||
os.environ['BEETSDIR'] = util.py3_path(self.temp_dir)
|
||||
|
||||
self.config = beets.config
|
||||
self.config.clear()
|
||||
|
|
@ -182,10 +182,12 @@ class TestHelper(object):
|
|||
|
||||
self.libdir = os.path.join(self.temp_dir, b'libdir')
|
||||
os.mkdir(self.libdir)
|
||||
self.config['directory'] = self.libdir
|
||||
self.config['directory'] = util.py3_path(self.libdir)
|
||||
|
||||
if disk:
|
||||
dbpath = util.bytestring_path(self.config['library'].as_filename())
|
||||
dbpath = util.bytestring_path(
|
||||
self.config['library'].as_filename()
|
||||
)
|
||||
else:
|
||||
dbpath = ':memory:'
|
||||
self.lib = Library(dbpath, self.libdir)
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import platform
|
|||
import time
|
||||
from datetime import datetime
|
||||
from beets.library import Item
|
||||
from beets.util import py3_path
|
||||
|
||||
from test import _common
|
||||
from test._common import unittest
|
||||
|
|
@ -48,10 +49,10 @@ class MetaSyncTest(_common.TestCase, TestHelper):
|
|||
|
||||
if _is_windows():
|
||||
self.config['metasync']['itunes']['library'] = \
|
||||
self.itunes_library_windows
|
||||
py3_path(self.itunes_library_windows)
|
||||
else:
|
||||
self.config['metasync']['itunes']['library'] = \
|
||||
self.itunes_library_unix
|
||||
py3_path(self.itunes_library_unix)
|
||||
|
||||
self._set_up_data()
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ from beetsplug.smartplaylist import SmartPlaylistPlugin
|
|||
from beets.library import Item, Album, parse_query_string
|
||||
from beets.dbcore import OrQuery
|
||||
from beets.dbcore.query import NullSort, MultipleSort, FixedFieldSort
|
||||
from beets.util import syspath, bytestring_path
|
||||
from beets.util import syspath, bytestring_path, py3_path
|
||||
from beets.ui import UserError
|
||||
from beets import config
|
||||
|
||||
|
|
@ -161,7 +161,7 @@ class SmartPlaylistTest(unittest.TestCase):
|
|||
|
||||
dir = bytestring_path(mkdtemp())
|
||||
config['smartplaylist']['relative_to'] = False
|
||||
config['smartplaylist']['playlist_dir'] = dir
|
||||
config['smartplaylist']['playlist_dir'] = py3_path(dir)
|
||||
try:
|
||||
spl.update_playlists(lib)
|
||||
except Exception:
|
||||
|
|
@ -191,7 +191,7 @@ class SmartPlaylistCLITest(unittest.TestCase, TestHelper):
|
|||
{'name': 'all.m3u',
|
||||
'query': u''}
|
||||
])
|
||||
config['smartplaylist']['playlist_dir'].set(self.temp_dir)
|
||||
config['smartplaylist']['playlist_dir'].set(py3_path(self.temp_dir))
|
||||
self.load_plugins('smartplaylist')
|
||||
|
||||
def tearDown(self):
|
||||
|
|
|
|||
|
|
@ -657,7 +657,7 @@ class ConfigTest(unittest.TestCase, TestHelper, _common.Assertions):
|
|||
# directory there. Some tests will set `BEETSDIR` themselves.
|
||||
del os.environ['BEETSDIR']
|
||||
self._old_home = os.environ.get('HOME')
|
||||
os.environ['HOME'] = self.temp_dir
|
||||
os.environ['HOME'] = util.py3_path(self.temp_dir)
|
||||
|
||||
# Also set APPDATA, the Windows equivalent of setting $HOME.
|
||||
self._old_appdata = os.environ.get('APPDATA')
|
||||
|
|
@ -793,8 +793,8 @@ class ConfigTest(unittest.TestCase, TestHelper, _common.Assertions):
|
|||
self.assertEqual(config['anoption'].get(), 'cli overwrite')
|
||||
|
||||
def test_cli_config_file_overwrites_beetsdir_defaults(self):
|
||||
os.environ['BEETSDIR'] = self.beetsdir
|
||||
env_config_path = os.path.join(self.beetsdir, 'config.yaml')
|
||||
os.environ['BEETSDIR'] = util.py3_path(self.beetsdir)
|
||||
env_config_path = os.path.join(self.beetsdir, b'config.yaml')
|
||||
with open(env_config_path, 'w') as file:
|
||||
file.write('anoption: value')
|
||||
|
||||
|
|
@ -854,7 +854,7 @@ class ConfigTest(unittest.TestCase, TestHelper, _common.Assertions):
|
|||
)
|
||||
|
||||
def test_cli_config_paths_resolve_relative_to_beetsdir(self):
|
||||
os.environ['BEETSDIR'] = self.beetsdir
|
||||
os.environ['BEETSDIR'] = util.py3_path(self.beetsdir)
|
||||
|
||||
cli_config_path = os.path.join(self.temp_dir, 'config.yaml')
|
||||
with open(cli_config_path, 'w') as file:
|
||||
|
|
@ -883,7 +883,7 @@ class ConfigTest(unittest.TestCase, TestHelper, _common.Assertions):
|
|||
self.assertTrue(plugins.find_plugins()[0].is_test_plugin)
|
||||
|
||||
def test_beetsdir_config(self):
|
||||
os.environ['BEETSDIR'] = self.beetsdir
|
||||
os.environ['BEETSDIR'] = util.py3_path(self.beetsdir)
|
||||
|
||||
env_config_path = os.path.join(self.beetsdir, b'config.yaml')
|
||||
with open(env_config_path, 'w') as file:
|
||||
|
|
@ -895,11 +895,11 @@ class ConfigTest(unittest.TestCase, TestHelper, _common.Assertions):
|
|||
def test_beetsdir_points_to_file_error(self):
|
||||
beetsdir = os.path.join(self.temp_dir, b'beetsfile')
|
||||
open(beetsdir, 'a').close()
|
||||
os.environ['BEETSDIR'] = beetsdir
|
||||
os.environ['BEETSDIR'] = util.py3_path(beetsdir)
|
||||
self.assertRaises(ConfigError, ui._raw_main, ['test'])
|
||||
|
||||
def test_beetsdir_config_does_not_load_default_user_config(self):
|
||||
os.environ['BEETSDIR'] = self.beetsdir
|
||||
os.environ['BEETSDIR'] = util.py3_path(self.beetsdir)
|
||||
|
||||
with open(self.user_config_path, 'w') as file:
|
||||
file.write('anoption: value')
|
||||
|
|
@ -908,7 +908,7 @@ class ConfigTest(unittest.TestCase, TestHelper, _common.Assertions):
|
|||
self.assertFalse(config['anoption'].exists())
|
||||
|
||||
def test_default_config_paths_resolve_relative_to_beetsdir(self):
|
||||
os.environ['BEETSDIR'] = self.beetsdir
|
||||
os.environ['BEETSDIR'] = util.py3_path(self.beetsdir)
|
||||
|
||||
config.read()
|
||||
self.assert_equal_path(config['library'].as_filename(),
|
||||
|
|
@ -917,7 +917,7 @@ class ConfigTest(unittest.TestCase, TestHelper, _common.Assertions):
|
|||
os.path.join(self.beetsdir, b'state.pickle'))
|
||||
|
||||
def test_beetsdir_config_paths_resolve_relative_to_beetsdir(self):
|
||||
os.environ['BEETSDIR'] = self.beetsdir
|
||||
os.environ['BEETSDIR'] = util.py3_path(self.beetsdir)
|
||||
|
||||
env_config_path = os.path.join(self.beetsdir, b'config.yaml')
|
||||
with open(env_config_path, 'w') as file:
|
||||
|
|
|
|||
Loading…
Reference in a new issue