Ejemplo n.º 1
0
 def test_quick_fixes_convert_to_text(self):
     err = PromptingError([
         PromptingError.WrongColumnType(["A", "B"], None,
                                        frozenset({"text"}))
     ])
     result = err.as_render_errors()
     self.assertEqual(
         result,
         [
             RenderError(
                 I18nMessage(
                     "py.renderer.execute.types.PromptingError.WrongColumnType.as_error_message.shouldBeText",
                     {
                         "columns": 2,
                         "0": "A",
                         "1": "B"
                     },
                     None,
                 ),
                 [
                     QuickFix(
                         I18nMessage(
                             "py.renderer.execute.types.PromptingError.WrongColumnType.as_quick_fixes.shouldBeText",
                             {},
                             None,
                         ),
                         QuickFixAction.PrependStep(
                             "converttotext", {"colnames": ["A", "B"]}),
                     )
                 ],
             )
         ],
     )
Ejemplo n.º 2
0
    def test_quick_fixes(self):
        err = PromptingError([
            PromptingError.WrongColumnType(["A"], "text",
                                           frozenset({"number"})),
            PromptingError.WrongColumnType(["B", "C"], "datetime",
                                           frozenset({"number"})),
        ])
        quick_fixes_result = err.as_quick_fixes()
        self.assertEqual(
            quick_fixes_result,
            [
                QuickFix(
                    "Convert Text to Numbers",
                    "prependModule",
                    ["converttexttonumber", {
                        "colnames": ["A"]
                    }],
                ),
                QuickFix(
                    "Convert Dates & Times to Numbers",
                    "prependModule",
                    ["converttexttonumber", {
                        "colnames": ["B", "C"]
                    }],
                ),
            ],
        )

        error_result = err.as_error_str()
        self.assertEqual(
            error_result,
            ("The column “A” must be converted from Text to Numbers.\n\n"
             "The columns “B” and “C” must be converted from Dates & Times to Numbers."
             ),
        )
Ejemplo n.º 3
0
 def test_as_quick_fixes(self):
     err = PromptingError([
         PromptingError.WrongColumnType(["A"], "text",
                                        frozenset({"number"})),
         PromptingError.WrongColumnType(["B", "C"], "datetime",
                                        frozenset({"number"})),
     ])
     result = err.as_quick_fixes()
     self.assertEqual(
         result,
         [
             QuickFix(
                 'Convert "A" to Numbers',
                 "prependModule",
                 ["converttexttonumber", {
                     "colnames": ["A"]
                 }],
             ),
             QuickFix(
                 'Convert "B", "C" to Numbers',
                 "prependModule",
                 ["converttexttonumber", {
                     "colnames": ["B", "C"]
                 }],
             ),
         ],
     )
Ejemplo n.º 4
0
 def test_as_quick_fixes(self):
     err = PromptingError([
         PromptingError.WrongColumnType(['A'], 'text',
                                        frozenset({'number'})),
         PromptingError.WrongColumnType(['B', 'C'], 'datetime',
                                        frozenset({'number'})),
     ])
     result = err.as_quick_fixes()
     self.assertEqual(result, [
         QuickFix('Convert "A" to Numbers', 'prependModule',
                  ['converttexttonumber', {
                      'colnames': ['A']
                  }]),
         QuickFix('Convert "B", "C" to Numbers', 'prependModule',
                  ['converttexttonumber', {
                      'colnames': ['B', 'C']
                  }]),
     ])
Ejemplo n.º 5
0
def _(dtype: ParamDType.Column, value: str, input_shape: TableShape) -> str:
    if dtype.tab_parameter:
        raise RuntimeError("Unsupported: fetch column with tab_parameter")

    if input_shape is None:
        return ""

    valid_columns = {c.name: c for c in input_shape.columns}
    if value not in valid_columns:
        return ""  # Null column

    column = valid_columns[value]
    if dtype.column_types and column.type.name not in dtype.column_types:
        raise PromptingError([
            PromptingError.WrongColumnType([value], column.type.name,
                                           dtype.column_types)
        ])

    return value
