Skip to content

Commit

Permalink
Merge pull request #1 from vedro-universe/update-libs
Browse files Browse the repository at this point in the history
update libs
  • Loading branch information
tsv1 authored Jul 23, 2023
2 parents f094079 + 527c4b3 commit 6705778
Show file tree
Hide file tree
Showing 10 changed files with 271 additions and 31 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ name: Publish
on:
push:
tags:
- 'v*.*.*'
- "v*.*.*"

jobs:
publish:
publish_pypi:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: "3.10"
- name: Build
run: make build
- name: Publish
Expand Down
13 changes: 10 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@ name: Test
on:
push:
branches:
- "*"
- "master"
paths-ignore:
- "**.md"
pull_request:
branches:
- "**"
paths-ignore:
- "**.md"
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10']
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
Expand Down
74 changes: 72 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,33 @@

## Installation

### 1. Install package
<details open>
<summary>Quick</summary>
<p>

For a quick installation, you can use a plugin manager as follows:

```shell
$ vedro plugin install vedro-advanced-tags
$ vedro plugin disable vedro.plugins.tagger
```

</p>
</details>

<details>
<summary>Manual</summary>
<p>

To install manually, follow these steps:

1. Install the package using pip:

```shell
$ pip3 install vedro-advanced-tags
```

### 2. Enable plugin
2. Next, activate the plugin in your `vedro.cfg.py` configuration file:

```python
# ./vedro.cfg.py
Expand All @@ -30,5 +50,55 @@ class Config(vedro.Config):

class VedroAdvancedTags(adv_tagger.VedroAdvancedTags):
enabled = True
```

</p>
</details>

## Usage

First, add tags to your scenarios:

```python
import vedro

class Scenario(vedro.Scenario):
subject = "register user"
tags = ["P0", "API"]
```

Then, you can run scenarios with specific tags.

#### AND

To run scenarios that include both specified tags, use the **and** operator:

```shell
$ vedro run --tags "P0 and API"
```

#### OR

To run scenarios that contain either of the specified tags, use the **or** operator:

```shell
$ vedro run --tags "API or CLI"
```

#### NOT

To run scenarios that do not include a specific tag, use the **not** operator:

```shell
$ vedro run --tags "not P0"
```

#### EXPR

To run scenarios that meet multiple conditions, use expressions.

For instance, to execute scenarios that either include the `API` or `CLI` tag, and do not include the `P0` tag, you can use:

```shell
$ vedro run --tags "(API or CLI) and (not P0)"
```
16 changes: 8 additions & 8 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
baby-steps==1.2.3
baby-steps==1.3.0
bump2version==1.0.1
codecov==2.1.12
coverage==7.0.1
codecov==2.1.13
coverage==7.2.7
flake8==6.0.0
isort==5.11.4
mypy==0.991
pytest==7.2.0
pytest-asyncio==0.20.3
pytest-cov==4.0.0
isort==5.12.0
mypy==1.4.1
pytest==7.4.0
pytest-asyncio==0.21.1
pytest-cov==4.1.0
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def find_dev_required():
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
author="Nikita Tsvetkov",
author_email="nikitanovosibirsk@yandex.com",
author_email="tsv1@fastmail.com",
python_requires=">=3.8",
url="https://github.com/vedro-universe/vedro-advanced-tags",
license="Apache-2.0",
Expand All @@ -31,6 +31,7 @@ def find_dev_required():
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Typing :: Typed",
],
)
16 changes: 14 additions & 2 deletions tests/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@

import pytest
from vedro import Scenario
from vedro.core import Dispatcher, VirtualScenario
from vedro.events import ArgParsedEvent, ArgParseEvent
from vedro.core import Dispatcher
from vedro.core import MonotonicScenarioScheduler as Scheduler
from vedro.core import VirtualScenario
from vedro.events import ArgParsedEvent, ArgParseEvent, StartupEvent

from vedro_advanced_tags import VedroAdvancedTags, VedroAdvancedTagsPlugin
from vedro_advanced_tags._grammar import ParseResults, TagOperand


