Example #1
0
    def test_parse(self):
        tokenized_query = ExperimentQueryManager.tokenize(self.query1)
        parsed_query = ExperimentQueryManager.parse(tokenized_query)
        assert parsed_query == {
            'updated_at':
            [QueryOpSpec(op='<=', negation=False, params='2020-10-10')],
            'started_at': [
                QueryOpSpec(op='>', negation=False, params='2010-10-10'),
                QueryOpSpec(op='=', negation=True, params='2016-10-01')
            ],
        }

        tokenized_query = ExperimentQueryManager.tokenize(self.query2)
        parsed_query = ExperimentQueryManager.parse(tokenized_query)
        assert parsed_query == {
            'metric__loss': [QueryOpSpec('<=', False, params=0.8)],
            'status':
            [QueryOpSpec('|', False, params=['starting', 'running'])],
        }

        tokenized_query = ExperimentQueryManager.tokenize(self.query3)
        parsed_query = ExperimentQueryManager.parse(tokenized_query)
        assert parsed_query == {
            'finished_at':
            [QueryOpSpec('..', False, params=['2012-12-12', '2042-12-12'])],
        }

        tokenized_query = ExperimentQueryManager.tokenize(self.query4)
        parsed_query = ExperimentQueryManager.parse(tokenized_query)
        assert parsed_query == {
            'tags': [
                QueryOpSpec('|', True, params=['tag1', 'tag2']),
                QueryOpSpec('=', False, params='tag3')
            ],
        }
Example #2
0
    def test_parse_datetime_operation(self):
        # Raises for not allowed operators
        with self.assertRaises(QueryParserException):
            parse_datetime_operation('foo|bar')

        with self.assertRaises(QueryParserException):
            parse_datetime_operation('')

        with self.assertRaises(QueryParserException):
            parse_datetime_operation('~')

        with self.assertRaises(QueryParserException):
            parse_datetime_operation('..')

        with self.assertRaises(QueryParserException):
            parse_datetime_operation('..da')

        with self.assertRaises(QueryParserException):
            parse_datetime_operation('asd..')

        with self.assertRaises(QueryParserException):
            parse_datetime_operation('asd..asd..asd')

        # Parses ranges
        assert parse_datetime_operation('foo..bar') == (QueryOpSpec(
            '..', False, ['foo', 'bar']))
        assert parse_datetime_operation(' foo .. bar ') == (QueryOpSpec(
            '..', False, ['foo', 'bar']))
        assert parse_datetime_operation('~ foo .. bar ') == (QueryOpSpec(
            '..', True, ['foo', 'bar']))

        # Comparison
        assert parse_datetime_operation('>=foo') == (QueryOpSpec(
            '>=', False, 'foo'))
        assert parse_datetime_operation(' ~ <= bar ') == (QueryOpSpec(
            '<=', True, 'bar'))
        assert parse_datetime_operation('~ > bar ') == (QueryOpSpec(
            '>', True, 'bar'))

        # Equality
        assert parse_datetime_operation('foo') == (QueryOpSpec(
            '=', False, 'foo'))
        assert parse_datetime_operation(' ~  bar ') == (QueryOpSpec(
            '=', True, 'bar'))
        assert parse_datetime_operation('~bar') == (QueryOpSpec(
            '=', True, 'bar'))
Example #3
0
    def test_parse_value_operation(self):
        # Raises for not allowed operators
        with self.assertRaises(QueryParserException):
            parse_value_operation('0.1..0.2')

        with self.assertRaises(QueryParserException):
            parse_datetime_operation('')

        with self.assertRaises(QueryParserException):
            parse_datetime_operation('~')

        # Raises for comparison
        with self.assertRaises(QueryParserException):
            parse_value_operation('>=f')

        with self.assertRaises(QueryParserException):
            parse_value_operation(' ~ <=f1 ')

        with self.assertRaises(QueryParserException):
            parse_value_operation('~|')

        with self.assertRaises(QueryParserException):
            parse_value_operation('|')

        with self.assertRaises(QueryParserException):
            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']))
Example #4
0
    def test_parse_scalar_operation(self):
        # Raises for not allowed operators
        with self.assertRaises(QueryParserException):
            parse_scalar_operation('1|12')

        with self.assertRaises(QueryParserException):
            parse_scalar_operation('0.1..0.2')

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

        with self.assertRaises(QueryParserException):
            parse_scalar_operation(' ~ <=f1 ')

        with self.assertRaises(QueryParserException):
            parse_scalar_operation('~ > bbb ')

        with self.assertRaises(QueryParserException):
            parse_datetime_operation('')

        with self.assertRaises(QueryParserException):
            parse_datetime_operation('~')

        with self.assertRaises(QueryParserException):
            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))