diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 544d049..af6c27e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest] # does not work with windows-latest - python-version: ["3.12", "3.13"] + python-version: ["3.8", "3.13"] steps: - uses: actions/checkout@v4 diff --git a/actions/__init__.py b/actions/__init__.py index d7563d3..adbaf5c 100644 --- a/actions/__init__.py +++ b/actions/__init__.py @@ -22,4 +22,4 @@ # ├── test_summarize_pr.py # └── ... -__version__ = "0.0.84" +__version__ = "0.0.85" diff --git a/actions/utils/github_utils.py b/actions/utils/github_utils.py index 47b8971..e3e0296 100644 --- a/actions/utils/github_utils.py +++ b/actions/utils/github_utils.py @@ -3,6 +3,7 @@ import json import os from pathlib import Path +from typing import Union import requests @@ -95,7 +96,7 @@ class Action: """Checks if the repository is public using event data or GitHub API if needed.""" return self.event_data.get("repository", {}).get("private") - def get_username(self) -> str | None: + def get_username(self) -> Union[str, None]: """Gets username associated with the GitHub token.""" response = self.post(GITHUB_GRAPHQL_URL, json={"query": "query { viewer { login } }"}) if response.status_code == 200: diff --git a/tests/test_github_utils.py b/tests/test_github_utils.py index 7bd7648..9448e0e 100644 --- a/tests/test_github_utils.py +++ b/tests/test_github_utils.py @@ -1,10 +1,30 @@ # Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license +import sys from unittest.mock import MagicMock, patch +import pytest + from actions.utils import Action, check_pypi_version, ultralytics_actions_info +@pytest.mark.skipif(sys.version_info < (3, 11), reason="tomllib requires Python 3.11+") +def test_check_pypi_version(): + """Test check_pypi_version function.""" + with patch("tomllib.load", return_value={"project": {"name": "test-package", "version": "1.0.0"}}): + with patch("requests.get") as mock_get: + mock_response = MagicMock() + mock_response.status_code = 200 + mock_response.json.return_value = {"info": {"version": "0.9.0"}} + mock_get.return_value = mock_response + + local_version, online_version, publish = check_pypi_version() + + assert local_version == "1.0.0" + assert online_version == "0.9.0" + assert publish is True + + def test_action_init(): """Test Action class initialization with default values.""" with patch.dict("os.environ", {"GITHUB_TOKEN": "test-token", "GITHUB_EVENT_NAME": "push"}): @@ -41,22 +61,6 @@ def test_load_event_data(): assert data == {"test": "data"} -def test_check_pypi_version(): - """Test check_pypi_version function.""" - with patch("tomllib.load", return_value={"project": {"name": "test-package", "version": "1.0.0"}}): - with patch("requests.get") as mock_get: - mock_response = MagicMock() - mock_response.status_code = 200 - mock_response.json.return_value = {"info": {"version": "0.9.0"}} - mock_get.return_value = mock_response - - local_version, online_version, publish = check_pypi_version() - - assert local_version == "1.0.0" - assert online_version == "0.9.0" - assert publish is True - - def test_ultralytics_actions_info(): """Test ultralytics_actions_info function.""" with patch("actions.utils.github_utils.Action.print_info") as mock_print_info: