Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add plugin command #43

Merged
merged 32 commits into from
May 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added tests/commands/__init__.py
Empty file.
Empty file.
Empty file.
19 changes: 19 additions & 0 deletions tests/commands/plugin_command/plugin_manager/_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from os import chdir, linesep
from pathlib import Path
from time import time
from typing import List, Optional

__all__ = ("create_config", "read_config")


def create_config(tmp_path: Path, config: Optional[List[str]] = None) -> Path:
chdir(tmp_path)
now = int(time() * 1000)
config_file = Path(f"vedro-cfg-{now}.py")
if config is not None:
config_file.write_text(linesep.join(config))
return config_file


def read_config(config_path: Path) -> str:
return config_path.read_text()
306 changes: 306 additions & 0 deletions tests/commands/plugin_command/plugin_manager/test_plugin_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,306 @@
import sys
from os import linesep
from pathlib import Path

import pytest
from baby_steps import given, then, when

from vedro.commands.plugin_command.plugin_manager import PluginManager

from ._utils import create_config, read_config


@pytest.mark.asyncio
@pytest.mark.skipif(sys.version_info < (3, 8), reason="requires python3.8 or higher")
async def test_plugin_manager_no_file(tmp_path: Path):
with given:
config_path = create_config(tmp_path)
plugin_manager = PluginManager(config_path)

with when:
await plugin_manager.enable("tagger")

with then:
config = read_config(config_path)
assert config == linesep.join([
"import vedro",
"import vedro.plugins.tagger",
"",
"",
"class Config(vedro.Config):",
"",
" class Plugins(vedro.Config.Plugins):",
"",
" class Tagger(vedro.plugins.tagger.Tagger):",
" enabled = True",
"",
])


@pytest.mark.asyncio
@pytest.mark.skipif(sys.version_info < (3, 8), reason="requires python3.8 or higher")
async def test_plugin_manager_no_config(tmp_path: Path):
with given:
config_path = create_config(tmp_path, [])
plugin_manager = PluginManager(config_path)

with when:
await plugin_manager.enable("tagger")

with then:
config = read_config(config_path)
assert config == linesep.join([
"import vedro",
"import vedro.plugins.tagger",
"",
"",
"class Config(vedro.Config):",
"",
" class Plugins(vedro.Config.Plugins):",
"",
" class Tagger(vedro.plugins.tagger.Tagger):",
" enabled = True",
"",
])


@pytest.mark.asyncio
@pytest.mark.skipif(sys.version_info < (3, 8), reason="requires python3.8 or higher")
async def test_plugin_manager_no_plugins_section(tmp_path: Path):
with given:
config_path = create_config(tmp_path, [
"import vedro",
"",
"",
"class Config(vedro.Config):",
" pass",
])
plugin_manager = PluginManager(config_path)

with when:
await plugin_manager.enable("tagger")

with then:
config = read_config(config_path)
assert config == linesep.join([
"import vedro.plugins.tagger",
"import vedro",
"",
"",
"class Config(vedro.Config):",
" pass",
"",
" class Plugins(vedro.Config.Plugins):",
"",
" class Tagger(vedro.plugins.tagger.Tagger):",
" enabled = True",
"",
])


@pytest.mark.asyncio
@pytest.mark.skipif(sys.version_info < (3, 8), reason="requires python3.8 or higher")
async def test_plugin_manager_no_plugins(tmp_path: Path):
with given:
config_path = create_config(tmp_path, [
"import vedro",
"",
"",
"class Config(vedro.Config):",
"",
" class Plugins(vedro.Config.Plugins):",
" pass",
])
plugin_manager = PluginManager(config_path)

with when:
await plugin_manager.enable("tagger")

with then:
config = read_config(config_path)
assert config == linesep.join([
"import vedro.plugins.tagger",
"import vedro",
"",
"",
"class Config(vedro.Config):",
"",
" class Plugins(vedro.Config.Plugins):",
" pass",
"",
" class Tagger(vedro.plugins.tagger.Tagger):",
" enabled = True",
"",
])


@pytest.mark.asyncio
@pytest.mark.skipif(sys.version_info < (3, 8), reason="requires python3.8 or higher")
async def test_plugin_manager_no_target_plugin(tmp_path: Path):
with given:
config_path = create_config(tmp_path, [
"import vedro",
"import vedro.plugins.skipper",
"import vedro.plugins.tagger",
"",
"",
"class Config(vedro.Config):",
"",
" class Plugins(vedro.Config.Plugins):",
"",
" class Skipper(vedro.plugins.skipper.Skipper):",
" enabled = True",
"",
])
plugin_manager = PluginManager(config_path)

with when:
await plugin_manager.enable("tagger")

