This repository has been archived by the owner on Apr 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_clause.py
50 lines (40 loc) · 1.88 KB
/
test_clause.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import plume
from plume.plume import Clause
from utils import Pokemon
import pytest
class TestClause:
def test_allows_or_operator_between_two_clauses(self):
result = str((Pokemon.name == 'Charamander') | (Pokemon.name == 'Bulbasaur'))
expected = "( name = 'Charamander' OR name = 'Bulbasaur' )"
assert result == expected
def test_or_operator_between_two_clauses_add_brackets(self):
result = str((Pokemon.name == 'Charamander') | (Pokemon.name == 'Bulbasaur'))
expected_open_bracket = '('
expected_close_bracket = ')'
assert result[0] == expected_open_bracket
assert result[-1] == expected_close_bracket
def test_allows_and_operator_between_two_clauses(self):
result = str((Pokemon.name == 'Charamander') & (Pokemon.level == 18))
expected = "name = 'Charamander' AND level = 18"
assert result == expected
def test_and_operator_between_two_clauses_does_not_add_brackets(self):
result = str((Pokemon.name == 'Charamander') & (Pokemon.level == 18))
assert result[0] != '('
assert result[-1] != ')'
def test_or_operator_has_lower_precedence_than_and_operator(self):
result = str(
(Pokemon.name == 'Charamander') | (Pokemon.name == 'Bulbasaur')
& (Pokemon.level > 18)
)
expected = "( name = 'Charamander' OR name = 'Bulbasaur' AND level > 18 )"
assert result == expected
def test_bracket_has_higher_precedence_than_and_operator(self):
result = str(
((Pokemon.name == 'Charamander') | (Pokemon.name == 'Bulbasaur'))
& (Pokemon.level > 18)
)
expected = "level > 18 AND ( name = 'Charamander' OR name = 'Bulbasaur' )"
assert result == expected
def test_is_slotted(self):
with pytest.raises(AttributeError):
Clause().__dict__