Skip to content

Commit

Permalink
WEB: Better management of releases (#56207)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dukastlik authored Dec 13, 2023
1 parent f571cce commit db6fd22
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .github/workflows/docbuild-and-upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ jobs:
- name: Build Pandas
uses: ./.github/actions/build_pandas

- name: Test website
run: python -m pytest web/

- name: Build website
run: python web/pandas_web.py web/pandas --target-path=web/build

Expand Down
15 changes: 14 additions & 1 deletion web/pandas_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import collections
import datetime
import importlib
import itertools
import json
import operator
import os
Expand All @@ -40,6 +41,7 @@
import feedparser
import jinja2
import markdown
from packaging import version
import requests
import yaml

Expand Down Expand Up @@ -245,6 +247,7 @@ def home_add_releases(context):
context["releases"].append(
{
"name": release["tag_name"].lstrip("v"),
"parsed_version": version.parse(release["tag_name"].lstrip("v")),
"tag": release["tag_name"],
"published": published,
"url": (
Expand All @@ -254,7 +257,17 @@ def home_add_releases(context):
),
}
)

# sorting out obsolete versions
grouped_releases = itertools.groupby(
context["releases"],
key=lambda r: (r["parsed_version"].major, r["parsed_version"].minor),
)
context["releases"] = [
max(release_group, key=lambda r: r["parsed_version"].minor)
for _, release_group in grouped_releases
]
# sorting releases by version number
context["releases"].sort(key=lambda r: r["parsed_version"], reverse=True)
return context

@staticmethod
Expand Down
88 changes: 88 additions & 0 deletions web/tests/test_pandas_web.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
from unittest.mock import (
mock_open,
patch,
)

import pytest
import requests

from web.pandas_web import Preprocessors


class MockResponse:
def __init__(self, status_code: int, response: dict):
self.status_code = status_code
self._resp = response

def json(self):
return self._resp

@staticmethod
def raise_for_status():
return


@pytest.fixture
def context() -> dict:
return {
"main": {"github_repo_url": "pandas-dev/pandas"},
"target_path": "test_target_path",
}


@pytest.fixture(scope="function")
def mock_response(monkeypatch, request):
def mocked_resp(*args, **kwargs):
status_code, response = request.param
return MockResponse(status_code, response)

monkeypatch.setattr(requests, "get", mocked_resp)


_releases_list = [
{
"prerelease": False,
"published_at": "2024-01-19T03:34:05Z",
"tag_name": "v1.5.6",
"assets": None,
},
{
"prerelease": False,
"published_at": "2023-11-10T19:07:37Z",
"tag_name": "v2.1.3",
"assets": None,
},
{
"prerelease": False,
"published_at": "2023-08-30T13:24:32Z",
"tag_name": "v2.1.0",
"assets": None,
},
{
"prerelease": False,
"published_at": "2023-04-30T13:24:32Z",
"tag_name": "v2.0.0",
"assets": None,
},
{
"prerelease": True,
"published_at": "2023-01-19T03:34:05Z",
"tag_name": "v1.5.3xd",
"assets": None,
},
{
"prerelease": False,
"published_at": "2027-01-19T03:34:05Z",
"tag_name": "v10.0.1",
"assets": None,
},
]


@pytest.mark.parametrize("mock_response", [(200, _releases_list)], indirect=True)
def test_web_preprocessor_creates_releases(mock_response, context):
m = mock_open()
with patch("builtins.open", m):
context = Preprocessors.home_add_releases(context)
release_versions = [release["name"] for release in context["releases"]]
assert release_versions == ["10.0.1", "2.1.3", "2.0.0", "1.5.6"]

0 comments on commit db6fd22

Please sign in to comment.