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']))
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))
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'))