def test_truncate_not_too_big(self): df = DataFrame({'foo': ['foo', 'bar', 'baz']}) expected = ProcessResult(DataFrame(df)) # copy it result = ProcessResult(df) result.truncate_in_place_if_too_big() self.assertEqual(result, expected)
def _module_dispatch_render_static(dispatch, params, table, fetch_result): try: result = dispatch.render(params, table, fetch_result=fetch_result) except Exception as err: traceback.print_exc() result = ProcessResult(error=f'Internal error: {err}') result = ProcessResult.coerce(result) result.truncate_in_place_if_too_big() result.sanitize_in_place() return result
def test_truncate_too_big_no_error(self): expected_df = DataFrame({'foo': ['bar', 'baz']}) expected = ProcessResult(dataframe=expected_df, error='Truncated output from 3 rows to 2') with mock.patch('django.conf.settings.MAX_ROWS_PER_TABLE', 2): result_df = DataFrame({'foo': ['bar', 'baz', 'moo']}) result = ProcessResult(result_df, error='') result.truncate_in_place_if_too_big() self.assertEqual(result, expected)
def test_render_truncate_and_sanitize(self): calls = [] retval = ProcessResult(pd.DataFrame({'A': [1]})) retval.truncate_in_place_if_too_big = lambda: calls.append('truncate') retval.sanitize_in_place = lambda: calls.append('sanitize') lm = LoadedModule('int', '1', False, render_impl=lambda _a, _b: retval) with self.assertLogs(): lm.render(MockParams(), pd.DataFrame(), fetch_result=None) self.assertEqual(calls, ['truncate', 'sanitize'])