diff --git a/src/dakara_player/media_player/mpv.py b/src/dakara_player/media_player/mpv.py index 66a2236..b9dedf3 100644 --- a/src/dakara_player/media_player/mpv.py +++ b/src/dakara_player/media_player/mpv.py @@ -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. @@ -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)) diff --git a/tests/unit/test_media_player_mpv.py b/tests/unit/test_media_player_mpv.py index fd7ea79..67d6d9f 100644 --- a/tests/unit/test_media_player_mpv.py +++ b/tests/unit/test_media_player_mpv.py @@ -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" @@ -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" @@ -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."""