Skip to content

Commit

Permalink
Merge pull request #115 from odrling/fix-mpv-version-parsing
Browse files Browse the repository at this point in the history
fix mpv version parsing
  • Loading branch information
Neraste authored Mar 18, 2024
2 parents 1f5d54d + 5c662dd commit 3524b20
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
16 changes: 7 additions & 9 deletions src/dakara_player/media_player/mpv.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,10 @@ def is_available():
def get_version():
"""Get media player version.
mpv version is in the form "mpv x.y.z+git.v.w" where "v" is a timestamp
and "w" a commit hash for post releases, or "mpv x.y.z" for releases.
In case of post release, as the version given by mpv does not respect
semantic versionning, the sub-version is the concatenation of the day
part and the time part of "v".
mpv versions are in the form "vMAJOR.MINOR.PATCH" for releases, older
versions (<0.37) do not include a 'v' before the version, post releases
are detected as any valid base version followed by "+BUILD" or "-BUILD"
where BUILD is whatever build information was included in the string.
Returns:
packaging.version.Version: Parsed version of mpv.
Expand All @@ -105,14 +103,14 @@ def get_version():
"""
player = mpv.MPV()
match = re.search(
r"mpv (\d+\.\d+\.\d+)(?:\+git\.(\d{8})T(\d{6})\..*)?",
r"mpv v?(\d+\.\d+\.\d+)([+-]\w+)?",
player.mpv_version,
)
player.terminate()

if match:
if match.group(2) and match.group(3):
return parse(match.group(1) + "-post" + match.group(2) + match.group(3))
if match.group(2):
return parse(match.group(1) + "-post")

return parse(match.group(1))

Expand Down
34 changes: 30 additions & 4 deletions tests/unit/test_media_player_mpv.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class MediaPlayerMpvTestCase(TestCase):
"""Test the static methods of the abstract MediaPlayerMpv class."""

@patch("dakara_player.media_player.mpv.mpv.MPV")
def test_get_version_postrelease(self, mocked_mpv_class):
"""Test to get the mpv post release version."""
def test_get_version_opensuse_postrelease(self, mocked_mpv_class):
"""Test to get the version from an openSUSE mpv build."""
# mock the version of mpv
mocked_mpv_class.return_value.mpv_version = (
"mpv 0.32.0+git.20200402T120653.5824ac7d36"
Expand All @@ -40,8 +40,8 @@ def test_get_version_postrelease(self, mocked_mpv_class):
self.assertTrue(version.is_postrelease)

@patch("dakara_player.media_player.mpv.mpv.MPV")
def test_get_version(self, mocked_mpv_class):
"""Test to get the mpv stable version."""
def test_get_version_old(self, mocked_mpv_class):
"""Test to get the version from a release build of mpv <0.37."""
# mock the version of mpv
mocked_mpv_class.return_value.mpv_version = "mpv 0.32.0"

Expand All @@ -52,6 +52,32 @@ def test_get_version(self, mocked_mpv_class):
self.assertEqual(version.base_version, "0.32.0")
self.assertFalse(version.is_postrelease)

@patch("dakara_player.media_player.mpv.mpv.MPV")
def test_get_version_meson(self, mocked_mpv_class):
"""Test to get the version from a release build of mpv >=0.37."""
# mock the version of mpv
mocked_mpv_class.return_value.mpv_version = "mpv v0.37.0"

# call the method
version = MediaPlayerMpv.get_version()

# assert the result
self.assertEqual(version.base_version, "0.37.0")
self.assertFalse(version.is_postrelease)

@patch("dakara_player.media_player.mpv.mpv.MPV")
def test_get_version_meson_git(self, mocked_mpv_class):
"""Test to get the version from a vcs build of mpv."""
# mock the version of mpv
mocked_mpv_class.return_value.mpv_version = "mpv v0.37.0-364-g2cc3bc12db"

# call the method
version = MediaPlayerMpv.get_version()

# assert the result
self.assertEqual(version.base_version, "0.37.0")
self.assertTrue(version.is_postrelease)

@patch("dakara_player.media_player.mpv.mpv.MPV")
def test_get_version_not_found(self, mocked_mpv_class):
"""Test to get the mpv version when it is not available."""
Expand Down

0 comments on commit 3524b20

Please sign in to comment.