Skip to content

Commit

Permalink
[lektor-613] Now using the isolated_cli_runner to manage the cwd. Fix…
Browse files Browse the repository at this point in the history
…es cwd the plugins tests end with, fixing broken subsequent tests.
  • Loading branch information
nixjdm committed May 12, 2019
1 parent d428092 commit f6a00db
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions tests/test_plugins.py
@@ -1,5 +1,6 @@
import textwrap
import os
import shutil

import pytest

Expand Down Expand Up @@ -31,10 +32,10 @@


@pytest.fixture(scope="function")
def scratch_project_with_plugin(scratch_project_data, request):
def scratch_project_with_plugin(scratch_project_data, request, isolated_cli_runner):
"""Create a scratch project and add a plugin that has the named event listener.
Return project and current event.
Return (project, current event, and attached cli_runner).
"""
base = scratch_project_data

Expand Down Expand Up @@ -87,19 +88,26 @@ def on_{}(self, **extra):
)
base.join("templates", "page.html").write_text(template_text, "utf8", ensure=True)

# Move into isolated path.
for entry in os.listdir(base):
entry_path = os.path.join(base, entry)
if os.path.isdir(entry_path):
shutil.copytree(entry_path, entry)
else:
shutil.copy2(entry_path, entry)

from lektor.project import Project

yield (Project.from_path(str(base)), request.param)
yield (Project.from_path(str(base)), request.param, isolated_cli_runner)


@pytest.mark.parametrize("scratch_project_with_plugin", build_events, indirect=True)
def test_plugin_build_events_via_cli(scratch_project_with_plugin, isolated_cli_runner):
def test_plugin_build_events_via_cli(scratch_project_with_plugin):
"""Test whether a plugin with a given event can successfully use an extra flag.
"""
proj, event = scratch_project_with_plugin
os.chdir(proj.tree)
proj, event, cli_runner = scratch_project_with_plugin

result = isolated_cli_runner.invoke(cli, ["build", "-f", "EXTRA"])
result = cli_runner.invoke(cli, ["build", "-f", "EXTRA"])
assert result.exit_code == 0

# Test that the event was triggered and the current extra flag was passed.
Expand All @@ -123,17 +131,14 @@ def test_plugin_build_events_via_cli(scratch_project_with_plugin, isolated_cli_r

assert len(hits) != 0

result = isolated_cli_runner.invoke(cli, ["clean", "--yes"])


@pytest.mark.parametrize("scratch_project_with_plugin", all_events, indirect=True)
def test_env_extra_flag_passthrough(scratch_project_with_plugin):
"""Test whether setting extra_flags passes through to each plugin event.
"""
from lektor.environment import Environment

proj, event = scratch_project_with_plugin
os.chdir(proj.tree)
proj, event, cli_runner = scratch_project_with_plugin

extra = {"extra": "extra"}
env = Environment(proj, extra_flags=extra)
Expand Down

0 comments on commit f6a00db

Please sign in to comment.