-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
484 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
dessert>=1.4,<2.0 | ||
rich>=10.0,<14.0 | ||
cabina>=0.7,<1.0 | ||
dessert>=1.4,<2.0 | ||
filelock>=3.5,<4.0 | ||
niltype>=0.3,<2.0 | ||
pyparsing>=3.0,<4.0 | ||
rich>=11.0,<14.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
from typing import Set | ||
|
||
import pytest | ||
from baby_steps import given, then, when | ||
from pytest import raises | ||
|
||
from vedro.plugins.tagger.logic_tag_matcher._logic_ops import And, Expr, Not, Operand, Operator, Or | ||
|
||
|
||
def test_tag_expr(): | ||
with when, raises(BaseException) as exc: | ||
Expr() | ||
|
||
with then: | ||
assert exc.type is TypeError | ||
|
||
|
||
def test_tag_operator(): | ||
with when, raises(BaseException) as exc: | ||
Operator() | ||
|
||
with then: | ||
assert exc.type is TypeError | ||
|
||
|
||
def test_tag_operand(): | ||
with when: | ||
operand = Operand("API") | ||
|
||
with then: | ||
assert isinstance(operand, Expr) | ||
assert repr(operand) == "Tag(API)" | ||
|
||
|
||
@pytest.mark.parametrize(("tags", "result"), [ | ||
({"API"}, True), | ||
({"P0"}, False), | ||
]) | ||
def test_tag_operand_expr(tags: Set[str], result: bool): | ||
with given: | ||
operand = Operand("API") | ||
|
||
with when: | ||
res = operand(tags) | ||
|
||
with then: | ||
assert res is result | ||
|
||
|
||
def test_not_operator(): | ||
with given: | ||
operand = Operand("API") | ||
|
||
with when: | ||
operator = Not(operand) | ||
|
||
with then: | ||
assert isinstance(operator, Expr) | ||
assert repr(operator) == "Not(Tag(API))" | ||
|
||
|
||
@pytest.mark.parametrize(("tags", "result"), [ | ||
({"API"}, False), | ||
({"P0"}, True), | ||
]) | ||
def test_not_operator_expr(tags: Set[str], result: bool): | ||
with given: | ||
operand = Operand("API") | ||
operator = Not(operand) | ||
|
||
with when: | ||
res = operator(tags) | ||
|
||
with then: | ||
assert res is result | ||
|
||
|
||
def test_and_operator(): | ||
with given: | ||
left_operand = Operand("API") | ||
right_operand = Operand("P0") | ||
|
||
with when: | ||
operator = And(left_operand, right_operand) | ||
|
||
with then: | ||
assert isinstance(operator, Expr) | ||
assert repr(operator) == "And(Tag(API), Tag(P0))" | ||
|
||
|
||
@pytest.mark.parametrize(("tags", "result"), [ | ||
({"API", "P0"}, True), | ||
({"P0"}, False), | ||
({"API"}, False), | ||
({"CLI"}, False), | ||
]) | ||
def test_and_operator_expr(tags: Set[str], result: bool): | ||
with given: | ||
left_operand = Operand("API") | ||
right_operand = Operand("P0") | ||
operator = And(left_operand, right_operand) | ||
|
||
with when: | ||
res = operator(tags) | ||
|
||
with then: | ||
assert res is result | ||
|
||
|
||
def test_or_operator(): | ||
with given: | ||
left_operand = Operand("API") | ||
right_operand = Operand("P0") | ||
|
||
with when: | ||
operator = Or(left_operand, right_operand) | ||
|
||
with then: | ||
assert isinstance(operator, Expr) | ||
assert repr(operator) == "Or(Tag(API), Tag(P0))" | ||
|
||
|
||
@pytest.mark.parametrize(("tags", "result"), [ | ||
({"API", "P0"}, True), | ||
({"P0"}, True), | ||
({"API"}, True), | ||
({"CLI"}, False), | ||
]) | ||
def test_or_operator_expr(tags: Set[str], result: bool): | ||
with given: | ||
left_operand = Operand("API") | ||
right_operand = Operand("P0") | ||
operator = Or(left_operand, right_operand) | ||
|
||
with when: | ||
res = operator(tags) | ||
|
||
with then: | ||
assert res is result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import pytest | ||
from baby_steps import given, then, when | ||
from pytest import raises | ||
|
||
from vedro.plugins.tagger.logic_tag_matcher import LogicTagMatcher | ||
|
||
|
||
def test_match(): | ||
with given: | ||
matcher = LogicTagMatcher("P0") | ||
|
||
with when: | ||
res = matcher.match({"P0"}) | ||
|
||
with then: | ||
assert res is True | ||
|
||
|
||
def test_not_match(): | ||
with given: | ||
matcher = LogicTagMatcher("P0") | ||
|
||
with when: | ||
res = matcher.match({"API"}) | ||
|
||
with then: | ||
assert res is False | ||
|
||
|
||
def test_invalid_expr(): | ||
with when, raises(ValueError) as exc: | ||
LogicTagMatcher("P0 and") | ||
|
||
with then: | ||
assert exc.type is ValueError | ||
|
||
|
||
@pytest.mark.parametrize("expr", [ | ||
"1TAG", | ||
"-TAG", | ||
"and", | ||
"or", | ||
"not", | ||
]) | ||
def test_invalid_tag(expr: str): | ||
with when, raises(ValueError) as exc: | ||
LogicTagMatcher(expr) | ||
|
||
with then: | ||
assert exc.type is ValueError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from baby_steps import then, when | ||
from pytest import raises | ||
|
||
from vedro.plugins.tagger import TagMatcher | ||
|
||
|
||
def test_tag_matcher(): | ||
with when, raises(BaseException) as exc: | ||
TagMatcher("expr") | ||
|
||
with then: | ||
assert exc.type is TypeError |
Oops, something went wrong.