Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions mapilio_kit/components/utilities/info.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
import sys
import time

Expand Down Expand Up @@ -38,10 +39,9 @@ def get_latest_version():
url = "https://raw.githubusercontent.com/mapilio/mapilio-kit/main/mapilio_kit/components/version.py"
response = requests.get(url)
if response.status_code == 200:
content = response.text
version_line = [line for line in content.split('\n') if 'VERSION' in line][0]
latest_version = version_line.split('"')[1]
return latest_version
match = re.search(r"""VERSION\s*=\s*["']([^"']+)["']""", response.text)
if match:
return match.group(1)
return None


Expand Down
54 changes: 54 additions & 0 deletions tests/test_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""Regression tests for ``mapilio_kit.components.utilities.info.get_latest_version``.

Covers the IndexError bug (GitHub issue #209) caused by a hard-coded quote
delimiter that broke when version.py switched quote styles.
"""

from __future__ import annotations

from unittest.mock import MagicMock, patch

import pytest

from mapilio_kit.components.utilities.info import get_latest_version


def _mock_response(text: str, status_code: int = 200) -> MagicMock:
resp = MagicMock()
resp.status_code = status_code
resp.text = text
return resp


@pytest.mark.parametrize(
"version_py_content, expected",
[
('VERSION = "3.0.6"', "3.0.6"),
("VERSION = '3.0.5'", "3.0.5"),
('VERSION = "3.1.0-beta"', "3.1.0-beta"),
],
)
def test_get_latest_version_parses_both_quote_styles(
version_py_content: str, expected: str
) -> None:
with patch(
"mapilio_kit.components.utilities.info.requests.get",
return_value=_mock_response(version_py_content),
):
assert get_latest_version() == expected


def test_get_latest_version_returns_none_on_http_error() -> None:
with patch(
"mapilio_kit.components.utilities.info.requests.get",
return_value=_mock_response("", status_code=404),
):
assert get_latest_version() is None


def test_get_latest_version_returns_none_when_no_version_line() -> None:
with patch(
"mapilio_kit.components.utilities.info.requests.get",
return_value=_mock_response("# no version here\n"),
):
assert get_latest_version() is None
Loading