mirror of
https://github.com/beetbox/beets.git
synced 2025-12-31 21:12:43 +01:00
fixed but with copying in library.add, tests
--HG-- extra : convert_revision : svn%3A41726ec3-264d-0410-9c23-a9f1637257cc/trunk%4078
This commit is contained in:
parent
d9553a2ff5
commit
e811b72763
3 changed files with 31 additions and 7 deletions
|
|
@ -311,10 +311,13 @@ class Item(object):
|
|||
self.remove()
|
||||
|
||||
@classmethod
|
||||
def from_path(cls, path):
|
||||
"""Creates a new item from the media file at the specified path."""
|
||||
def from_path(cls, path, library=None):
|
||||
"""Creates a new item from the media file at the specified path. Sets
|
||||
the item's library (but does not add the item) if library is
|
||||
specified."""
|
||||
i = cls({})
|
||||
i.read(path)
|
||||
i.library = library
|
||||
return i
|
||||
|
||||
|
||||
|
|
@ -562,10 +565,10 @@ class Library(object):
|
|||
|
||||
for f in _walk_files(path):
|
||||
try:
|
||||
i = Item.from_path(_normpath(f))
|
||||
i = Item.from_path(_normpath(f), self)
|
||||
if copy:
|
||||
i.move(copy=True)
|
||||
i.add(self)
|
||||
i.add()
|
||||
except FileTypeError:
|
||||
_log(f + ' of unknown type, skipping')
|
||||
|
||||
|
|
|
|||
|
|
@ -78,16 +78,23 @@ class StoreTest(unittest.TestCase):
|
|||
|
||||
class AddTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.lib = lib()
|
||||
self.lib = beets.library.Library(':memory:')
|
||||
self.i = item(self.lib)
|
||||
def tearDown(self):
|
||||
self.lib.conn.close()
|
||||
|
||||
def test_add_inserts_row(self):
|
||||
def test_item_add_inserts_row(self):
|
||||
self.i.add()
|
||||
new_grouping = self.lib.conn.execute('select grouping from items '
|
||||
'where composer="the composer"').fetchone()['grouping']
|
||||
self.assertEqual(new_grouping, self.i.grouping)
|
||||
|
||||
def test_library_add_inserts_row(self):
|
||||
self.lib.add(os.path.join('rsrc', 'full.mp3'))
|
||||
new_grouping = self.lib.conn.execute('select grouping from items '
|
||||
'where composer="the composer"').fetchone()['grouping']
|
||||
self.assertEqual(new_grouping, self.i.grouping)
|
||||
|
||||
|
||||
class RemoveTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
|
|
|
|||
|
|
@ -123,7 +123,21 @@ class WalkTest(unittest.TestCase):
|
|||
self.assertTrue(f in s)
|
||||
s.remove(f)
|
||||
self.assertTrue(not s)
|
||||
|
||||
|
||||
class AddTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.dir = os.path.join('rsrc', 'test_lib')
|
||||
self.lib = beets.library.Library(':memory:')
|
||||
self.lib.options['directory'] = self.dir
|
||||
self.lib.options['path_format'] = 'item'
|
||||
def tearDown(self):
|
||||
if os.path.exists(self.dir):
|
||||
shutil.rmtree(self.dir)
|
||||
|
||||
def test_library_add_copies(self):
|
||||
self.lib.add(os.path.join('rsrc', 'full.mp3'), copy=True)
|
||||
self.assertTrue(os.path.isfile(os.path.join(self.dir, 'item')))
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromName(__name__)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue