Skip to content

Commit

Permalink
Merge pull request #323 from MichalKacprzak99/michalkacprzak99-logica…
Browse files Browse the repository at this point in the history
…l-operators-formulas

Add formulas for missing logical operators
  • Loading branch information
mesozoic committed Dec 16, 2023
2 parents e62a24e + 65d579c commit 54ef64f
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
50 changes: 50 additions & 0 deletions pyairtable/formulas.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,53 @@ def LOWER(value: str) -> str:
"LOWER(TestValue)"
"""
return "LOWER({})".format(value)


def NOT_EQUAL(left: Any, right: Any) -> str:
"""
Create an inequality assertion
>>> NOT_EQUAL(2,2)
'2!=2'
"""
return "{}!={}".format(left, right)


def LESS_EQUAL(left: Any, right: Any) -> str:
"""
Create a less than assertion
>>> LESS_EQUAL(2,2)
'2<=2'
"""
return "{}<={}".format(left, right)


def GREATER_EQUAL(left: Any, right: Any) -> str:
"""
Create a greater than assertion
>>> GREATER_EQUAL(2,2)
'2>=2'
"""
return "{}>={}".format(left, right)


def LESS(left: Any, right: Any) -> str:
"""
Create a less assertion
>>> LESS(2,2)
'2<2'
"""
return "{}<{}".format(left, right)


def GREATER(left: Any, right: Any) -> str:
"""
Create a greater assertion
>>> GREATER(2,2)
'2>2'
"""
return "{}>{}".format(left, right)
25 changes: 25 additions & 0 deletions tests/test_formulas.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
EQUAL,
FIELD,
FIND,
GREATER,
GREATER_EQUAL,
IF,
LESS,
LESS_EQUAL,
LOWER,
NOT_EQUAL,
OR,
STR_VALUE,
escape_quotes,
Expand Down Expand Up @@ -86,3 +91,23 @@ def test_escape_quotes(text, escaped):

def test_lower():
assert LOWER("TestValue") == "LOWER(TestValue)"


def test_greater_equal():
assert GREATER_EQUAL("A", "B") == "A>=B"


def test_less_equal():
assert LESS_EQUAL("A", "B") == "A<=B"


def test_greater():
assert GREATER("A", "B") == "A>B"


def test_less():
assert LESS("A", "B") == "A<B"


def test_not_equal():
assert NOT_EQUAL("A", "B") == "A!=B"

0 comments on commit 54ef64f

Please sign in to comment.