Ejemplo n.º 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')
            ],
        }
Ejemplo n.º 2
0
    def test_build(self):
        tokenized_query = ExperimentQueryManager.tokenize(self.query1)
        parsed_query = ExperimentQueryManager.parse(tokenized_query)
        built_query = ExperimentQueryManager.build(parsed_query)
        assert built_query == {
            'updated_at': [
                QueryCondSpec(DateTimeCondition(op='<=', negation=False),
                              params='2020-10-10')
            ],
            'started_at': [
                QueryCondSpec(DateTimeCondition(op='>', negation=False),
                              params='2010-10-10'),
                QueryCondSpec(DateTimeCondition(op='=', negation=True),
                              params='2016-10-01')
            ],
        }

        tokenized_query = ExperimentQueryManager.tokenize(self.query2)
        parsed_query = ExperimentQueryManager.parse(tokenized_query)
        built_query = ExperimentQueryManager.build(parsed_query)
        assert built_query == {
            'metric__loss': [
                QueryCondSpec(ComparisonCondition(op='<=', negation=False),
                              params=0.8)
            ],
            'status': [
                QueryCondSpec(ValueCondition(op='|', negation=False),
                              params=['starting', 'running'])
            ],
        }

        tokenized_query = ExperimentQueryManager.tokenize(self.query3)
        parsed_query = ExperimentQueryManager.parse(tokenized_query)
        built_query = ExperimentQueryManager.build(parsed_query)
        assert built_query == {
            'finished_at': [
                QueryCondSpec(DateTimeCondition(op='..', negation=False),
                              params=['2012-12-12', '2042-12-12'])
            ],
        }

        tokenized_query = ExperimentQueryManager.tokenize(self.query4)
        parsed_query = ExperimentQueryManager.parse(tokenized_query)
        built_query = ExperimentQueryManager.build(parsed_query)
        assert built_query == {
            'tags': [
                QueryCondSpec(ArrayCondition(op='|', negation=True),
                              params=['tag1', 'tag2']),
                QueryCondSpec(ArrayCondition(op='=', negation=False),
                              params='tag3')
            ],
        }
Ejemplo n.º 3
0
    def test_tokenize(self):
        tokenized_query = ExperimentQueryManager.tokenize(self.query1)
        assert dict(tokenized_query.items()) == {
            'updated_at': ['<=2020-10-10'],
            'started_at': ['>2010-10-10', '~2016-10-01'],
        }

        tokenized_query = ExperimentQueryManager.tokenize(self.query2)
        assert dict(tokenized_query) == {
            'metric.loss': ['<=0.8'],
            'status': ['starting|running'],
        }

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

        tokenized_query = ExperimentQueryManager.tokenize(self.query4)
        assert tokenized_query == {
            'tags': ['~tag1|tag2', 'tag3'],
        }

        tokenized_query = ExperimentQueryManager.tokenize(self.query5)
        assert tokenized_query == {'name': ['%foo%'], 'description': ['~bal%']}

        with self.assertRaises(QueryError):
            ExperimentQueryManager.tokenize(self.query6)
Ejemplo n.º 4
0
 def test_handle(self):
     tokenized_query = ExperimentQueryManager.tokenize(self.query1)
     parsed_query = ExperimentQueryManager.parse(tokenized_query)
     built_query = ExperimentQueryManager.build(parsed_query)
     assert built_query == ExperimentQueryManager.handle_query(self.query1)