@pytest.fixture()
Expand Down Expand Up @@ -43,3 +46,12 @@ async def fire_arg_parsed_event(dispatcher: Dispatcher, *, tags: Optional[str] =

arg_parsed_event = ArgParsedEvent(Namespace(tags=tags))
await dispatcher.fire(arg_parsed_event)


async def fire_startup_event(dispatcher: Dispatcher, scheduler: Scheduler) -> None:
startup_event = StartupEvent(scheduler)
await dispatcher.fire(startup_event)


def make_tag(name: str) -> TagOperand:
return TagOperand("...", 0, ParseResults([name]))
80 changes: 78 additions & 2 deletions tests/test_advanded_tags.py → tests/test_advanced_tags.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import pytest
from baby_steps import given, then, when
from pytest import raises
from vedro.core import Dispatcher
from vedro.core import MonotonicScenarioScheduler as Scheduler
from vedro.events import StartupEvent
from vedro.core import Report
from vedro.events import CleanupEvent, StartupEvent

from ._utils import dispatcher, fire_arg_parsed_event, make_vscenario, tagger
from ._utils import dispatcher, fire_arg_parsed_event, fire_startup_event, make_vscenario, tagger

__all__ = ("dispatcher", "tagger") # fixtures

Expand Down Expand Up @@ -160,3 +162,77 @@ async def test_tags_skipped(*, dispatcher: Dispatcher):

with then:
assert list(scheduler.scheduled) == [scenarios[0]]


@pytest.mark.usefixtures(tagger.__name__)
async def test_tags_type_validation(*, dispatcher: Dispatcher):
with given:
await fire_arg_parsed_event(dispatcher, tags="SMOKE")

scenario = make_vscenario(tags={"SMOKE": "SMOKE"}) # type: ignore
scheduler = Scheduler([scenario])

startup_event = StartupEvent(scheduler)

with when, raises(BaseException) as exc:
await dispatcher.fire(startup_event)

with then:
assert exc.type is TypeError
assert str(exc.value) == (
f"Scenario '{scenario.rel_path}' tags must be a list, tuple or set, got <class 'dict'>"
)


@pytest.mark.usefixtures(tagger.__name__)
async def test_tags_value_validation(*, dispatcher: Dispatcher):
with given:
await fire_arg_parsed_event(dispatcher, tags="SMOKE")

scenario = make_vscenario(tags=["-SMOKE"])
scheduler = Scheduler([scenario])

startup_event = StartupEvent(scheduler)

with when, raises(BaseException) as exc:
await dispatcher.fire(startup_event)

with then:
assert exc.type is ValueError
assert str(exc.value) == (
f"Scenario '{scenario.rel_path}' tag '-SMOKE' is not a valid identifier"
)


@pytest.mark.usefixtures(tagger.__name__)
async def test_tags_show_parsed_disabled(*, dispatcher: Dispatcher):
with given:
await fire_arg_parsed_event(dispatcher, tags="API or CLI")
await fire_startup_event(dispatcher, Scheduler([]))

report = Report()
cleanup_event = CleanupEvent(report)

with when:
await dispatcher.fire(cleanup_event)

with then:
assert report.summary == []


async def test_tags_show_parsed_enabled(*, tagger, dispatcher: Dispatcher):
with given:
tagger._show_parsed = True
await fire_arg_parsed_event(dispatcher, tags="API or CLI")
await fire_startup_event(dispatcher, Scheduler([]))

report = Report()
cleanup_event = CleanupEvent(report)

with when:
await dispatcher.fire(cleanup_event)

with then:
assert report.summary == [
'--tags "API or CLI" -> OR(Tag(API), Tag(CLI))'
]
60 changes: 60 additions & 0 deletions tests/test_grammar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from baby_steps import given, then, when
from pyparsing import ParseResults

from vedro_advanced_tags._grammar import AndTag, NotTag, OrTag, TagExpr, TagOperand

from ._utils import make_tag


def test_tag_operand():
with given:
tokens = ParseResults(["API"])

with when:
tag_operand = TagOperand("...", 0, tokens)

with then:
assert isinstance(tag_operand, TagExpr)
assert repr(tag_operand) == "Tag(API)"


def test_and_operator():
with given:
tokens = ParseResults([
[make_tag("API"), "and", make_tag("P0")]
])

with when:
and_operator = AndTag("...", 0, tokens)

with then:
assert isinstance(and_operator, TagExpr)
assert repr(and_operator) == "AND(Tag(API), Tag(P0))"


def test_or_operator():
with given:
tokens = ParseResults([
[make_tag("API"), "or", make_tag("P0")]
])

with when:
or_operator = OrTag("...", 0, tokens)

with then:
assert isinstance(or_operator, TagExpr)
assert repr(or_operator) == "OR(Tag(API), Tag(P0))"


def test_not_operator():
with given:
tokens = ParseResults([
["not", make_tag("API")]
])

with when:
not_operator = NotTag("...", 0, tokens)

with then:
assert isinstance(not_operator, TagExpr)
assert repr(not_operator) == "NOT(Tag(API))"
4 changes: 2 additions & 2 deletions vedro_advanced_tags/_tag_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from ._grammar import TagsType, parse

__all__ = ("AdvancdedTagMatcher", "TagMatcher",)
__all__ = ("AdvancedTagMatcher", "TagMatcher",)


class TagMatcher(ABC):
Expand All @@ -14,7 +14,7 @@ def match(self, tags: TagsType) -> bool:
pass


class AdvancdedTagMatcher(TagMatcher):
class AdvancedTagMatcher(TagMatcher):
def __init__(self, expr: str) -> None:
super().__init__(expr)
self._grammar = parse(expr)
Expand Down
Loading

0 comments on commit 6705778

Please sign in to comment.