Extract data from HTML to allow for simpler extraction
This commit is contained in:
		
							parent
							
								
									8301ae206f
								
							
						
					
					
						commit
						867b18576f
					
				| @ -2,6 +2,7 @@ from solo_turnier import worker | |||||||
| import os | import os | ||||||
| import json | import json | ||||||
| import pytest | import pytest | ||||||
|  | import pytest_mock | ||||||
| 
 | 
 | ||||||
| def __importJSONData(name): | def __importJSONData(name): | ||||||
|     path = os.path.join(os.path.dirname(__file__), 'worker', name) |     path = os.path.join(os.path.dirname(__file__), 'worker', name) | ||||||
| @ -190,3 +191,28 @@ def test_consolidateGroups_failing(fixture_consolidateGroups_fail): | |||||||
| 
 | 
 | ||||||
|     with pytest.raises(Exception): |     with pytest.raises(Exception): | ||||||
|         dataWorker.consolidateGroups(data) |         dataWorker.consolidateGroups(data) | ||||||
|  | 
 | ||||||
|  | def test_createHtmlLUT(mocker): | ||||||
|  |     mock = mocker.patch('solo_turnier.html_parser.HtmlParser.guessDataFromHtmlTitle') | ||||||
|  |     mock.side_effect= [ | ||||||
|  |         {'group': 'group1', 'class_': 'class1', 'dance': 'dance1'}, | ||||||
|  |         {'group': 'group2', 'class_': 'class2', 'dance': 'dance2'}, | ||||||
|  |         {'group': 'group3', 'class_': 'class3', 'dance': 'dance3'}, | ||||||
|  |     ] | ||||||
|  |      | ||||||
|  |     importMock1 = mocker.patch('solo_turnier.html_parser.HtmlImport') | ||||||
|  |     importMock2 = mocker.patch('solo_turnier.html_parser.HtmlImport') | ||||||
|  |     importMock3 = mocker.patch('solo_turnier.html_parser.HtmlImport') | ||||||
|  |     importMock1.title = 'Fake title 1' | ||||||
|  |     importMock2.title = 'Fake title 2' | ||||||
|  |     importMock3.title = 'Fake title 3' | ||||||
|  | 
 | ||||||
|  |     dataWorker = worker.DataWorker() | ||||||
|  |     structure = dataWorker._createHtmlLUT([importMock1, importMock2, importMock3]) | ||||||
|  | 
 | ||||||
|  |     expected = { | ||||||
|  |         ('group1', 'class1', 'dance1'): importMock1, | ||||||
|  |         ('group2', 'class2', 'dance2'): importMock2, | ||||||
|  |         ('group3', 'class3', 'dance3'): importMock3, | ||||||
|  |     } | ||||||
|  |     assert expected == structure | ||||||
|  | |||||||
| @ -1,5 +1,6 @@ | |||||||
| import logging | import logging | ||||||
| 
 | 
 | ||||||
|  | from solo_turnier import html_parser | ||||||
| class ResultRow: | class ResultRow: | ||||||
|     def __init__(self, firstName, lastName, club, id, group, class_, dance, place, placeTo, competitionGroup, competitionClass): |     def __init__(self, firstName, lastName, club, id, group, class_, dance, place, placeTo, competitionGroup, competitionClass): | ||||||
|         self.firstName = firstName |         self.firstName = firstName | ||||||
| @ -196,3 +197,13 @@ class DataWorker: | |||||||
|                 raise Exception(f'{person} cannot have different groups.') |                 raise Exception(f'{person} cannot have different groups.') | ||||||
|              |              | ||||||
|         return (not ambiguous, warnChange) |         return (not ambiguous, warnChange) | ||||||
|  | 
 | ||||||
|  |     def _createHtmlLUT(self, htmlImports: list[html_parser.HtmlImport]): | ||||||
|  |         ret = {} | ||||||
|  |         parser = html_parser.HtmlParser() | ||||||
|  |         for imp in htmlImports: | ||||||
|  |             parsed = parser.guessDataFromHtmlTitle(imp.title) | ||||||
|  |             key = (parsed['group'], parsed['class_'], parsed['dance']) | ||||||
|  |             ret[key] = imp | ||||||
|  |         return ret | ||||||
|  | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user