Exemplo n.º 1
0
 def test_local_only_gets_fs_image(self):
     _common.touch(os.path.join(self.dpath, b"art.jpg"))
     album = _common.Bag(mb_albumid=self.MBID, asin=self.ASIN)
     candidate = self.plugin.art_for_album(album, [self.dpath], local_only=True)
     self.assertIsNotNone(candidate)
     self.assertEqual(candidate.path, os.path.join(self.dpath, b"art.jpg"))
     self.assertEqual(len(responses.calls), 0)
Exemplo n.º 2
0
    def setUp(self):
        super(UpdateTest, self).setUp()

        self.io.install()

        self.libdir = os.path.join(self.temp_dir, b'testlibdir')

        # Copy a file into the library.
        self.lib = library.Library(':memory:', self.libdir)
        item_path = os.path.join(_common.RSRC, b'full.mp3')
        item_path_two = os.path.join(_common.RSRC, b'full.flac')
        self.i = library.Item.from_path(item_path)
        self.i2 = library.Item.from_path(item_path_two)
        self.lib.add(self.i)
        self.lib.add(self.i2)
        self.i.move(operation=MoveOperation.COPY)
        self.i2.move(operation=MoveOperation.COPY)
        self.album = self.lib.add_album([self.i, self.i2])

        # Album art.
        artfile = os.path.join(self.temp_dir, b'testart.jpg')
        _common.touch(artfile)
        self.album.set_art(artfile)
        self.album.store()
        os.remove(artfile)
Exemplo n.º 3
0
 def test_main_interface_gives_precedence_to_fs_art(self):
     _common.touch(os.path.join(self.dpath, b'art.jpg'))
     self.mock_response(self.AMAZON_URL)
     album = _common.Bag(asin=self.ASIN)
     candidate = self.plugin.art_for_album(album, [self.dpath])
     self.assertIsNotNone(candidate)
     self.assertEqual(candidate.path, os.path.join(self.dpath, b'art.jpg'))
Exemplo n.º 4
0
 def test_local_only_gets_fs_image(self):
     _common.touch(os.path.join(self.dpath, 'art.jpg'))
     album = _common.Bag(mb_albumid=self.MBID, asin=self.ASIN)
     artpath = self.plugin.art_for_album(album, [self.dpath],
                                         local_only=True)
     self.assertEqual(artpath, os.path.join(self.dpath, 'art.jpg'))
     self.assertEqual(len(responses.calls), 0)
Exemplo n.º 5
0
    def setUp(self):
        super(SafeMoveCopyTest, self).setUp()

        self.path = os.path.join(self.temp_dir, 'testfile')
        touch(self.path)
        self.otherpath = os.path.join(self.temp_dir, 'testfile2')
        touch(self.otherpath)
        self.dest = self.path + '.dest'
Exemplo n.º 6
0
 def test_precedence_amongst_correct_files(self):
     images = [b"front-cover.jpg", b"front.jpg", b"back.jpg"]
     paths = [os.path.join(self.dpath, i) for i in images]
     for p in paths:
         _common.touch(p)
     self.extra["cover_names"] = ["cover", "front", "back"]
     candidates = [candidate.path for candidate in self.source.get(None, self.extra)]
     self.assertEqual(candidates, paths)
Exemplo n.º 7
0
    def test_removing_last_item_in_album_with_albumart_prunes_dir(self):
        artfile = os.path.join(self.temp_dir, 'testart.jpg')
        touch(artfile)
        self.ai.set_art(artfile)
        self.ai.store()

        parent = os.path.dirname(self.i.path)
        self.i.remove(True)
        self.assertNotExists(parent)
Exemplo n.º 8
0
 def test_precedence_amongst_correct_files(self):
     images = [b'front-cover.jpg', b'front.jpg', b'back.jpg']
     paths = [os.path.join(self.dpath, i) for i in images]
     for p in paths:
         _common.touch(p)
     self.settings.cover_names = ['cover', 'front', 'back']
     candidates = [candidate.path for candidate in
                   self.source.get(None, self.settings, [self.dpath])]
     self.assertEqual(candidates, paths)
