Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tsv1 committed Sep 18, 2022
1 parent 46e296b commit 525bb43
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 47 deletions.
20 changes: 19 additions & 1 deletion tests/plugins/orderer/_utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import random
from argparse import Namespace
from contextlib import contextmanager
from pathlib import Path

import pytest

from vedro.core import ArgumentParser, ConfigType, Dispatcher
from vedro import Scenario
from vedro.core import ArgumentParser, ConfigType, Dispatcher, VirtualScenario
from vedro.events import ArgParsedEvent, ArgParseEvent, ConfigLoadedEvent
from vedro.plugins.orderer import Orderer, OrdererPlugin

Expand All @@ -20,6 +23,21 @@ def orderer(dispatcher: Dispatcher) -> OrdererPlugin:
return orderer


@contextmanager
def seeded(seed: str):
state = random.getstate()
random.seed(seed)
yield random.seed(seed)
random.setstate(state)


def make_vscenario(path: str) -> VirtualScenario:
class _Scenario(Scenario):
__file__ = Path(path).absolute()

return VirtualScenario(_Scenario, steps=[])


async def fire_config_loaded_event(dispatcher: Dispatcher, config: ConfigType) -> None:
config_loaded_event = ConfigLoadedEvent(Path(), config)
await dispatcher.fire(config_loaded_event)
Expand Down
25 changes: 3 additions & 22 deletions tests/plugins/orderer/test_random_scenario_orderer.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,16 @@
import random
from contextlib import contextmanager
from pathlib import Path

import pytest
from baby_steps import given, then, when

from vedro import Scenario
from vedro.core import VirtualScenario
from vedro.plugins.orderer import RandomOrderer

from ._utils import make_vscenario, seeded


@pytest.fixture()
def orderer():
def orderer() -> RandomOrderer:
return RandomOrderer()


@contextmanager
def seeded(seed: str):
state = random.getstate()
random.seed(seed)
yield
random.setstate(state)


def make_vscenario(path: str) -> VirtualScenario:
class _Scenario(Scenario):
__file__ = Path(path).absolute()

return VirtualScenario(_Scenario, steps=[])


@pytest.mark.asyncio
async def test_sort_no_scenarios(*, orderer: RandomOrderer):
with given:
Expand Down
15 changes: 3 additions & 12 deletions tests/plugins/orderer/test_reversed_scenario_orderer.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
from pathlib import Path

import pytest
from baby_steps import given, then, when

from vedro import Scenario
from vedro.core import VirtualScenario
from vedro.plugins.orderer import ReversedOrderer

from ._utils import make_vscenario


@pytest.fixture()
def orderer():
def orderer() -> ReversedOrderer:
return ReversedOrderer()


def make_vscenario(path: str) -> VirtualScenario:
class _Scenario(Scenario):
__file__ = Path(path).absolute()

return VirtualScenario(_Scenario, steps=[])


@pytest.mark.asyncio
async def test_sort_no_scenarios(*, orderer: ReversedOrderer):
with given:
Expand Down
15 changes: 3 additions & 12 deletions tests/plugins/orderer/test_stable_scenario_orderer.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
from pathlib import Path

import pytest
from baby_steps import given, then, when

from vedro import Scenario
from vedro.core import VirtualScenario
from vedro.plugins.orderer import StableScenarioOrderer

from ._utils import make_vscenario


@pytest.fixture()
def orderer():
def orderer() -> StableScenarioOrderer:
return StableScenarioOrderer()


def make_vscenario(path: str) -> VirtualScenario:
class _Scenario(Scenario):
__file__ = Path(path).absolute()

return VirtualScenario(_Scenario, steps=[])


@pytest.mark.asyncio
async def test_sort_no_scenarios(*, orderer: StableScenarioOrderer):
with given:
Expand Down

0 comments on commit 525bb43

Please sign in to comment.