-
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
10 changed files
with
98 additions
and
23 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from pathlib import Path | ||
|
||
from vedro import Scenario | ||
from vedro.core import VirtualScenario | ||
|
||
__all__ = ("make_vscenario",) | ||
|
||
|
||
def make_vscenario(path: str) -> VirtualScenario: | ||
class _Scenario(Scenario): | ||
__file__ = Path(path).absolute() | ||
|
||
return VirtualScenario(_Scenario, steps=[]) |
52 changes: 52 additions & 0 deletions
52
tests/core/scenario_orderer/test_plain_scenario_orderer.py
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,52 @@ | ||
import pytest | ||
from baby_steps import given, then, when | ||
|
||
from vedro.core.scenario_orderer import PlainScenarioOrderer | ||
|
||
from ._utils import make_vscenario | ||
|
||
|
||
@pytest.fixture() | ||
def orderer() -> PlainScenarioOrderer: | ||
return PlainScenarioOrderer() | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_sort_no_scenarios(*, orderer: PlainScenarioOrderer): | ||
with given: | ||
scenarios = [] | ||
|
||
with when: | ||
res = await orderer.sort(scenarios) | ||
|
||
with then: | ||
assert res == [] | ||
assert scenarios == [] | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_sort_scenarios(*, orderer: PlainScenarioOrderer): | ||
with given: | ||
orig_scenarios = {path: make_vscenario(path) for path in [ | ||
"scenarios/directory/scn.py", | ||
"scenarios/dir1/scn1.py", | ||
"scenarios/dir1/scn2.py", | ||
"scenarios/dir2/scn2.py", | ||
"scenarios/scn2.py", | ||
"scenarios/scn10.py", | ||
]} | ||
scenarios = list(orig_scenarios.values()) | ||
|
||
with when: | ||
res = await orderer.sort(scenarios) | ||
|
||
with then: | ||
assert res == [ | ||
orig_scenarios["scenarios/directory/scn.py"], | ||
orig_scenarios["scenarios/dir1/scn1.py"], | ||
orig_scenarios["scenarios/dir1/scn2.py"], | ||
orig_scenarios["scenarios/dir2/scn2.py"], | ||
orig_scenarios["scenarios/scn2.py"], | ||
orig_scenarios["scenarios/scn10.py"], | ||
] | ||
assert scenarios == list(orig_scenarios.values()) |
2 changes: 1 addition & 1 deletion
2
...s/orderer/test_stable_scenario_orderer.py → ...o_orderer/test_stable_scenario_orderer.py
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
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,4 +1,5 @@ | ||
from ._plain_scenario_orderer import PlainScenarioOrderer | ||
from ._scenario_orderer import ScenarioOrderer | ||
from ._stable_scenario_orderer import StableScenarioOrderer | ||
|
||
__all__ = ("ScenarioOrderer", "PlainScenarioOrderer",) | ||
__all__ = ("ScenarioOrderer", "PlainScenarioOrderer", "StableScenarioOrderer",) |
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,16 @@ | ||
from pathlib import Path | ||
from typing import Any, List, Tuple | ||
|
||
from .._virtual_scenario import VirtualScenario | ||
from ._scenario_orderer import ScenarioOrderer | ||
|
||
__all__ = ("StableScenarioOrderer",) | ||
|
||
|
||
class StableScenarioOrderer(ScenarioOrderer): | ||
def _cmp(self, scn: VirtualScenario) -> Tuple[Any, ...]: | ||
path = Path(scn.path) | ||
return (len(path.parts),) + tuple((len(x), x) for x in path.parts) | ||
|
||
async def sort(self, scenarios: List[VirtualScenario]) -> List[VirtualScenario]: | ||
return list(sorted(scenarios, key=self._cmp)) |
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
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,15 +1,4 @@ | ||
from pathlib import Path | ||
from typing import Any, List, Tuple | ||
|
||
from vedro.core import ScenarioOrderer, VirtualScenario | ||
# backward compatibility | ||
from vedro.core.scenario_orderer import StableScenarioOrderer | ||
|
||
__all__ = ("StableScenarioOrderer",) | ||
|
||
|
||
class StableScenarioOrderer(ScenarioOrderer): | ||
def _cmp(self, scn: VirtualScenario) -> Tuple[Any, ...]: | ||
path = Path(scn.path) | ||
return (len(path.parts),) + tuple((len(x), x) for x in path.parts) | ||
|
||
async def sort(self, scenarios: List[VirtualScenario]) -> List[VirtualScenario]: | ||
return list(sorted(scenarios, key=self._cmp)) |