def test_coerce_dict_quickfix_multiple(self): dataframe = pd.DataFrame({"A": [1, 2]}) result = ProcessResult.coerce({ "dataframe": dataframe, "errors": [ { "message": "an error", "quickFixes": [ dict( text="Hi", action="prependModule", args=["texttodate", { "column": "created_at" }], ), dict( text=("message.id", {}), action="prependModule", args=["texttodate", { "column": "created_at" }], ), ], }, "other error", ], "json": { "foo": "bar" }, }) expected = ProcessResult( dataframe, errors=[ RenderError( TODO_i18n("an error"), [ QuickFix( TODO_i18n("Hi"), QuickFixAction.PrependStep( "texttodate", {"column": "created_at"}), ), QuickFix( I18nMessage("message.id", {}, None), QuickFixAction.PrependStep( "texttodate", {"column": "created_at"}), ), ], ), RenderError(TODO_i18n("other error")), ], json={"foo": "bar"}, ) self.assertEqual(result, expected)
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_coerce_dict_legacy_with_quickfix_dict(self): dataframe = pd.DataFrame({"A": [1, 2]}) result = ProcessResult.coerce( { "dataframe": dataframe, "error": "an error", "json": {"foo": "bar"}, "quick_fixes": [ { "text": "Hi", "action": "prependModule", "args": ["texttodate", {"column": "created_at"}], } ], } ) expected = ProcessResult( dataframe, errors=[ RenderError( TODO_i18n("an error"), [ QuickFix( TODO_i18n("Hi"), QuickFixAction.PrependStep( "texttodate", {"column": "created_at"} ), ) ], ) ], json={"foo": "bar"}, ) self.assertEqual(result, expected)
def test_coerce_dict_i18n(self): expected = ProcessResult( errors=[ RenderError( TODO_i18n("an error"), [ QuickFix( I18nMessage("message.id", {}, None), QuickFixAction.PrependStep( "texttodate", {"column": "created_at"} ), ) ], ) ] ) result = ProcessResult.coerce( { "message": "an error", "quickFixes": [ dict( text=("message.id", {}), action="prependModule", args=["texttodate", {"column": "created_at"}], ) ], } ) self.assertEqual(result, expected)
def test_from_string_with_quick_fix(self): self.assertEqual( coerce_RenderError( { "message": "error", "quickFixes": [ dict( text="button text", action="prependModule", args=["converttotext", {"colnames": ["A", "B"]}], ) ], } ), RenderError( TODO_i18n("error"), [ QuickFix( TODO_i18n("button text"), QuickFixAction.PrependStep( "converttotext", {"colnames": ["A", "B"]} ), ) ], ), )
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_coerce_dict_with_quickfix_tuple(self): dataframe = pd.DataFrame({"A": [1, 2]}) quick_fix = QuickFix( "Hi", "prependModule", ["texttodate", {"column": "created_at"}] ) result = ProcessResult.coerce( { "dataframe": dataframe, "error": "an error", "json": {"foo": "bar"}, "quick_fixes": [ ("Hi", "prependModule", "texttodate", {"column": "created_at"}) ], } ) expected = ProcessResult( dataframe, "an error", json={"foo": "bar"}, quick_fixes=[quick_fix] ) self.assertEqual(result, expected)
def test_list_from_list_with_quick_fixes(self): self.assertEqual( coerce_RenderError_list( [ { "message": ("my id", {}), "quickFixes": [ dict( text="button text", action="prependModule", args=["converttotext", {"colnames": ["A", "B"]}], ) ], }, { "message": ("my other id", {"other": "this"}), "quickFixes": [ dict( text=("quick fix id", {"fix": "that"}), action="prependModule", args=["convert-date", {"colnames": ["C", "D"]}], ), dict( text=("another quick fix id", {"fix": "that"}), action="prependModule", args=["converttonumber", {"colnames": ["E", "F"]}], ), ], }, ] ), [ RenderError( I18nMessage("my id", {}, None), [ QuickFix( TODO_i18n("button text"), QuickFixAction.PrependStep( "converttotext", {"colnames": ["A", "B"]} ), ) ], ), RenderError( I18nMessage("my other id", {"other": "this"}, None), [ QuickFix( I18nMessage("quick fix id", {"fix": "that"}, None), QuickFixAction.PrependStep( "convert-date", {"colnames": ["C", "D"]} ), ), QuickFix( I18nMessage("another quick fix id", {"fix": "that"}, None), QuickFixAction.PrependStep( "converttonumber", {"colnames": ["E", "F"]} ), ), ], ), ], )