with then:
config = read_config(config_path)
assert config == linesep.join([
"import vedro",
"import vedro.plugins.skipper",
"import vedro.plugins.tagger",
"",
"",
"class Config(vedro.Config):",
"",
" class Plugins(vedro.Config.Plugins):",
"",
" class Skipper(vedro.plugins.skipper.Skipper):",
" enabled = True",
"",
" class Tagger(vedro.plugins.tagger.Tagger):",
" enabled = True",
"",
])


@pytest.mark.asyncio
@pytest.mark.skipif(sys.version_info < (3, 8), reason="requires python3.8 or higher")
async def test_plugin_manager_no_enabled_attr(tmp_path: Path):
with given:
config_path = create_config(tmp_path, [
"import vedro",
"import vedro.plugins.skipper",
"import vedro.plugins.tagger",
"",
"",
"class Config(vedro.Config):",
"",
" class Plugins(vedro.Config.Plugins):",
"",
" class Tagger(vedro.plugins.tagger.Tagger):",
" description = 'desc'",
"",
" class Skipper(vedro.plugins.skipper.Skipper):",
" enabled = True",
"",
])
plugin_manager = PluginManager(config_path)

with when:
await plugin_manager.enable("tagger")

with then:
config = read_config(config_path)
assert config == linesep.join([
"import vedro",
"import vedro.plugins.skipper",
"import vedro.plugins.tagger",
"",
"",
"class Config(vedro.Config):",
"",
" class Plugins(vedro.Config.Plugins):",
"",
" class Tagger(vedro.plugins.tagger.Tagger):",
" description = 'desc'",
" enabled = True",
"",
" class Skipper(vedro.plugins.skipper.Skipper):",
" enabled = True",
"",
])


@pytest.mark.asyncio
@pytest.mark.skipif(sys.version_info < (3, 8), reason="requires python3.8 or higher")
@pytest.mark.parametrize("enabled", [True, False])
async def test_plugin_manager_enabled_enabled(enabled: bool, *, tmp_path: Path):
with given:
config_path = create_config(tmp_path, [
"import vedro",
"import vedro.plugins.tagger",
"",
"",
"class Config(vedro.Config):",
"",
" class Plugins(vedro.Config.Plugins):",
"",
" class Tagger(vedro.plugins.tagger.Tagger):",
f" enabled = {enabled}",
"",
])
plugin_manager = PluginManager(config_path)

with when:
await plugin_manager.enable("tagger")

with then:
config = read_config(config_path)
assert config == linesep.join([
"import vedro",
"import vedro.plugins.tagger",
"",
"",
"class Config(vedro.Config):",
"",
" class Plugins(vedro.Config.Plugins):",
"",
" class Tagger(vedro.plugins.tagger.Tagger):",
" enabled = True",
"",
])


@pytest.mark.asyncio
@pytest.mark.skipif(sys.version_info < (3, 8), reason="requires python3.8 or higher")
@pytest.mark.parametrize("enabled", [True, False])
async def test_plugin_manager_disabled_enabled(enabled: bool, *, tmp_path: Path):
with given:
config_path = create_config(tmp_path, [
"import vedro",
"import vedro.plugins.tagger",
"",
"",
"class Config(vedro.Config):",
"",
" class Plugins(vedro.Config.Plugins):",
"",
" class Tagger(vedro.plugins.tagger.Tagger):",
f" enabled = {enabled}",
"",
])
plugin_manager = PluginManager(config_path)

with when:
await plugin_manager.disable("tagger")

with then:
config = read_config(config_path)
assert config == linesep.join([
"import vedro",
"import vedro.plugins.tagger",
"",
"",
"class Config(vedro.Config):",
"",
" class Plugins(vedro.Config.Plugins):",
"",
" class Tagger(vedro.plugins.tagger.Tagger):",
" enabled = False",
"",
])
17 changes: 17 additions & 0 deletions tests/commands/plugin_command/test_plugin_command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from baby_steps import given, then, when

from vedro.commands import Command, CommandArgumentParser
from vedro.commands.plugin_command import PluginCommand
from vedro.core import Config


def test_plugin_command():
with given:
config = Config
arg_parser = CommandArgumentParser()

with when:
command = PluginCommand(config, arg_parser)

with then:
assert isinstance(command, Command)
Empty file.
22 changes: 22 additions & 0 deletions tests/commands/run_command/_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from os import chdir, linesep
from pathlib import Path

import pytest

__all__ = ("tmp_dir", "create_scenario",)


@pytest.fixture()
def tmp_dir(tmp_path: Path) -> Path:
chdir(tmp_path)
Path("./scenarios").mkdir(exist_ok=True)
yield tmp_path


def create_scenario(tmp_dir: Path, scenario_path: str) -> None:
scenario = linesep.join([
"import vedro",
"class Scenario(vedro.Scenario):",
" pass",
])
(tmp_dir / "scenarios" / scenario_path).write_text(scenario)
Loading