Exemplo n.º 1
0
	def test_find_group_end(self):
		p = Parser()

		for items, group_end_pos in (
			(['foo', '==', '1', ')'], 3),
			(['foo', '==', '1', ')', 'or', 'a', '==', '1'], 3),
			(['foo', '==', '1', ')', 'or', '(', 'foo', '==', '1', ')'], 3),
		):
			assert p.find_group_end(ConsumableIter(items)) == group_end_pos

		with pytest.raises(Exception):
			assert p.find_group_end(ConsumableIter(['foo', '==', 'bar'])) == group_end_pos

		with pytest.raises(Exception) as e:
			assert p.find_group_end(ConsumableIter(['(', 'foo', '==', 'bar'])) == group_end_pos
Exemplo n.º 2
0
	def test_get_condition_class(self):
		p = Parser()

		assert p._get_condition_class('==') == EqualsCondition
		assert p._get_condition_class('>') == GreaterThanCondition
		assert p._get_condition_class('<') == LessThanCondition
		assert p._get_condition_class('>=') == GreaterThanOrEqualCondition
		assert p._get_condition_class('<=') == LessThanOrEqualCondition

		for x in (None, 'foobar'):
			with pytest.raises(Exception) as e:
				p._get_condition_class(x)
				assert e
Exemplo n.º 3
0
	def test_get_operator_class(self):
		p = Parser()

		assert p._get_operator_class('and') == AndOperator
		assert p._get_operator_class('or') == OrOperator

		for x in (None, 'foobar'):
			with pytest.raises(Exception) as e:
				p._get_operator_class(x)
				assert e
Exemplo n.º 4
0
	def test_constructor(self):
		p = Parser()
		p = Parser('foo')
		p = Parser('foo', bar='baz')