Пример #1
0
    def test_row2raw(self):
        # unsupported value_type - eval fails
        with pytest.raises(NameError):
            PatternCreator.row2raw(
                pd.Series(
                    {
                        "label": "et1",
                        "attribute_0": "TEXT",
                        "value_0": "aaa",
                        "value_type_0": "wrong_type",
                        "op_0": "",
                    }
                )
            )

        # already the first token is invalid
        with pytest.raises(ValueError):
            PatternCreator.row2raw(
                pd.Series(
                    {
                        "label": "et1",
                        "attribute_0": np.nan,
                        "value_0": "aaa",
                        "value_type_0": "wrong_type",
                        "op_0": "",
                    }
                )
            )

        res = PatternCreator.row2raw(
            pd.Series(
                {
                    "label": "et1",
                    "attribute_0": "TEXT",
                    "value_0": "aaa",
                    "value_type_0": "str",
                    "op_0": "",
                    "attribute_1": np.nan,
                    "value_1": "bbb",
                    "value_type_1": "int",
                    "op_1": "!",
                }
            )
        )

        assert res == {"label": "et1", "pattern": [{"TEXT": "aaa"}]}
Пример #2
0
 def test_raw2row2raw(self, raw):
     assert raw == PatternCreator.row2raw(PatternCreator.raw2row(raw))