Beispiel #1
0
    def test_parse_value_operation(self):
        # Raises for not allowed operators
        with self.assertRaises(PQLException):
            parse_value_operation("0.1..0.2")

        with self.assertRaises(PQLException):
            parse_datetime_operation("")

        with self.assertRaises(PQLException):
            parse_datetime_operation("~")

        # Raises for comparison
        with self.assertRaises(PQLException):
            parse_value_operation(">=f")

        with self.assertRaises(PQLException):
            parse_value_operation(" ~ <=f1 ")

        with self.assertRaises(PQLException):
            parse_value_operation("~|")

        with self.assertRaises(PQLException):
            parse_value_operation("|")

        with self.assertRaises(PQLException):
            parse_value_operation("~tag1 |")

        # Equality
        assert parse_value_operation("tag") == (QueryOpSpec("=", False, "tag"))
        assert parse_value_operation(" ~  tag ") == (QueryOpSpec("=", True, "tag"))
        assert parse_value_operation("~tag") == (QueryOpSpec("=", True, "tag"))

        # In op
        assert parse_value_operation("tag1|tag2") == (
            QueryOpSpec("|", False, ["tag1", "tag2"])
        )
        assert parse_value_operation(" ~  tag1|tag2 ") == (
            QueryOpSpec("|", True, ["tag1", "tag2"])
        )
        assert parse_value_operation("~tag1 | tag2| tag23") == (
            QueryOpSpec("|", True, ["tag1", "tag2", "tag23"])
        )
Beispiel #2
0
    def test_parse_scalar_operation(self):
        # Raises for not allowed operators
        with self.assertRaises(PQLException):
            parse_scalar_operation("1|12")

        with self.assertRaises(PQLException):
            parse_scalar_operation("0.1..0.2")

        # Raise for not scalars
        with self.assertRaises(PQLException):
            parse_scalar_operation(">=f")

        with self.assertRaises(PQLException):
            parse_scalar_operation(" ~ <=f1 ")

        with self.assertRaises(PQLException):
            parse_scalar_operation("~ > bbb ")

        with self.assertRaises(PQLException):
            parse_datetime_operation("")

        with self.assertRaises(PQLException):
            parse_datetime_operation("~")

        with self.assertRaises(PQLException):
            parse_datetime_operation(">")

        # Comparison
        assert parse_scalar_operation(">=1") == (QueryOpSpec(">=", False, 1))
        assert parse_scalar_operation(" ~ <= 0.1 ") == (QueryOpSpec(
            "<=", True, 0.1))
        assert parse_scalar_operation("~ > 20 ") == (QueryOpSpec(
            ">", True, 20))

        # Equality
        assert parse_scalar_operation("1") == (QueryOpSpec("=", False, 1))
        assert parse_scalar_operation(" ~  2 ") == (QueryOpSpec("=", True, 2))
        assert parse_scalar_operation("~0.1") == (QueryOpSpec("=", True, 0.1))
Beispiel #3
0
    def test_parse_datetime_operation(self):
        # Raises for not allowed operators
        with self.assertRaises(PQLException):
            parse_datetime_operation("foo|bar")

        with self.assertRaises(PQLException):
            parse_datetime_operation("")

        with self.assertRaises(PQLException):
            parse_datetime_operation("~")

        with self.assertRaises(PQLException):
            parse_datetime_operation("..")

        with self.assertRaises(PQLException):
            parse_datetime_operation("..da")

        with self.assertRaises(PQLException):
            parse_datetime_operation("asd..")

        with self.assertRaises(PQLException):
            parse_datetime_operation("asd..asd..asd")

        # Parses ranges
        assert parse_datetime_operation("foo..bar") == (QueryOpSpec(
            "..", False, ["foo", "bar"]))
        assert parse_datetime_operation(
            "2016-10-01 10:10..2016-10-01 10:10:00") == (QueryOpSpec(
                "..", False, ["2016-10-01 10:10", "2016-10-01 10:10:00"]))
        assert parse_datetime_operation(" foo .. bar ") == (QueryOpSpec(
            "..", False, ["foo", "bar"]))
        assert parse_datetime_operation(
            " 2016-10-00 .. 2016-10-01 10:10:00 ") == (QueryOpSpec(
                "..", False, ["2016-10-00", "2016-10-01 10:10:00"]))
        assert parse_datetime_operation("~ foo .. bar ") == (QueryOpSpec(
            "..", True, ["foo", "bar"]))
        assert parse_datetime_operation(
            "~ 2016-10-00 .. 2016-10-01 10:10:00 ") == (QueryOpSpec(
                "..", True, ["2016-10-00", "2016-10-01 10:10:00"]))

        # Comparison
        assert parse_datetime_operation(">=foo") == (QueryOpSpec(
            ">=", False, "foo"))
        assert parse_datetime_operation(">=2016-10-01 10:10") == (QueryOpSpec(
            ">=", False, "2016-10-01 10:10"))
        assert parse_datetime_operation(" ~ <= bar ") == (QueryOpSpec(
            "<=", True, "bar"))
        assert parse_datetime_operation(" ~ <= 2016-10-01 10:10 ") == (
            QueryOpSpec("<=", True, "2016-10-01 10:10"))
        assert parse_datetime_operation("~ > bar ") == (QueryOpSpec(
            ">", True, "bar"))
        assert parse_datetime_operation("~ > 2016-10-01 10:10:00 ") == (
            QueryOpSpec(">", True, "2016-10-01 10:10:00"))

        # Equality
        assert parse_datetime_operation("foo") == (QueryOpSpec(
            "=", False, "foo"))
        assert parse_datetime_operation("2016-10-01 10:10") == (QueryOpSpec(
            "=", False, "2016-10-01 10:10"))
        assert parse_datetime_operation(" ~  bar ") == (QueryOpSpec(
            "=", True, "bar"))
        assert parse_datetime_operation(" ~ 2016-10-01 10:10:00") == (
            QueryOpSpec("=", True, "2016-10-01 10:10:00"))
        assert parse_datetime_operation("~bar") == (QueryOpSpec(
            "=", True, "bar"))
        assert parse_datetime_operation("~2016-10-01 10:10") == (QueryOpSpec(
            "=", True, "2016-10-01 10:10"))