@@ -863,60 +863,41 @@ def test_fetch_art_if_imported_file_deleted(self):
863
863
assert self .album .art_filepath .exists ()
864
864
865
865
866
+ IMAGE_PATH = os .path .join (_common .RSRC , b"abbey-similar.jpg" )
867
+ IMAGE_SIZE = os .stat (util .syspath (IMAGE_PATH )).st_size
868
+
869
+
870
+ def fs_source_get (_self , album , settings , paths ):
871
+ if paths :
872
+ yield fetchart .Candidate (logger , source_name = _self .ID , path = IMAGE_PATH )
873
+
874
+
875
+ @patch ("beetsplug.fetchart.FileSystem.get" , fs_source_get )
866
876
class ArtForAlbumTest (UseThePlugin ):
867
877
"""Tests that fetchart.art_for_album respects the scale & filesize
868
878
configurations (e.g., minwidth, enforce_ratio, max_filesize)
869
879
"""
870
880
871
881
IMG_225x225 = os .path .join (_common .RSRC , b"abbey.jpg" )
872
882
IMG_348x348 = os .path .join (_common .RSRC , b"abbey-different.jpg" )
873
- IMG_500x490 = os .path .join (_common .RSRC , b"abbey-similar.jpg" )
874
883
875
884
IMG_225x225_SIZE = os .stat (util .syspath (IMG_225x225 )).st_size
876
- IMG_348x348_SIZE = os .stat (util .syspath (IMG_348x348 )).st_size
877
885
878
886
RESIZE_OP = "resize"
879
887
DEINTERLACE_OP = "deinterlace"
880
888
REFORMAT_OP = "reformat"
881
889
882
- def setUp (self ):
883
- super ().setUp ()
890
+ album = _common .Bag ()
884
891
885
- self .old_fs_source_get = fetchart .FileSystem .get
886
-
887
- def fs_source_get (_self , album , settings , paths ):
888
- if paths :
889
- yield fetchart .Candidate (
890
- logger , source_name = _self .ID , path = self .image_file
891
- )
892
-
893
- fetchart .FileSystem .get = fs_source_get
894
-
895
- self .album = _common .Bag ()
896
-
897
- def tearDown (self ):
898
- fetchart .FileSystem .get = self .old_fs_source_get
899
- super ().tearDown ()
900
-
901
- def assertImageIsValidArt (self , image_file , should_exist ):
902
- assert Path (os .fsdecode (image_file )).exists ()
903
- self .image_file = image_file
904
-
905
- candidate = self .plugin .art_for_album (self .album , ["" ], True )
906
-
907
- if should_exist :
908
- assert candidate is not None
909
- assert candidate .path == self .image_file
910
- assert Path (os .fsdecode (candidate .path )).exists ()
911
- else :
912
- assert candidate is None
892
+ def get_album_art (self ):
893
+ return self .plugin .art_for_album (self .album , ["" ], True )
913
894
914
895
def _assert_image_operated (self , image_file , operation , should_operate ):
915
896
self .image_file = image_file
916
897
with patch .object (
917
898
ArtResizer .shared , operation , return_value = self .image_file
918
899
) as mock_operation :
919
- self .plugin . art_for_album ( self . album , [ "" ], True )
900
+ self .get_album_art ( )
920
901
assert mock_operation .called == should_operate
921
902
922
903
def _require_backend (self ):
@@ -929,48 +910,51 @@ def _require_backend(self):
929
910
def test_respect_minwidth (self ):
930
911
self ._require_backend ()
931
912
self .plugin .minwidth = 300
932
- self .assertImageIsValidArt (self .IMG_225x225 , False )
933
- self .assertImageIsValidArt (self .IMG_348x348 , True )
913
+ assert self .get_album_art ()
914
+
915
+ def test_respect_minwidth_no (self ):
916
+ self ._require_backend ()
917
+ self .plugin .minwidth = 600
918
+ assert not self .get_album_art ()
934
919
935
920
def test_respect_enforce_ratio_yes (self ):
936
921
self ._require_backend ()
937
922
self .plugin .enforce_ratio = True
938
- self .assertImageIsValidArt (self .IMG_500x490 , False )
939
- self .assertImageIsValidArt (self .IMG_225x225 , True )
923
+ assert not self .get_album_art ()
940
924
941
925
def test_respect_enforce_ratio_no (self ):
942
926
self .plugin .enforce_ratio = False
943
- self .assertImageIsValidArt ( self . IMG_500x490 , True )
927
+ assert self .get_album_art ( )
944
928
945
929
def test_respect_enforce_ratio_px_above (self ):
946
930
self ._require_backend ()
947
931
self .plugin .enforce_ratio = True
948
932
self .plugin .margin_px = 5
949
- self .assertImageIsValidArt ( self . IMG_500x490 , False )
933
+ assert not self .get_album_art ( )
950
934
951
935
def test_respect_enforce_ratio_px_below (self ):
952
936
self ._require_backend ()
953
937
self .plugin .enforce_ratio = True
954
938
self .plugin .margin_px = 15
955
- self .assertImageIsValidArt ( self . IMG_500x490 , True )
939
+ assert self .get_album_art ( )
956
940
957
941
def test_respect_enforce_ratio_percent_above (self ):
958
942
self ._require_backend ()
959
943
self .plugin .enforce_ratio = True
960
944
self .plugin .margin_percent = (500 - 490 ) / 500 * 0.5
961
- self .assertImageIsValidArt ( self . IMG_500x490 , False )
945
+ assert not self .get_album_art ( )
962
946
963
947
def test_respect_enforce_ratio_percent_below (self ):
964
948
self ._require_backend ()
965
949
self .plugin .enforce_ratio = True
966
950
self .plugin .margin_percent = (500 - 490 ) / 500 * 1.5
967
- self .assertImageIsValidArt ( self . IMG_500x490 , True )
951
+ assert self .get_album_art ( )
968
952
969
953
def test_resize_if_necessary (self ):
970
954
self ._require_backend ()
971
955
self .plugin .maxwidth = 300
972
- self . _assert_image_operated ( self . IMG_225x225 , self .RESIZE_OP , False )
973
- self ._assert_image_operated (self . IMG_348x348 , self .RESIZE_OP , True )
956
+ assert self .get_album_art ( )
957
+ self ._assert_image_operated (IMAGE_PATH , self .RESIZE_OP , True )
974
958
975
959
def test_fileresize (self ):
976
960
self ._require_backend ()
@@ -979,9 +963,9 @@ def test_fileresize(self):
979
963
980
964
def test_fileresize_if_necessary (self ):
981
965
self ._require_backend ()
982
- self .plugin .max_filesize = self . IMG_225x225_SIZE
983
- self ._assert_image_operated (self . IMG_225x225 , self .RESIZE_OP , False )
984
- self .assertImageIsValidArt ( self . IMG_225x225 , True )
966
+ self .plugin .max_filesize = IMAGE_SIZE
967
+ self ._assert_image_operated (IMAGE_PATH , self .RESIZE_OP , False )
968
+ assert self .get_album_art ( )
985
969
986
970
def test_fileresize_no_scale (self ):
987
971
self ._require_backend ()
0 commit comments