@@ -1542,7 +1542,8 @@ def __init__(self, method_name='runTest'):
1542
1542
def setUp (self ):
1543
1543
super (ImportPretendTest , self ).setUp ()
1544
1544
self .setup_beets ()
1545
- self ._create_import_dir (1 )
1545
+ self .__create_import_dir ()
1546
+ self .__create_empty_import_dir ()
1546
1547
self ._setup_import_session ()
1547
1548
config ['import' ]['pretend' ] = True
1548
1549
self .matcher = AutotagStub ().install ()
@@ -1552,45 +1553,61 @@ def tearDown(self):
1552
1553
self .teardown_beets ()
1553
1554
self .matcher .restore ()
1554
1555
1555
- def test_import_pretend (self ):
1556
+ def __create_import_dir (self ):
1557
+ self ._create_import_dir (1 )
1556
1558
resource_path = os .path .join (_common .RSRC , u'empty.mp3' )
1557
1559
single_path = os .path .join (self .import_dir , u'track_2.mp3' )
1558
-
1559
1560
shutil .copy (resource_path , single_path )
1560
- import_files = [
1561
+ self . import_paths = [
1561
1562
os .path .join (self .import_dir , u'the_album' ),
1562
1563
single_path
1563
1564
]
1564
- self ._setup_import_session (singletons = True )
1565
- self .importer .paths = import_files
1565
+ self .import_files = [
1566
+ displayable_path (
1567
+ os .path .join (self .import_paths [0 ], u'track_1.mp3' )),
1568
+ displayable_path (single_path )
1569
+ ]
1570
+
1571
+ def __create_empty_import_dir (self ):
1572
+ path = os .path .join (self .temp_dir , 'empty' )
1573
+ os .makedirs (path )
1574
+ self .empty_path = path
1575
+
1576
+ def __run (self , import_paths , singletons = True ):
1577
+ self ._setup_import_session (singletons = singletons )
1578
+ self .importer .paths = import_paths
1566
1579
1567
1580
with capture_log () as logs :
1568
1581
self .importer .run ()
1569
1582
1583
+ logs = [line for line in logs if not line .startswith ('Sending event:' )]
1584
+
1570
1585
self .assertEqual (len (self .lib .items ()), 0 )
1571
1586
self .assertEqual (len (self .lib .albums ()), 0 )
1572
1587
1573
- self .assertEqual (len (logs ), 3 )
1574
- self .assertEqual (logs [1 ], os .path .join (import_files [0 ],
1575
- u'track_1.mp3' ))
1576
- self .assertEqual (logs [2 ], import_files [1 ])
1588
+ return logs
1577
1589
1578
- def test_import_pretend_empty (self ):
1579
- path = os .path .join (self .temp_dir , 'empty' )
1580
- os .makedirs (path )
1590
+ def test_import_singletons_pretend (self ):
1591
+ logs = self .__run (self .import_paths )
1581
1592
1582
- self ._setup_import_session (singletons = True )
1583
- self .importer .paths = [path ]
1593
+ self .assertEqual (logs , [
1594
+ 'Singleton: %s' % self .import_files [0 ],
1595
+ 'Singleton: %s' % self .import_paths [1 ]])
1584
1596
1585
- with capture_log () as logs :
1586
- self .importer . run ( )
1597
+ def test_import_album_pretend ( self ) :
1598
+ logs = self .__run ( self . import_paths , singletons = False )
1587
1599
1588
- self .assertEqual (len (self .lib .items ()), 0 )
1589
- self .assertEqual (len (self .lib .albums ()), 0 )
1600
+ self .assertEqual (logs , [
1601
+ 'Album %s' % displayable_path (self .import_paths [0 ]),
1602
+ ' %s' % self .import_files [0 ],
1603
+ 'Album %s' % displayable_path (self .import_paths [1 ]),
1604
+ ' %s' % self .import_paths [1 ]])
1605
+
1606
+ def test_import_pretend_empty (self ):
1607
+ logs = self .__run ([self .empty_path ])
1590
1608
1591
- self .assertEqual (len (logs ), 2 )
1592
- self .assertEqual (logs [1 ], 'No files imported from {0}'
1593
- .format (displayable_path (path )))
1609
+ self .assertEqual (logs , ['No files imported from {0}'
1610
+ .format (displayable_path (self .empty_path ))])
1594
1611
1595
1612
1596
1613
def suite ():
0 commit comments