Exemplo n.º 9
0
    def test_move_avoids_collision_with_existing_file(self):
        # Make a conflicting file at the destination.
        dest = self.i.destination()
        os.makedirs(os.path.dirname(dest))
        touch(dest)

        self.i.move()
        self.assertNotEqual(self.i.path, dest)
        self.assertEqual(os.path.dirname(self.i.path),
                         os.path.dirname(dest))
Exemplo n.º 10
0
    def test_setart_copies_image(self):
        os.remove(self.art)

        newart = os.path.join(self.libdir, 'newart.jpg')
        touch(newart)
        i2 = item()
        i2.path = self.i.path
        i2.artist = u'someArtist'
        ai = self.lib.add_album((i2,))
        i2.move(True)

        self.assertEqual(ai.artpath, None)
        ai.set_art(newart)
        self.assertTrue(os.path.exists(ai.artpath))
Exemplo n.º 11
0
    def setUp(self):
        super(RemoveTest, self).setUp()

        # Make library and item.
        self.lib = beets.library.Library(':memory:')
        self.libdir = os.path.join(self.temp_dir, 'testlibdir')
        self.lib.directory = self.libdir
        self.i = item(self.lib)
        self.i.path = self.i.destination()
        # Make a music file.
        util.mkdirall(self.i.path)
        touch(self.i.path)
        # Make an album with the item.
        self.ai = self.lib.add_album((self.i,))
Exemplo n.º 12
0
    def test_setart_to_existing_art_works(self):
        os.remove(self.art)

        # Original art.
        newart = os.path.join(self.libdir, 'newart.jpg')
        touch(newart)
        i2 = item()
        i2.path = self.i.path
        i2.artist = u'someArtist'
        ai = self.lib.add_album((i2,))
        i2.move(True)
        ai.set_art(newart)

        # Set the art again.
        ai.set_art(ai.artpath)
        self.assertTrue(os.path.exists(ai.artpath))
Exemplo n.º 13
0
    def test_setart_to_existing_but_unset_art_works(self):
        newart = os.path.join(self.libdir, 'newart.jpg')
        touch(newart)
        i2 = item()
        i2.path = self.i.path
        i2.artist = u'someArtist'
        ai = self.lib.add_album((i2,))
        i2.move(True)

        # Copy the art to the destination.
        artdest = ai.art_destination(newart)
        shutil.copy(newart, artdest)

        # Set the art again.
        ai.set_art(artdest)
        self.assertTrue(os.path.exists(ai.artpath))
Exemplo n.º 14
0
    def setUp(self):
        super(UniquePathTest, self).setUp()

        self.base = os.path.join(self.temp_dir, 'testdir')
        os.mkdir(self.base)
        touch(os.path.join(self.base, 'x.mp3'))
        touch(os.path.join(self.base, 'x.1.mp3'))
        touch(os.path.join(self.base, 'x.2.mp3'))
        touch(os.path.join(self.base, 'y.mp3'))
Exemplo n.º 15
0
    def setUp(self):
        super(AlbumFileTest, self).setUp()

        # Make library and item.
        self.lib = beets.library.Library(':memory:')
        self.lib.path_formats = \
            [('default', join('$albumartist', '$album', '$title'))]
        self.libdir = os.path.join(self.temp_dir, 'testlibdir')
        self.lib.directory = self.libdir
        self.i = item(self.lib)
        # Make a file for the item.
        self.i.path = self.i.destination()
        util.mkdirall(self.i.path)
        touch(self.i.path)
        # Make an album.
        self.ai = self.lib.add_album((self.i,))
        # Alternate destination dir.
        self.otherdir = os.path.join(self.temp_dir, 'testotherdir')
