def test_render_error_to_thrift(self): self.assertEqual( types.RenderError( types.I18nMessage("foo", {}), [ types.QuickFix( types.I18nMessage("click"), types.QuickFixAction.PrependStep("filter", {"x": "y"}), ) ], ).to_thrift(), ttypes.RenderError( ttypes.I18nMessage("foo", {}, ttypes.I18nMessageSource()), [ ttypes.QuickFix( ttypes.I18nMessage("click", {}, ttypes.I18nMessageSource()), ttypes.QuickFixAction( prepend_step=ttypes.PrependStepQuickFixAction( "filter", ttypes.RawParams('{"x":"y"}') ) ), ) ], ), )
def test_render_error_to_thrift(self): self.assertEqual( types.arrow_render_error_to_thrift( types.RenderError( I18nMessage("foo", {}, None), [ types.QuickFix( I18nMessage("click", {}, None), types.QuickFixAction.PrependStep( "filter", {"x": "y"}), ) ], )), ttypes.RenderError( ttypes.I18nMessage("foo", {}, None), [ ttypes.QuickFix( ttypes.I18nMessage("click", {}, None), ttypes.QuickFixAction( prepend_step=ttypes.PrependStepQuickFixAction( "filter", {"x": ttypes.Json( string_value="y")})), ) ], ), )
def test_fetch_result_from_thrift_happy_path(self): with tempfile.NamedTemporaryFile(dir=str(self.basedir)) as tf: self.assertEqual( types.thrift_fetch_result_to_arrow( ttypes.FetchResult( Path(tf.name).name, [ttypes.RenderError(ttypes.I18nMessage("hi", {}), [])], ), self.basedir, ), types.FetchResult(Path( tf.name), [types.RenderError(types.I18nMessage("hi"))]), )
def test_quick_fix_to_thrift(self): self.assertEqual( types.QuickFix( types.I18nMessage("click"), types.QuickFixAction.PrependStep("filter", {"x": "y"}), ).to_thrift(), ttypes.QuickFix( ttypes.I18nMessage("click", {}), ttypes.QuickFixAction( prepend_step=ttypes.PrependStepQuickFixAction( "filter", ttypes.RawParams('{"x":"y"}'))), ), )
def test_quick_fix_from_thrift(self): self.assertEqual( types.thrift_quick_fix_to_arrow( ttypes.QuickFix( ttypes.I18nMessage("click", {}, None), ttypes.QuickFixAction( prepend_step=ttypes.PrependStepQuickFixAction( "filter", {"x": ttypes.Json(string_value="y")})), )), types.QuickFix( I18nMessage("click", {}, None), types.QuickFixAction.PrependStep("filter", {"x": "y"}), ), )
def test_i18n_message_to_thrift_source_none(self): self.assertEqual( types.I18nMessage( "modules.x.y", {"a": "s", "b": 12345678, "c": 0.123} ).to_thrift(), ttypes.I18nMessage( "modules.x.y", { "a": ttypes.I18nArgument(string_value="s"), "b": ttypes.I18nArgument(i32_value=12345678), "c": ttypes.I18nArgument(double_value=0.123), }, ttypes.I18nMessageSource(), ), )
def test_i18n_message_from_thrift_source_none(self): self.assertEqual( types.thrift_i18n_message_to_arrow( ttypes.I18nMessage( "modules.x.y", { "a": ttypes.I18nArgument(string_value="s"), "b": ttypes.I18nArgument(i32_value=12345678), "c": ttypes.I18nArgument(double_value=0.123), }, None, ) ), I18nMessage("modules.x.y", {"a": "s", "b": 12345678, "c": 0.123}, None), )
def test_i18n_message_to_thrift_source_library(self): self.assertEqual( types.arrow_i18n_message_to_thrift( I18nMessage( "modules.x.y", {"a": "s", "b": 12345678, "c": 0.123}, "cjwmodule" ) ), ttypes.I18nMessage( "modules.x.y", { "a": ttypes.I18nArgument(string_value="s"), "b": ttypes.I18nArgument(i32_value=12345678), "c": ttypes.I18nArgument(double_value=0.123), }, "cjwmodule", ), )
def test_i18n_message_from_thrift(self): self.assertEqual( types.I18nMessage.from_thrift( ttypes.I18nMessage( "modules.x.y", { "a": ttypes.I18nArgument(string_value="s"), "b": ttypes.I18nArgument(i32_value=12345678), "c": ttypes.I18nArgument(double_value=0.123), }, )), types.I18nMessage("modules.x.y", { "a": "s", "b": 12345678, "c": 0.123 }), )
def test_default_render_returns_fetch_result(self): # Functionality used by libraryofcongress with ExitStack() as ctx: input_arrow_table = ctx.enter_context( arrow_table_context({"A": [1]}, dir=self.basedir) ) parquet_filename = Path( ctx.enter_context(parquet_file({"A": [2]}, dir=self.basedir)).name ).name out_filename = ctx.enter_context(tempfile_context(dir=self.basedir)).name thrift_result = module.render_thrift( ttypes.RenderRequest( str(self.basedir), arrow_arrow_table_to_thrift(input_arrow_table), {}, # params ttypes.Tab("tab-1", "Tab 1"), ttypes.FetchResult( parquet_filename, [ ttypes.RenderError( ttypes.I18nMessage( "TODO_i18n", { "text": ttypes.I18nArgument( string_value="A warning" ) }, ), [], ) ], ), out_filename, ) ) result = thrift_render_result_to_arrow(thrift_result, self.basedir) assert_render_result_equals( result, RenderResult( arrow_table({"A": [2]}), [RenderError(I18nMessage.TODO_i18n("A warning"))], ), )
def test_i18n_message_from_thrift_invalid_source(self): with self.assertRaises(ValueError): types.thrift_i18n_message_to_arrow( ttypes.I18nMessage("modules.x.y", {}, "random"))
def test_i18n_message_to_thrift_source_none(self): self.assertEqual( types.arrow_i18n_message_to_thrift( types.I18nMessage("modules.x.y")), ttypes.I18nMessage("modules.x.y", {}, None), )