Exemple #1
0
def _html_table_processor() -> HTMLTableProcessor:
    root_url = 'https://127.0.0.1'
    headings_xpath = '{TABLE_XPATH}/thead//th[contains(@class, "rgHeader")]/descendant-or-self::*/text()'
    data_rows_xpath = '{TABLE_XPATH}/tbody//tr'
    data_cell_xpath = 'td/descendant-or-self::*/text()'
    table_class = 'rgMasterTable'
    return HTMLTableProcessor(root_url, headings_xpath, data_rows_xpath,
                              data_cell_xpath, table_class)
Exemple #2
0
    def test_get_table_html(self, html_table_processor: HTMLTableProcessor,
                            sample_html: str,
                            sample_processed_result: pd.DataFrame) -> None:
        actual_result = html_table_processor.get_tabular_data_from_html(
            sample_html,
            column_name_mapper=GenericColumnMapper().map_list,
            known_percentages=['Percentage']).reset_index(drop=True)

        pd.testing.assert_frame_equal(sample_processed_result, actual_result)
Exemple #3
0
    def test_get_table_element(self, html_table_processor: HTMLTableProcessor,
                               sample_html: str,
                               sample_processed_result: pd.DataFrame) -> None:
        html_dom = lxml.etree.HTML(sample_html)
        actual_result = html_table_processor.get_tabular_data_from_element(
            html_dom,
            column_name_mapper=GenericColumnMapper().map_list,
            known_percentages=['Percentage']).reset_index(drop=True)

        pd.testing.assert_frame_equal(sample_processed_result,
                                      actual_result,
                                      check_dtype=False)
Exemple #4
0
    def test_get_table_url(self, html_table_processor: HTMLTableProcessor,
                           sample_html: str,
                           sample_processed_result: pd.DataFrame,
                           response_get_monkeypatch: Callable) -> None:
        response_get_monkeypatch(sample_html)
        actual_result = html_table_processor.get_tabular_data_from_url(
            '/test',
            column_name_mapper=GenericColumnMapper().map_list,
            known_percentages=['Percentage']).reset_index(drop=True)

        pd.testing.assert_frame_equal(sample_processed_result,
                                      actual_result,
                                      check_dtype=False)