Exemplo n.º 16
0
    def test_setart_to_conflicting_file_gets_new_path(self):
        newart = os.path.join(self.libdir, 'newart.jpg')
        touch(newart)
        i2 = item()
        i2.path = self.i.path
        i2.artist = u'someArtist'
        ai = self.lib.add_album((i2,))
        i2.move(True)

        # Make a file at the destination.
        artdest = ai.art_destination(newart)
        touch(artdest)

        # Set the art.
        ai.set_art(newart)
        self.assertNotEqual(artdest, ai.artpath)
        self.assertEqual(os.path.dirname(artdest),
                         os.path.dirname(ai.artpath))
Exemplo n.º 17
0
    def setUp(self):
        super(ArtImporterTest, self).setUp()

        # Mock the album art fetcher to always return our test file.
        self.art_file = os.path.join(self.temp_dir, 'tmpcover.jpg')
        _common.touch(self.art_file)
        self.old_afa = self.plugin.art_for_album
        self.afa_response = self.art_file

        def art_for_album(i, p, local_only=False):
            return self.afa_response

        self.plugin.art_for_album = art_for_album

        # Test library.
        self.libpath = os.path.join(self.temp_dir, 'tmplib.blb')
        self.libdir = os.path.join(self.temp_dir, 'tmplib')
        os.mkdir(self.libdir)
        os.mkdir(os.path.join(self.libdir, 'album'))
        itempath = os.path.join(self.libdir, 'album', 'test.mp3')
        shutil.copyfile(os.path.join(_common.RSRC, 'full.mp3'), itempath)
        self.lib = library.Library(self.libpath)
        self.i = _common.item()
        self.i.path = itempath
        self.album = self.lib.add_album([self.i])
        self.lib._connection().commit()

        # The import configuration.
        self.session = _common.import_session(self.lib)

        # Import task for the coroutine.
        self.task = importer.ImportTask(None, None, [self.i])
        self.task.is_album = True
        self.task.album = self.album
        info = AlbumInfo(
            album='some album',
            album_id='albumid',
            artist='some artist',
            artist_id='artistid',
            tracks=[],
        )
        self.task.set_choice(AlbumMatch(0, info, {}, set(), set()))
Exemplo n.º 18
0
    def setUp(self):
        super(UpdateTest, self).setUp()

        self.io.install()

        self.libdir = os.path.join(self.temp_dir, 'testlibdir')

        # Copy a file into the library.
        self.lib = library.Library(':memory:', self.libdir)
        self.i = library.Item.from_path(os.path.join(_common.RSRC, 'full.mp3'))
        self.lib.add(self.i)
        self.i.move(True)
        self.album = self.lib.add_album([self.i])

        # Album art.
        artfile = os.path.join(self.temp_dir, 'testart.jpg')
        _common.touch(artfile)
        self.album.set_art(artfile)
        self.album.store()
        os.remove(artfile)
Exemplo n.º 19
0
    def setUp(self):
        super(ArtFileTest, self).setUp()

        # Make library and item.
        self.lib = beets.library.Library(':memory:')
        self.libdir = os.path.join(self.temp_dir, 'testlibdir')
        self.lib.directory = self.libdir
        self.i = item(self.lib)
        self.i.path = self.i.destination()
        # Make a music file.
        util.mkdirall(self.i.path)
        touch(self.i.path)
        # Make an album.
        self.ai = self.lib.add_album((self.i,))
        # Make an art file too.
        self.art = self.lib.get_album(self.i).art_destination('something.jpg')
        touch(self.art)
        self.ai.artpath = self.art
        self.ai.store()
        # Alternate destination dir.
        self.otherdir = os.path.join(self.temp_dir, 'testotherdir')
