Ejemplo n.º 1
0
 def test_clean_condition_not(self):
     context = self._render_context(input_table=arrow_table({"A": ["a"]}))
     self.assertEqual(
         clean_value(
             ParamDType.Condition(),
             {
                 "operation": "text_is_not",
                 "column": "A",
                 "value": "a",
                 "isCaseSensitive": False,
                 "isRegex": False,
             },
             context,
         ),
         {
             "operation": "not",
             "condition": {
                 "operation": "text_is",
                 "column": "A",
                 "value": "a",
                 "isCaseSensitive": False,
                 "isRegex": False,
             },
         },
     )
Ejemplo n.º 2
0
    def test_clean_condition_timestamp_wrong_value(self):
        context = self._render_context(
            input_table=arrow_table(
                {"A": pa.array([datetime.now()], pa.timestamp("ns"))}
            )
        )
        with self.assertRaises(PromptingError) as cm:
            clean_value(
                ParamDType.Condition(),
                {
                    "operation": "timestamp_is_greater_than",
                    "column": "A",
                    "value": "Yesterday",
                    "isCaseSensitive": False,
                    "isRegex": False,
                },
                context,
            )

        self.assertEqual(
            cm.exception.errors,
            [
                PromptingError.CannotCoerceValueToTimestamp("Yesterday"),
            ],
        )
Ejemplo n.º 3
0
 def test_clean_condition_and_or_simplify(self):
     context = self._render_context(input_table=arrow_table({"A": [1]}))
     self.assertEqual(
         clean_value(
             ParamDType.Condition(),
             {
                 "operation": "and",
                 "conditions": [
                     {
                         "operation": "or",
                         "conditions": [
                             {
                                 "operation": "cell_is_blank",
                                 "column": "A",
                                 "value": "",
                                 "isCaseSensitive": False,
                                 "isRegex": False,
                             },
                         ],
                     },
                 ],
             },
             context,
         ),
         {
             "operation": "cell_is_blank",
             "column": "A",
         },
     )
Ejemplo n.º 4
0
 def test_clean_condition_empty_column_is_none(self):
     context = self._render_context(input_table=arrow_table({"A": [1]}))
     self.assertEqual(
         clean_value(
             ParamDType.Condition(),
             {
                 "operation": "text_is",
                 "column": "",
                 "value": "",
                 "isCaseSensitive": False,
                 "isRegex": False,
             },
             context,
         ),
         None,
     )
     # And test it in the context of a broader and/or
     self.assertEqual(
         clean_value(
             ParamDType.Condition(),
             {
                 "operation": "and",
                 "conditions": [
                     {
                         "operation": "or",
                         "conditions": [
                             {
                                 "operation": "text_is",
                                 "column": "",
                                 "value": "",
                                 "isCaseSensitive": False,
                                 "isRegex": False,
                             }
                         ],
                     }
                 ],
             },
             context,
         ),
         None,
     )
Ejemplo n.º 5
0
 def test_clean_condition_empty_and_and_or_are_none(self):
     context = self._render_context(input_table=arrow_table({"A": [1]}))
     self.assertEqual(
         clean_value(
             ParamDType.Condition(),
             {
                 "operation": "and",
                 "conditions": [{"operation": "or", "conditions": []}],
             },
             context,
         ),
         None,
     )
Ejemplo n.º 6
0
 def test_clean_condition_no_operation(self):
     context = self._render_context(input_table=arrow_table({"A": [1]}))
     self.assertEqual(
         clean_value(
             ParamDType.Condition(),
             {
                 "operation": "",
                 "column": "A",
                 "value": "foo",
                 "isCaseSensitive": False,
                 "isRegex": False,
             },
             context,
         ),
         None,
     )
