Skip to content

Commit

Permalink
add function that grouping versions by major release
Browse files Browse the repository at this point in the history
  • Loading branch information
vlaszdunov committed Jun 9, 2024
1 parent 327ef14 commit 50e5a66
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
18 changes: 15 additions & 3 deletions src/version_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def get_active_versions(page_content: bs) -> list[str]:
return active_versions_list


def get_stable_releases_links(page_content: bs, active_versions_list: list)->list[str]:
def get_stable_releases_links(page_content: bs, active_versions_list: list) -> list[str]:
active_stable_releases_link = []
stable_releases_links = page_content.find_all('a')
for link in stable_releases_links:
Expand All @@ -37,5 +37,17 @@ def get_stable_releases_links(page_content: bs, active_versions_list: list)->lis
return active_stable_releases_link


def get_newest_releases_links(active_stable_releases_link: list[str]) -> list[str]:
pass
def group_releases_by_major_version(active_stable_releases_link: list[str], active_versions: list[str]):
last_stable_releases = dict.fromkeys(active_versions)
for key in last_stable_releases:
last_stable_releases[key] = []

for link in active_stable_releases_link:
a = re.search(r'\d+.\d+', link)[0]
last_stable_releases[a].append(link)

return last_stable_releases


# group_releases_by_major_version(get_stable_releases_links(get_page_content(BASE_URL, 'downloads/source/'),
# get_active_versions(get_page_content(BASE_URL, 'downloads/'))), get_active_versions(get_page_content(BASE_URL, 'downloads/')))
4 changes: 2 additions & 2 deletions tests/test_download_link.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<a href="https://www.python.org/ftp/python/3.12.3/Python-3.12.3.tgz">Gzipped source tarball</a>
<a href="https://www.python.org/ftp/python/3.11.5/Python-3.11.4.tgz">Gzipped source tarball</a>
<a href="https://www.python.org/ftp/python/3.11.5/Python-3.11.9.tgz">Gzipped source tarball</a>
<a href="https://www.python.org/ftp/python/3.11.9/Python-3.11.9.tgz">Gzipped source tarball</a>
<a href="https://www.python.org/ftp/python/3.11.4/Python-3.11.4.tgz">Gzipped source tarball</a>
14 changes: 9 additions & 5 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from src.version_parser import *

BASE_URL = 'https://www.python.org/'
correct_test_download_links = ['https://www.python.org/ftp/python/3.11.5/Python-3.11.4.tgz',\
'https://www.python.org/ftp/python/3.11.5/Python-3.11.9.tgz']
correct_test_download_links = ['https://www.python.org/ftp/python/3.11.9/Python-3.11.9.tgz',
'https://www.python.org/ftp/python/3.11.4/Python-3.11.4.tgz']

test_active_version_page = bs(Path('tests/test_active_versions.html')
.read_text(), 'lxml')
Expand All @@ -29,6 +29,10 @@ def test_get_stable_releases_link():
test_download_links_page, ['3.11'])
assert active_versions_links == correct_test_download_links

def test_get_newest_releases_links():
latest_releases_links = get_newest_releases_links(correct_test_download_links)
assert latest_releases_links == ['https://www.python.org/ftp/python/3.11.5/Python-3.11.9.tgz']

def test_grouping_releases_by_major_version():
latest_releases_links = group_releases_by_major_version(
correct_test_download_links, ['3.11'])
print(latest_releases_links)
assert latest_releases_links == {
'3.11': correct_test_download_links}

0 comments on commit 50e5a66

Please sign in to comment.