Exemplo n.º 20
0
    def test_setart_sets_permissions(self):
        os.remove(self.art)

        newart = os.path.join(self.libdir, 'newart.jpg')
        touch(newart)
        os.chmod(newart, 0o400)  # read-only

        try:
            i2 = item()
            i2.path = self.i.path
            i2.artist = u'someArtist'
            ai = self.lib.add_album((i2,))
            i2.move(True)
            ai.set_art(newart)

            mode = stat.S_IMODE(os.stat(ai.artpath).st_mode)
            self.assertTrue(mode & stat.S_IRGRP)
            self.assertTrue(os.access(ai.artpath, os.W_OK))

        finally:
            # Make everything writable so it can be cleaned up.
            os.chmod(newart, 0o777)
            os.chmod(ai.artpath, 0o777)
Exemplo n.º 21
0
    def setUp(self):
        super(WalkTest, self).setUp()

        self.base = os.path.join(self.temp_dir, 'testdir')
        os.mkdir(self.base)
        touch(os.path.join(self.base, 'y'))
        touch(os.path.join(self.base, 'x'))
        os.mkdir(os.path.join(self.base, 'd'))
        touch(os.path.join(self.base, 'd', 'z'))
Exemplo n.º 22
0
 def test_non_image_file_not_identified(self):
     _common.touch(os.path.join(self.dpath, b'a.txt'))
     with self.assertRaises(StopIteration):
         next(self.source.get(None, self.settings, [self.dpath]))
Exemplo n.º 23
0
 def test_finds_jpg_in_directory(self):
     _common.touch(os.path.join(self.dpath, b'a.jpg'))
     candidate = next(self.source.get(None, self.settings, [self.dpath]))
     self.assertEqual(candidate.path, os.path.join(self.dpath, b'a.jpg'))
Exemplo n.º 24
0
 def test_appropriately_named_file_takes_precedence(self):
     _common.touch(os.path.join(self.dpath, b'a.jpg'))
     _common.touch(os.path.join(self.dpath, b'art.jpg'))
     candidate = next(self.source.get(None, self.settings, [self.dpath]))
     self.assertEqual(candidate.path, os.path.join(self.dpath, b'art.jpg'))
Exemplo n.º 25
0
 def test_main_interface_gives_precedence_to_fs_art(self):
     _common.touch(os.path.join(self.dpath, 'art.jpg'))
     self.mock_response(self.AMAZON_URL)
     album = _common.Bag(asin=self.ASIN)
     artpath = self.plugin.art_for_album(album, [self.dpath])
     self.assertEqual(artpath, os.path.join(self.dpath, 'art.jpg'))
Exemplo n.º 26
0
 def test_finds_jpg_in_directory(self):
     _common.touch(os.path.join(self.dpath, 'a.jpg'))
     fn = self.source.get(self.dpath, ('art', ), False)
     self.assertEqual(fn, os.path.join(self.dpath, 'a.jpg'))
Exemplo n.º 27
0
 def test_appropriately_named_file_takes_precedence(self):
     _common.touch(os.path.join(self.dpath, 'a.jpg'))
     _common.touch(os.path.join(self.dpath, 'art.jpg'))
     fn = self.source.get(self.dpath, ('art',), False)
     self.assertEqual(fn, os.path.join(self.dpath, 'art.jpg'))
Exemplo n.º 28
0
 def test_appropriately_named_file_takes_precedence(self):
     _common.touch(os.path.join(self.dpath, 'a.jpg'))
     _common.touch(os.path.join(self.dpath, 'art.jpg'))
     fn = self.source.get(self.dpath, ('art', ), False)
     self.assertEqual(fn, os.path.join(self.dpath, 'art.jpg'))
Exemplo n.º 29
0
    def setUp(self):
        super(SoftRemoveTest, self).setUp()

        self.path = os.path.join(self.temp_dir, b'testfile')
        touch(self.path)
Exemplo n.º 30
0
 def test_cautious_skips_fallback(self):
     _common.touch(os.path.join(self.dpath, b'a.jpg'))
     self.settings.cautious = True
     with self.assertRaises(StopIteration):
         next(self.source.get(None, self.settings, [self.dpath]))
