Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable skipped tests #5363

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
13 changes: 11 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,17 @@ jobs:
if: matrix.platform == 'ubuntu-latest'
run: |
sudo apt update
sudo apt install ffmpeg gobject-introspection libgirepository1.0-dev
poetry install --extras replaygain
sudo apt install \
bash-completion \
ffmpeg \
gobject-introspection \
gstreamer1.0-plugins-good \
libgirepository1.0-dev \
mp3gain
poetry install \
--extras embedart \
--extras lyrics \
--extras replaygain

- name: Install Python dependencies
run: poetry install --only=main,test
Expand Down
19 changes: 0 additions & 19 deletions beets/test/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
- The `control_stdin` and `capture_stdout` context managers allow one to
interact with the user interface.

- `has_program` checks the presence of a command on the system.

- The `generate_album_info` and `generate_track_info` functions return
fixtures to be used when mocking the autotagger.

Expand All @@ -34,7 +32,6 @@
import os
import os.path
import shutil
import subprocess
import sys
from contextlib import contextmanager
from enum import Enum
Expand Down Expand Up @@ -126,22 +123,6 @@ def _convert_args(args):
return args


def has_program(cmd, args=["--version"]):
"""Returns `True` if `cmd` can be executed."""
full_cmd = _convert_args([cmd] + args)
try:
with open(os.devnull, "wb") as devnull:
subprocess.check_call(
full_cmd, stderr=devnull, stdout=devnull, stdin=devnull
)
except OSError:
return False
except subprocess.CalledProcessError:
return False
else:
return True