Ejemplo n.º 6
0
    def test_quick_fixes_convert_to_text(self):
        err = PromptingError([
            PromptingError.WrongColumnType(["A", "B"], None,
                                           frozenset({"text"}))
        ])
        quick_fixes_result = err.as_quick_fixes()
        self.assertEqual(
            quick_fixes_result,
            [
                QuickFix(
                    I18nMessage.TODO_i18n("Convert to Text"),
                    QuickFixAction.PrependStep("converttotext",
                                               {"colnames": ["A", "B"]}),
                )
            ],
        )

        error_result = err.as_error_str()
        self.assertEqual(error_result,
                         "The columns “A” and “B” must be converted to Text.")
Ejemplo n.º 7
0
    def test_quick_fixes_convert_to_text(self):
        err = PromptingError([
            PromptingError.WrongColumnType(["A", "B"], None,
                                           frozenset({"text"}))
        ])
        quick_fixes_result = err.as_quick_fixes()
        self.assertEqual(
            quick_fixes_result,
            [
                QuickFix(
                    "Convert to Text",
                    "prependModule",
                    ["converttotext", {
                        "colnames": ["A", "B"]
                    }],
                )
            ],
        )

        error_result = err.as_error_str()
        self.assertEqual(error_result,
                         "The columns “A” and “B” must be converted to Text.")
Ejemplo n.º 8
0
def _(dtype: ParamDType.Column, value: str,
      input_metadata: TableMetadata) -> str:
    if dtype.tab_parameter:
        raise RuntimeError("Unsupported: fetch column with tab_parameter")

    if not input_metadata.columns:
        return ""

    valid_columns = {c.name: c for c in input_metadata.columns}
    if value not in valid_columns:
        return ""  # Null column

    column = valid_columns[value]
    if dtype.column_types and column.type.name not in dtype.column_types:
        if "text" in dtype.column_types:
            found_type = None
        else:
            found_type = column.type.name
        raise PromptingError([
            PromptingError.WrongColumnType([value], found_type,
                                           dtype.column_types)
        ])

    return value
Ejemplo n.º 9
0
 def test_quick_fixes(self):
     err = PromptingError([
         PromptingError.WrongColumnType(["A"], "text",
                                        frozenset({"number"})),
         PromptingError.WrongColumnType(["B", "C"], "timestamp",
                                        frozenset({"number"})),
     ])
     result = err.as_render_errors()
     self.assertEqual(
         result,
         [
             RenderError(
                 I18nMessage(
                     "py.renderer.execute.types.PromptingError.WrongColumnType.as_error_message.general",
                     {
                         "columns": 1,
                         "0": "A",
                         "found_type": "text",
                         "best_wanted_type": "number",
                     },
                     None,
                 ),
                 [
                     QuickFix(
                         I18nMessage(
                             "py.renderer.execute.types.PromptingError.WrongColumnType.as_quick_fixes.general",
                             {
                                 "found_type": "text",
                                 "best_wanted_type": "number"
                             },
                             None,
                         ),
                         QuickFixAction.PrependStep("converttexttonumber",
                                                    {"colnames": ["A"]}),
                     )
                 ],
             ),
             RenderError(
                 I18nMessage(
                     "py.renderer.execute.types.PromptingError.WrongColumnType.as_error_message.general",
                     {
                         "columns": 2,
                         "0": "B",
                         "1": "C",
                         "found_type": "timestamp",
                         "best_wanted_type": "number",
                     },
                     None,
                 ),
                 [
                     QuickFix(
                         I18nMessage(
                             "py.renderer.execute.types.PromptingError.WrongColumnType.as_quick_fixes.general",
                             {
                                 "found_type": "timestamp",
                                 "best_wanted_type": "number",
                             },
                             None,
                         ),
                         QuickFixAction.PrependStep(
                             "converttexttonumber",
                             {"colnames": ["B", "C"]}),
                     )
                 ],
             ),
         ],
     )