Commit 05347fad authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Improve typing with newer mypy & behave-utils

Fix PEP-612 features now mypy suports it.
parent 54473683
Loading
Loading
Loading
Loading
+3 −9
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@ from __future__ import annotations
import sys
from os import environ
from typing import TYPE_CHECKING
from typing import Any
from typing import Iterator

from behave import fixture
@@ -60,22 +59,17 @@ def before_scenario(context: ScenarioContext, scenario: Scenario) -> None:
	context.session = use_fixture(requests_session, context)


# Todo(dom.sekotill): When PEP-612 is properly implemented in mypy the [*a, **k] and default
# values nonsense can be removed from fixtures

@fixture
def setup_test_cluster(context: Context, /, site_url: URL|None = None, *a: Any, **k: Any) -> Iterator[Site]:
def setup_test_cluster(context: Context, /, site_url: URL) -> Iterator[Site]:
	"""
	Prepare and return the details of a site fixture
	"""
	assert site_url is not None, \
		"site_url is required, but default supplied until PEP-612 supported"
	with test_cluster(site_url) as site:
		yield site


@fixture
def requests_session(context: ScenarioContext, /, *a: Any, **k: Any) -> Iterator[Session]:
def requests_session(context: ScenarioContext, /) -> Iterator[Session]:
	"""
	Create and configure a `requests` session for accessing site fixtures
	"""
@@ -86,7 +80,7 @@ def requests_session(context: ScenarioContext, /, *a: Any, **k: Any) -> Iterator


@fixture
def db_snapshot_rollback(context: FeatureContext, /, *a: Any, **k: Any) -> Iterator[None]:
def db_snapshot_rollback(context: FeatureContext, /) -> Iterator[None]:
	"""
	Manage the state of a site's database as a revertible fixture
	"""
+1 −9
Original line number Diff line number Diff line
@@ -11,7 +11,6 @@ Step implementations involving creating and requesting WP posts (and pages)
from __future__ import annotations

from codecs import decode as utf8_decode
from typing import Any
from typing import Iterator

from behave import fixture
@@ -123,17 +122,12 @@ def assert_contains(
@fixture
def wp_post(
	context: Context, /,
	post_type: PostType|None = None,
	post_type: PostType,
	content: str = DEFAULT_CONTENT,
	*a: Any,
	**k: Any,
) -> Iterator[JSONObject]:
	"""
	Create a WP post fixture of the given type with the given content
	"""
	assert post_type is not None, \
		"post_type MUST be supplied to use_fixture when calling with wp_post"

	wp = context.site.backend
	postid = wp.cli(
		"post", "create",
@@ -162,8 +156,6 @@ def set_specials(
	context: Context, /,
	homepage: JSONObject|None = None,
	posts: JSONObject|None = None,
	*a: Any,
	**k: Any,
) -> Iterator[None]:
	"""
	Set the homepage and post index to new pages, creating default pages if needed
+6 −1
Original line number Diff line number Diff line
@@ -13,8 +13,10 @@ from __future__ import annotations
from contextlib import contextmanager
from os import environ
from pathlib import Path
from typing import TYPE_CHECKING
from typing import Iterator
from typing import NamedTuple
from typing import TypeVar

from behave_utils import URL
from behave_utils import wait
@@ -35,6 +37,9 @@ class Wordpress(Container):

	DEFAULT_ALIASES = ("upstream",)

	if TYPE_CHECKING:
		T = TypeVar("T", bound="Wordpress")

	def __init__(self, site_url: URL, database: Mysql, network: Network|None = None):
		Container.__init__(
			self,
@@ -66,7 +71,7 @@ class Wordpress(Container):
		return Cli(self, "wp")

	@contextmanager
	def started(self) -> Iterator[Container]:
	def started(self: T) -> Iterator[T]:
		with self:
			self.start()
			cmd = ["bash", "-c", "[[ /proc/1/exe -ef `which php-fpm` ]]"]