class TestHelper:
"""Helper mixin for high-level cli and plugin tests.

Expand Down
20 changes: 0 additions & 20 deletions test/plugins/test_art.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,21 +884,12 @@ def _assert_image_operated(self, image_file, operation, should_operate):
self.plugin.art_for_album(self.album, [""], True)
self.assertEqual(mock_operation.called, should_operate)

def _require_backend(self):
"""Skip the test if the art resizer doesn't have ImageMagick or
PIL (so comparisons and measurements are unavailable).
"""
if not ArtResizer.shared.local:
self.skipTest("ArtResizer has no local imaging backend available")

def test_respect_minwidth(self):
self._require_backend()
self.plugin.minwidth = 300
self._assertImageIsValidArt(self.IMG_225x225, False)
self._assertImageIsValidArt(self.IMG_348x348, True)

def test_respect_enforce_ratio_yes(self):
self._require_backend()
self.plugin.enforce_ratio = True
self._assertImageIsValidArt(self.IMG_500x490, False)
self._assertImageIsValidArt(self.IMG_225x225, True)
Expand All @@ -908,60 +899,50 @@ def test_respect_enforce_ratio_no(self):
self._assertImageIsValidArt(self.IMG_500x490, True)

def test_respect_enforce_ratio_px_above(self):
self._require_backend()
self.plugin.enforce_ratio = True
self.plugin.margin_px = 5
self._assertImageIsValidArt(self.IMG_500x490, False)

def test_respect_enforce_ratio_px_below(self):
self._require_backend()
self.plugin.enforce_ratio = True
self.plugin.margin_px = 15
self._assertImageIsValidArt(self.IMG_500x490, True)

def test_respect_enforce_ratio_percent_above(self):
self._require_backend()
self.plugin.enforce_ratio = True
self.plugin.margin_percent = (500 - 490) / 500 * 0.5
self._assertImageIsValidArt(self.IMG_500x490, False)

def test_respect_enforce_ratio_percent_below(self):
self._require_backend()
self.plugin.enforce_ratio = True
self.plugin.margin_percent = (500 - 490) / 500 * 1.5
self._assertImageIsValidArt(self.IMG_500x490, True)

def test_resize_if_necessary(self):
self._require_backend()
self.plugin.maxwidth = 300
self._assert_image_operated(self.IMG_225x225, self.RESIZE_OP, False)
self._assert_image_operated(self.IMG_348x348, self.RESIZE_OP, True)

def test_fileresize(self):
self._require_backend()
self.plugin.max_filesize = self.IMG_225x225_SIZE // 2
self._assert_image_operated(self.IMG_225x225, self.RESIZE_OP, True)

def test_fileresize_if_necessary(self):
self._require_backend()
self.plugin.max_filesize = self.IMG_225x225_SIZE
self._assert_image_operated(self.IMG_225x225, self.RESIZE_OP, False)
self._assertImageIsValidArt(self.IMG_225x225, True)

def test_fileresize_no_scale(self):
self._require_backend()
self.plugin.maxwidth = 300
self.plugin.max_filesize = self.IMG_225x225_SIZE // 2
self._assert_image_operated(self.IMG_225x225, self.RESIZE_OP, True)

def test_fileresize_and_scale(self):
self._require_backend()
self.plugin.maxwidth = 200
self.plugin.max_filesize = self.IMG_225x225_SIZE // 2
self._assert_image_operated(self.IMG_225x225, self.RESIZE_OP, True)

def test_deinterlace(self):
self._require_backend()
self.plugin.deinterlace = True
self._assert_image_operated(self.IMG_225x225, self.DEINTERLACE_OP, True)
self.plugin.deinterlace = False
Expand All @@ -970,7 +951,6 @@ def test_deinterlace(self):
)

def test_deinterlace_and_resize(self):
self._require_backend()
self.plugin.maxwidth = 300
self.plugin.deinterlace = True
self._assert_image_operated(self.IMG_348x348, self.DEINTERLACE_OP, True)
Expand Down
2 changes: 1 addition & 1 deletion test/plugins/test_embedart.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def wrapper(*args, **kwargs):
return wrapper


class EmbedartCliTest(TestHelper, FetchImageHelper):
class EmbedartCliTest(TestHelper, FetchImageHelper, unittest.TestCase):
small_artpath = os.path.join(_common.RSRC, b"image-2x3.jpg")
abbey_artpath = os.path.join(_common.RSRC, b"abbey.jpg")
abbey_similarpath = os.path.join(_common.RSRC, b"abbey-similar.jpg")
Expand Down
9 changes: 5 additions & 4 deletions test/plugins/test_fetchart.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ def check_cover_is_stored(self):

def hide_file_windows(self):
hidden_mask = 2
success = ctypes.windll.kernel32.SetFileAttributesW(
self.cover_path, hidden_mask
self.assertTrue(
ctypes.windll.kernel32.SetFileAttributesW(
self.cover_path, hidden_mask
),
"Could not set file attributes",
)
if not success:
self.skipTest("unable to set file attributes")

def test_set_art_from_folder(self):
self.touch(b"c\xc3\xb6ver.jpg", dir=self.album.path, content="IMAGE")
Expand Down
78 changes: 15 additions & 63 deletions test/plugins/test_lyrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,16 +249,12 @@ def assertLyricsContentOk(self, title, text, msg=""): # noqa: N802
LYRICS_TEXTS = confuse.load_yaml(yaml_path)


class LyricsGoogleBaseTest(unittest.TestCase):
class LyricsTestCase(unittest.TestCase):
def setUp(self):
"""Set up configuration."""
try:
__import__("bs4")
except ImportError:
self.skipTest("Beautiful Soup 4 not available")
self.plugin = lyrics.LyricsPlugin()


class LyricsPluginSourcesTest(LyricsGoogleBaseTest, LyricsAssertions):
class LyricsPluginSourcesTest(LyricsTestCase, LyricsAssertions):
"""Check that beets google custom search engine sources are correctly
scraped.
"""
Expand Down Expand Up @@ -346,10 +342,6 @@ class LyricsPluginSourcesTest(LyricsGoogleBaseTest, LyricsAssertions):
),
]

def setUp(self):
LyricsGoogleBaseTest.setUp(self)
self.plugin = lyrics.LyricsPlugin()

@unittest.skipUnless(
os.environ.get("INTEGRATION_TEST", "0") == "1",
"integration testing not enabled",
Expand Down Expand Up @@ -383,7 +375,7 @@ def test_google_sources_ok(self):
self.assertLyricsContentOk(s["title"], res, url)


class LyricsGooglePluginMachineryTest(LyricsGoogleBaseTest, LyricsAssertions):
class LyricsGooglePluginMachineryTest(LyricsTestCase, LyricsAssertions):
"""Test scraping heuristics on a fake html page."""

source = dict(
Expand All @@ -393,11 +385,6 @@ class LyricsGooglePluginMachineryTest(LyricsGoogleBaseTest, LyricsAssertions):
path="/lyrics/beetssong",
)

def setUp(self):
"""Set up configuration"""
LyricsGoogleBaseTest.setUp(self)
self.plugin = lyrics.LyricsPlugin()

@patch.object(lyrics.Backend, "fetch_url", MockFetchUrl())
def test_mocked_source_ok(self):
"""Test that lyrics of the mocked page are correctly scraped"""
Expand Down Expand Up @@ -461,23 +448,9 @@ def test_is_page_candidate_special_chars(self):
# test Genius backend


class GeniusBaseTest(unittest.TestCase):
def setUp(self):
"""Set up configuration."""
try:
__import__("bs4")
except ImportError:
self.skipTest("Beautiful Soup 4 not available")


class GeniusScrapeLyricsFromHtmlTest(GeniusBaseTest):
class GeniusScrapeLyricsFromHtmlTest(LyricsTestCase):
"""tests Genius._scrape_lyrics_from_html()"""

def setUp(self):
"""Set up configuration"""
GeniusBaseTest.setUp(self)
self.plugin = lyrics.LyricsPlugin()

def test_no_lyrics_div(self):
"""Ensure we don't crash when the scraping the html for a genius page
doesn't contain <div class="lyrics"></div>
Expand Down Expand Up @@ -507,14 +480,9 @@ def test_good_lyrics_multiple_divs(self):
# TODO: find an example of a lyrics page with multiple divs and test it


