def test_to_arrow_quick_fixes(self): fd, filename = tempfile.mkstemp() os.close(fd) # Remove the file. Then we'll test that ProcessResult.to_arrow() does # not write it (because the result is an error) os.unlink(filename) try: result = ProcessResult( error="bad, bad error", quick_fixes=[ QuickFix( "button foo", "prependModule", ["converttotext", {"colnames": ["A", "B"]}], ), QuickFix( "button bar", "prependModule", ["converttonumber", {"colnames": ["A", "B"]}], ), ], ).to_arrow(Path(filename)) self.assertEqual( result.errors, [ atypes.RenderError( atypes.I18nMessage.TODO_i18n("bad, bad error"), [ atypes.QuickFix( atypes.I18nMessage.TODO_i18n("button foo"), atypes.QuickFixAction.PrependStep( "converttotext", {"colnames": ["A", "B"]} ), ), atypes.QuickFix( atypes.I18nMessage.TODO_i18n("button bar"), atypes.QuickFixAction.PrependStep( "converttonumber", {"colnames": ["A", "B"]} ), ), ], ) ], ) with self.assertRaises(FileNotFoundError): open(filename) finally: try: os.unlink(filename) except FileNotFoundError: pass
def test_render_error_to_dict(self): self.assertEqual( fields._render_error_to_dict( types.RenderError( types.I18nMessage("err", {}), [ types.QuickFix( types.I18nMessage("click", {}, "cjwmodule"), types.QuickFixAction.PrependStep("filter", {"x": "y"}), ) ], ) ), { "message": {"id": "err", "arguments": {}}, "quickFixes": [ { "buttonText": { "id": "click", "arguments": {}, "source": "cjwmodule", }, "action": { "type": "prependStep", "moduleSlug": "filter", "partialParams": {"x": "y"}, }, } ], }, )
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_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_to_arrow(self): self.assertEqual( QuickFix( "button text", "prependModule", ["converttotext", {"colnames": ["A", "B"]}], ).to_arrow(), atypes.QuickFix( atypes.I18nMessage.TODO_i18n("button text"), atypes.QuickFixAction.PrependStep( "converttotext", {"colnames": ["A", "B"]} ), ), )
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_quick_fix_to_dict(self): self.assertEqual( types.QuickFix( types.I18nMessage("click"), types.QuickFixAction.PrependStep("filter", {"x": "y"}), ).to_dict(), { "buttonText": {"id": "click", "arguments": {}}, "action": { "type": "prependStep", "moduleSlug": "filter", "partialParams": {"x": "y"}, }, }, )