Usage of objects in HTML parser
This commit is contained in:
parent
4275466cca
commit
358f985978
@ -3,6 +3,17 @@ from bs4 import BeautifulSoup
|
||||
import logging
|
||||
import re
|
||||
|
||||
class HtmlParticipant:
|
||||
def __init__(self, name, place, finalist):
|
||||
self.name = name
|
||||
self.place = place
|
||||
self.finalist = finalist
|
||||
|
||||
class HtmlImport:
|
||||
def __init__(self, title: str, participants: dict[int, HtmlParticipant]):
|
||||
self.title = title
|
||||
self.participants = participants
|
||||
|
||||
class HtmlParser:
|
||||
|
||||
def __init__(self):
|
||||
@ -26,11 +37,7 @@ class HtmlParser:
|
||||
name = match.group(1)
|
||||
number = match.group(2)
|
||||
|
||||
participant = {
|
||||
'name': name,
|
||||
'place': place,
|
||||
'finalist': finalist
|
||||
}
|
||||
participant = HtmlParticipant(name, place, finalist)
|
||||
participants[number] = participant
|
||||
|
||||
for row in rows:
|
||||
@ -55,10 +62,7 @@ class HtmlParser:
|
||||
|
||||
title = soup.find('div', class_='eventhead').table.tr.td.contents[0]
|
||||
|
||||
ret = {
|
||||
'participants': participants,
|
||||
'title': title
|
||||
}
|
||||
ret = HtmlImport(title, participants)
|
||||
return ret
|
||||
|
||||
def guessDataFromHtmlTitle(self, title):
|
||||
|
@ -25,7 +25,12 @@ def test_extractDataFromHtml(dataProviderHtmlParser):
|
||||
parser = solo_turnier.html_parser.HtmlParser()
|
||||
actualResult = parser.parseString(htmlString)
|
||||
|
||||
assert actualResult == expected
|
||||
participants = {}
|
||||
for i in actualResult.participants:
|
||||
participants[i] = actualResult.participants[i].__dict__
|
||||
|
||||
assert actualResult.title == expected['title']
|
||||
assert participants == expected['participants']
|
||||
|
||||
@pytest.fixture(params=range(5))
|
||||
def fixture_guessDataFromTitle(request):
|
||||
|
Loading…
Reference in New Issue
Block a user