Ejemplo n.º 7
0
    def test_clean_condition_number_wrong_value(self):
        context = self._render_context(input_table=arrow_table({"A": [1]}))
        with self.assertRaises(PromptingError) as cm:
            clean_value(
                ParamDType.Condition(),
                {
                    "operation": "number_is",
                    "column": "A",
                    "value": "bad",
                    "isCaseSensitive": False,
                    "isRegex": False,
                },
                context,
            )

        self.assertEqual(
            cm.exception.errors, [PromptingError.CannotCoerceValueToNumber("bad")]
        )
Ejemplo n.º 8
0
 def test_clean_condition_untyped(self):
     context = self._render_context(input_table=arrow_table({"A": [1]}))
     self.assertEqual(
         clean_value(
             ParamDType.Condition(),
             {
                 "operation": "cell_is_blank",
                 "column": "A",
                 "value": "2020-11-01",
                 "isCaseSensitive": True,
                 "isRegex": False,
             },
             context,
         ),
         {
             "operation": "cell_is_blank",
             "column": "A",
         },
     )
Ejemplo n.º 9
0
    def test_clean_condition_number_wrong_column_type(self):
        context = self._render_context(input_table=arrow_table({"A": ["a"]}))
        with self.assertRaises(PromptingError) as cm:
            clean_value(
                ParamDType.Condition(),
                {
                    "operation": "number_is",
                    "column": "A",
                    "value": "1",
                    "isCaseSensitive": False,
                    "isRegex": False,
                },
                context,
            )

        self.assertEqual(
            cm.exception.errors,
            [PromptingError.WrongColumnType(["A"], "text", frozenset({"number"}))],
        )
Ejemplo n.º 10
0
    def test_clean_condition_not_with_subclause_error(self):
        context = self._render_context(input_table=arrow_table({"A": [1]}))
        with self.assertRaises(PromptingError) as cm:
            clean_value(
                ParamDType.Condition(),
                {
                    "operation": "text_is",
                    "column": "A",
                    "value": "",
                    "isCaseSensitive": False,
                    "isRegex": False,
                },
                context,
            )

        self.assertEqual(
            cm.exception.errors,
            [PromptingError.WrongColumnType(["A"], None, frozenset({"text"}))],
        )
Ejemplo n.º 11
0
 def test_clean_condition_number_happy_path(self):
     context = self._render_context(input_table=arrow_table({"A": [1]}))
     self.assertEqual(
         clean_value(
             ParamDType.Condition(),
             {
                 "operation": "number_is",
                 "column": "A",
                 "value": "1",
                 "isCaseSensitive": False,
                 "isRegex": False,
             },
             context,
         ),
         {
             "operation": "number_is",
             "column": "A",
             "value": 1,
         },
     )
Ejemplo n.º 12
0
    def test_clean_condition_timestamp_wrong_column_type(self):
        context = self._render_context(input_table=arrow_table({"A": [1]}))
        with self.assertRaises(PromptingError) as cm:
            clean_value(
                ParamDType.Condition(),
                {
                    "operation": "timestamp_is_greater_than",
                    "column": "A",
                    "value": "2020-01-01T00:00Z",
                    "isCaseSensitive": False,
                    "isRegex": False,
                },
                context,
            )

        self.assertEqual(
            cm.exception.errors,
            [
                PromptingError.WrongColumnType(
                    ["A"], "number", frozenset({"timestamp"})
                ),
            ],
        )
Ejemplo n.º 13
0
 def test_clean_condition_timestamp_happy_path(self):
     context = self._render_context(
         input_table=arrow_table(
             {"A": pa.array([datetime.now()], pa.timestamp("ns"))}
         )
     )
     self.assertEqual(
         clean_value(
             ParamDType.Condition(),
             {
                 "operation": "timestamp_is_greater_than",
                 "column": "A",
                 "value": "2020-11-01",
                 "isCaseSensitive": False,
                 "isRegex": False,
             },
             context,
         ),
         {
             "operation": "timestamp_is_greater_than",
             "column": "A",
             "value": "2020-11-01",
         },
     )
Ejemplo n.º 14
0
 def dtype(self) -> Optional[ParamDType]:
     return ParamDType.Condition()