Skip to content

Commit

Permalink
fix(multipass): parse dev multipass versions
Browse files Browse the repository at this point in the history
  • Loading branch information
lengau committed Sep 26, 2024
1 parent 7494548 commit d7cfb80
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
12 changes: 11 additions & 1 deletion craft_providers/multipass/multipass.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,17 @@ def is_supported_version(self) -> bool:
minimum_version = packaging.version.parse(self.minimum_required_version)
version, _ = self.version()

return packaging.version.parse(version) >= minimum_version
parsed_version = None
while parsed_version is None:
try:
parsed_version = packaging.version.parse(version)
except packaging.version.InvalidVersion:
# This catches versions such as: 1.15.0-dev.2929.pr661, which are
# compliant, but not pep440 compliant. We can lob off sections until
# we get a pep440 cempliant version.
version = version.rpartition(".")[0]

return parsed_version >= minimum_version

def launch(
self,
Expand Down
37 changes: 29 additions & 8 deletions tests/unit/multipass/test_multipass.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,20 +201,31 @@ def test_info_error(fake_process, mock_details_from_process_error):
)


def test_is_supported_version(fake_process):
fake_process.register_subprocess(
["multipass", "version"], stdout=b"multipass 1.7.0\nmultipassd 1.7.0\n"
)
@pytest.mark.parametrize(
"version_output",
[
b"multipass 1.7.0\nmultipassd 1.7.0\n",
b"multipass 1.15.0-dev.354+g533e02ffc\nmultipassd 1.15.0-dev.354+g533e02ffc\n", # Snap multipass, edge channel
b"multipass 1.15.0-dev.2929.pr661+gc67ef6641.mac\nmultipassd 1.15.0-dev.2929.pr661+gc67ef6641.mac", # Dev build on a mac
],
)
def test_is_supported_version(fake_process, version_output):
fake_process.register_subprocess(["multipass", "version"], stdout=version_output)

assert Multipass().is_supported_version() is True

assert len(fake_process.calls) == 1


def test_is_supported_version_false(fake_process):
fake_process.register_subprocess(
["multipass", "version"], stdout=b"multipass 1.4.0\nmultipassd 1.4.0\n"
)
@pytest.mark.parametrize(
"version_output",
[
b"multipass 1.4.0\nmultipassd 1.4.0\n",
b"multipass 1.invalid.15.999\nmultipassd 999\n",
],
)
def test_is_supported_version_false(fake_process, version_output):
fake_process.register_subprocess(["multipass", "version"], stdout=version_output)

assert Multipass().is_supported_version() is False

Expand Down Expand Up @@ -718,6 +729,16 @@ def test_wait_until_ready_timeout_error(
),
("1.6.2", "1.6.3"),
),
pytest.param(
b"multipass 1.15.0-dev.354+g533e02ffc\nmultipassd 1.15.0-dev.354+g533e02ffc\n",
("1.15.0-dev.354", "1.15.0-dev.354"),
id="snap-edge-channel",
),
pytest.param(
b"multipass 1.15.0-dev.2929.pr661+gc67ef6641.mac\nmultipassd 1.15.0-dev.2929.pr661+gc67ef6641.mac",
("1.15.0-dev.2929.pr661", "1.15.0-dev.2929.pr661"),
id="macos-dev-build",
),
],
)
def test_version(fake_process, output, expected):
Expand Down

0 comments on commit d7cfb80

Please sign in to comment.