Exemplo n.º 31
0
 def test_cautious_skips_fallback(self):
     _common.touch(os.path.join(self.dpath, b'a.jpg'))
     self.settings.cautious = True
     with self.assertRaises(StopIteration):
         next(self.source.get(None, self.settings, [self.dpath]))
Exemplo n.º 32
0
 def test_cautious_skips_fallback(self):
     _common.touch(os.path.join(self.dpath, 'a.jpg'))
     fn = self.source.get(self.dpath, ('art',), True)
     self.assertEqual(fn, None)
Exemplo n.º 33
0
 def test_appropriately_named_file_takes_precedence(self):
     _common.touch(os.path.join(self.dpath, b'a.jpg'))
     _common.touch(os.path.join(self.dpath, b'art.jpg'))
     candidate = next(self.source.get(None, self.settings, [self.dpath]))
     self.assertEqual(candidate.path, os.path.join(self.dpath, b'art.jpg'))
Exemplo n.º 34
0
 def test_cautious_skips_fallback(self):
     _common.touch(os.path.join(self.dpath, 'a.jpg'))
     fn = self.source.get(self.dpath, ('art', ), True)
     self.assertEqual(fn, None)
Exemplo n.º 35
0
 def test_removing_last_item_prunes_dir_with_blacklisted_file(self):
     parent = os.path.dirname(self.i.path)
     touch(os.path.join(parent, b'.DS_Store'))
     self.i.remove(True)
     self.assertNotExists(parent)
Exemplo n.º 36
0
 def test_non_image_file_not_identified(self):
     _common.touch(os.path.join(self.dpath, b'a.txt'))
     with self.assertRaises(StopIteration):
         next(self.source.get(None, self.settings, [self.dpath]))
Exemplo n.º 37
0
 def test_removing_last_item_preserves_nonempty_dir(self):
     parent = os.path.dirname(self.i.path)
     touch(os.path.join(parent, b'dummy.txt'))
     self.i.remove(True)
     self.assertExists(parent)
Exemplo n.º 38
0
 def test_finds_jpg_in_directory(self):
     _common.touch(os.path.join(self.dpath, 'a.jpg'))
     fn = self.source.get(self.dpath, ('art',), False)
     self.assertEqual(fn, os.path.join(self.dpath, 'a.jpg'))
Exemplo n.º 39
0
 def test_precedence_amongst_correct_files(self):
     _common.touch(os.path.join(self.dpath, 'back.jpg'))
     _common.touch(os.path.join(self.dpath, 'front.jpg'))
     _common.touch(os.path.join(self.dpath, 'front-cover.jpg'))
     fn = self.source.get(self.dpath, ('cover', 'front', 'back'), False)
     self.assertEqual(fn, os.path.join(self.dpath, 'front-cover.jpg'))
Exemplo n.º 40
0
 def test_non_image_file_not_identified(self):
     _common.touch(os.path.join(self.dpath, 'a.txt'))
     fn = self.source.get(self.dpath, ('art',), False)
     self.assertEqual(fn, None)
Exemplo n.º 41
0
 def test_non_image_file_not_identified(self):
     _common.touch(os.path.join(self.dpath, 'a.txt'))
     fn = self.source.get(self.dpath, ('art', ), False)
     self.assertEqual(fn, None)
Exemplo n.º 42
0
 def test_precedence_amongst_correct_files(self):
     _common.touch(os.path.join(self.dpath, 'back.jpg'))
     _common.touch(os.path.join(self.dpath, 'front.jpg'))
     _common.touch(os.path.join(self.dpath, 'front-cover.jpg'))
     fn = self.source.get(self.dpath, ('cover', 'front', 'back'), False)
     self.assertEqual(fn, os.path.join(self.dpath, 'front-cover.jpg'))
Exemplo n.º 43
0
 def test_finds_jpg_in_directory(self):
     _common.touch(os.path.join(self.dpath, b'a.jpg'))
     candidate = next(self.source.get(None, self.settings, [self.dpath]))
     self.assertEqual(candidate.path, os.path.join(self.dpath, b'a.jpg'))