class GeniusFetchTest(GeniusBaseTest):
class GeniusFetchTest(LyricsTestCase):
"""tests Genius.fetch()"""

def setUp(self):
"""Set up configuration"""
GeniusBaseTest.setUp(self)
self.plugin = lyrics.LyricsPlugin()

@patch.object(lyrics.Genius, "_scrape_lyrics_from_html")
@patch.object(lyrics.Backend, "fetch_url", return_value=True)
def test_json(self, mock_fetch_url, mock_scrape):
Expand Down Expand Up @@ -567,22 +535,12 @@ def test_json(self, mock_fetch_url, mock_scrape):
# test Tekstowo


class TekstowoBaseTest(unittest.TestCase):
def setUp(self):
"""Set up configuration."""
try:
__import__("bs4")
except ImportError:
self.skipTest("Beautiful Soup 4 not available")


class TekstowoExtractLyricsTest(TekstowoBaseTest):
class TekstowoExtractLyricsTest(LyricsTestCase):
"""tests Tekstowo.extract_lyrics()"""

def setUp(self):
"""Set up configuration"""
TekstowoBaseTest.setUp(self)
self.plugin = lyrics.LyricsPlugin()
super().setUp()
tekstowo.config = self.plugin.config

def test_good_lyrics(self):
Expand Down Expand Up @@ -628,14 +586,9 @@ def test_song_no_match(self):
)


class TekstowoParseSearchResultsTest(TekstowoBaseTest):
class TekstowoParseSearchResultsTest(LyricsTestCase):
"""tests Tekstowo.parse_search_results()"""

def setUp(self):
"""Set up configuration"""
TekstowoBaseTest.setUp(self)
self.plugin = lyrics.LyricsPlugin()

def test_multiple_results(self):
"""Ensure we are able to scrape a page with multiple search results"""
url = (
Expand All @@ -659,13 +612,12 @@ def test_no_results(self):
self.assertEqual(tekstowo.parse_search_results(mock(url)), None)


class TekstowoIntegrationTest(TekstowoBaseTest, LyricsAssertions):
class TekstowoIntegrationTest(LyricsTestCase, LyricsAssertions):
"""Tests Tekstowo lyric source with real requests"""

def setUp(self):
"""Set up configuration"""
TekstowoBaseTest.setUp(self)
self.plugin = lyrics.LyricsPlugin()
super().setUp()
tekstowo.config = self.plugin.config

@unittest.skipUnless(
Expand Down Expand Up @@ -693,9 +645,9 @@ def test_no_matching_results(self):
# test LRCLib backend


class LRCLibLyricsTest(unittest.TestCase):
class LRCLibLyricsTest(LyricsTestCase):
def setUp(self):
self.plugin = lyrics.LyricsPlugin()
super().setUp()
lrclib.config = self.plugin.config

@patch("beetsplug.lyrics.requests.get")
Expand Down Expand Up @@ -750,9 +702,9 @@ def test_fetch_exception(self, mock_get):
self.assertIsNone(lyrics)


class LRCLibIntegrationTest(LyricsAssertions):
class LRCLibIntegrationTest(LyricsTestCase, LyricsAssertions):
def setUp(self):
self.plugin = lyrics.LyricsPlugin()
super().setUp()
lrclib.config = self.plugin.config

@unittest.skipUnless(
Expand Down
Loading
Loading