import pytest import os import json import solo_turnier.html_parser @pytest.fixture(scope='module', params=range(2)) def dataProviderHtmlParser(request): variant = str(request.param+1) dir = os.path.join(os.path.dirname(__file__), 'html_parser', 'erg', variant) htmlFile = os.path.join(dir, 'erg.htm') jsonFile = os.path.join(dir, 'expected.json') with open(htmlFile, 'r') as fp: html = fp.read() with open(jsonFile, 'r') as fp: jsonContent = json.load(fp) return (html, jsonContent) def test_extractDataFromHtml(dataProviderHtmlParser): htmlString = dataProviderHtmlParser[0] expected = dataProviderHtmlParser[1] parser = solo_turnier.html_parser.HtmlParser(htmlString) actualResult = parser.parseString(htmlString) 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(6)) def fixture_guessDataFromTitle(request): cases = { '09.07.2022 - ETW, Solos Jun. Beginner Jive': { 'class_': 'Beg.', 'dance': 'Jive', 'group': 'Jun.' }, '09.07.2022 - ETW, Solos Jun. Newc./Beg. Rumba': { 'class_': 'Newc./Beg.', 'dance': 'Rumba', 'group': 'Jun.' }, '09.07.2022 - ETW, Solos Kin./Jun. Beginner Cha Cha': { 'class_': 'Beg.', 'dance': 'Cha Cha', 'group': 'Kin./Jun.' }, '09.07.2022 - ETW, Solos Kin. Newcomer Samba': { 'class_': 'Newc.', 'dance': 'Samba', 'group': 'Kin.' }, '09.07.2022 - ETW, Solos Jugend Beg./Adv. Wiener Walzer': { 'class_': 'Beg./Adv.', 'dance': 'Wiener Walzer', 'group': 'Jug.' }, '09.07.2022 - ETW, Solos Jugend Sichtung Wiener Walzer': { 'class_': 'Sichtung', 'dance': 'Wiener Walzer', 'group': 'Jug.' }, } keys = list(cases.keys()) key = keys[request.param] return (key, cases[key]) def test_guessDataFromTitle(fixture_guessDataFromTitle): parser = solo_turnier.html_parser.HtmlParser('') ret = parser.guessDataFromHtmlTitle(fixture_guessDataFromTitle[0]) assert ret == fixture_guessDataFromTitle[1] @pytest.fixture(params=range(1)) def fixture_parsePreparationResult(request): variant = str(request.param+1) dir = os.path.join(os.path.dirname(__file__), 'html_parser', 'tabges', variant) htmlFile = os.path.join(dir, 'tabges.htm') jsonFile = os.path.join(dir, 'expected.json') with open(htmlFile, 'r') as fp: html = fp.read() with open(jsonFile, 'r') as fp: jsonContent = json.load(fp) return (html, jsonContent) def test_parsePreparationResult(fixture_parsePreparationResult): html = fixture_parsePreparationResult[0] jsonContent = fixture_parsePreparationResult[1] parser = solo_turnier.html_parser.HtmlParser(html) ret = parser.parsePreparationRound() assert ret == jsonContent @pytest.fixture(params=range(1)) def fixture_cleanPreparationImport(request): variant = str(request.param+1) dir = os.path.join(os.path.dirname(__file__), 'html_parser', 'tabges', variant) srcFile = os.path.join(dir, 'expected.json') expectedFile = os.path.join(dir, 'cleaned.json') with open(srcFile, 'r') as fp: source = json.load(fp) with open(expectedFile, 'r') as fp: expected = json.load(fp) return (source, expected) def test_cleanPreparationImport(fixture_cleanPreparationImport): src = fixture_cleanPreparationImport[0] expected = fixture_cleanPreparationImport[1] parser = solo_turnier.html_parser.HtmlParser('') parser.cleanPreparationRoundImport(src) assert src == expected