Skip to content

Commit

Permalink
change parsing functions
Browse files Browse the repository at this point in the history
  • Loading branch information
vlaszdunov committed Jun 5, 2024
1 parent e4707b4 commit f1a40a5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
7 changes: 3 additions & 4 deletions src/version_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
headers = json.loads(Path('src/request_header.json').read_bytes())


def get_page_content(internal_page: str = '') -> bs:
page_content = requests.get(BASE_URL+internal_page, headers=headers).text
def get_page_content(base_url, internal_page: str = '') -> bs:
page_content = requests.get(base_url+internal_page, headers=headers).text
return bs(page_content, 'lxml')


def get_active_versions(internal_url: str) -> list[str]:
page_content = get_page_content(internal_url)
def get_active_versions(page_content: bs) -> list[str]:
active_versions_raw_list = page_content.find_all(
'span', attrs={'class': 'release-version'})

Expand Down
3 changes: 3 additions & 0 deletions tests/test_html.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<span class="release-version">3.11</span>
<span>4</span>
<span class="version">2</span>
11 changes: 7 additions & 4 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
from pathlib import Path

import pytest

from src.version_parser import *

BASE_URL = 'https://www.python.org/'


test_html = bs(Path('tests/test_html.html').read_text(), 'lxml')


def test_get_page_content():
page_content = get_page_content(BASE_URL)
assert len(page_content.contents) != 0


def test_get_versions():
# Проверяем, что функция get_versions() использует результаты get_data()
actual_versions = get_active_versions('downloads/')
# Предположим, что это версии, которые мы ожидаем получить
assert actual_versions.__class__==list
actual_versions = get_active_versions(test_html)
assert actual_versions == ['3.11']

0 comments on commit f1a40a5

Please sign in to comment.