Esempio n. 1
0
 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)
Esempio n. 2
0
 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)
Esempio n. 3
0
 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)
Esempio n. 4
0
 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"]}
                     ),
                 )
             ],
         ),
     )
Esempio n. 5
0
 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"]}
                         ),
                     ),
                 ],
             ),
         ],
     )