def render(self, params: Dict[str, Any], fetch_result: Optional[FetchResult]): with tempfile_context(prefix="output-", suffix=".arrow") as output_path: errors = render(ArrowTable(), params, output_path, fetch_result=fetch_result) arrow_table = ArrowTable.from_arrow_file_with_inferred_metadata( output_path) yield RenderResult(arrow_table, [RenderError(I18nMessage(*e)) for e in errors])
def test_render_has_header_false(self): # TODO "no first row" should be a parse option. Fetch should store # raw data, and render should parse. result = render( pd.DataFrame(), P(has_header=False), fetch_result=ProcessResult(pd.DataFrame({ "A": [1], "B": [2] })), ) assert_process_result_equal( result, pd.DataFrame({ "0": ["A", "1"], "1": ["B", "2"] }))
def test_render_missing_fetch_result_returns_empty(self): result = render(pd.DataFrame(), P(), fetch_result=None) assert_process_result_equal(result, pd.DataFrame())
def test_render_ok(self): result = render(pd.DataFrame(), P(), fetch_result=ProcessResult(expected_table)) assert_process_result_equal(result, expected_table)
def test_render_fetch_warning(self): result = render(pd.DataFrame(), P(), fetch_result=ProcessResult(expected_table, "truncated")) assert_process_result_equal(result, (expected_table, "truncated"))
def test_render_fetch_error(self): result = render(pd.DataFrame(), P(), fetch_result=ProcessResult(error="please log in")) assert_process_result_equal(result, "please log in")
def test_render_no_file(self): result = render(pd.DataFrame(), P(), fetch_result=ProcessResult()) assert_process_result_equal(result, None)