From 29bb2d52b62c8a4d54978c392130f84f77357766 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Tue, 31 Dec 2013 15:31:09 +0100 Subject: [PATCH] local: Re-add test for #500 fix. --- mopidy/backends/local/json.py | 1 + tests/backends/local/library_test.py | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/mopidy/backends/local/json.py b/mopidy/backends/local/json.py index d1cacd6d70..e4779ffe2e 100644 --- a/mopidy/backends/local/json.py +++ b/mopidy/backends/local/json.py @@ -52,6 +52,7 @@ def __init__(self, config): config['local']['data_dir'], b'library.json.gz') def load(self): + logger.debug('Loading json library from %s', self._json_file) library = load_library(self._json_file) self._tracks = dict((t.uri, t) for t in library.get('tracks', [])) return len(self._tracks) diff --git a/tests/backends/local/library_test.py b/tests/backends/local/library_test.py index 40bece7d49..4ca5abf057 100644 --- a/tests/backends/local/library_test.py +++ b/tests/backends/local/library_test.py @@ -1,6 +1,7 @@ from __future__ import unicode_literals -import copy +import os +import shutil import tempfile import unittest @@ -89,31 +90,30 @@ def test_refresh_missing_uri(self): # Verifies that https://github.com/mopidy/mopidy/issues/500 # has been fixed. - # TODO: re-add something that tests this in a more sane way - return + tmpdir = tempfile.mkdtemp() + try: + tmplib = os.path.join(tmpdir, 'library.json.gz') + shutil.copy(path_to_data_dir('library.json.gz'), tmplib) - with tempfile.NamedTemporaryFile() as library: - with open(self.config['local-json']['json_file']) as fh: - library.write(fh.read()) - library.flush() - - config = copy.deepcopy(self.config) - config['local-json']['json_file'] = library.name + config = {'local': self.config['local'].copy()} + config['local']['data_dir'] = tmpdir backend = actor.LocalBackend(config=config, audio=None) # Sanity check that value is in the library result = backend.library.lookup(self.tracks[0].uri) self.assertEqual(result, self.tracks[0:1]) - # Clear library and refresh - library.seek(0) - library.truncate() + # Clear and refresh. + open(tmplib, 'w').close() backend.library.refresh() # Now it should be gone. result = backend.library.lookup(self.tracks[0].uri) self.assertEqual(result, []) + finally: + shutil.rmtree(tmpdir) + def test_lookup(self): tracks = self.library.lookup(self.tracks[0].uri) self.assertEqual(tracks, self.tracks[0:1])