Skip to content

Commit 0e83b89

Browse files
committed
Some rephrasing
1 parent e8f6f0e commit 0e83b89

10 files changed

Lines changed: 53 additions & 102 deletions

tests/fixtures/aem_pack.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ async def process_pack(
149149
def mock_registry() -> AEMPackRegistry:
150150
"""An AEMPackRegistry wired with mocked collaborators.
151151
152-
Suitable for tests that exercise only the pure in-memory methods
153-
(``_traverse_graph``, ``_create_aem_pack``, ``_apply_workflow_to_data``) and
154-
therefore do not need Mongo/Kafka containers.
152+
Suitable for tests that exercise only the in-memory methods `_traverse_graph`,
153+
`_create_aem_pack` and ``_apply_workflow_to_data`, which do not need Mongo/Kafka
154+
containers.
155155
"""
156156
return AEMPackRegistry(
157157
config=MagicMock(spec=Config),

tests/fixtures/examples.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
"""Example configs: paths, loaders, schemas, and the parametrize fixtures that
17-
consume them. One module for everything driven by YAML/JSON fixture files.
18-
"""
16+
"""Fixtures for example transformation configs and mock schema."""
1917

2018
import contextlib
2119
import json
@@ -42,10 +40,10 @@
4240

4341
@cache
4442
def _examples_in(subpath: str) -> Mapping[str, Path]:
45-
"""Return ``{stem: path}`` for files under ``CONFIG_DIR / subpath``, sorted by stem.
43+
"""Return `{stem: path}` for files under `CONFIG_DIR / subpath`, sorted by stem.
4644
47-
The result is a read-only ``MappingProxyType`` because ``@cache`` shares one
48-
instance across callers mutation would silently corrupt the cache.
45+
The result is a read-only `MappingProxyType` because `@cache` shares one instance
46+
across callers and mutation would silently corrupt the cache.
4947
"""
5048
return MappingProxyType(
5149
dict(
@@ -55,7 +53,7 @@ def _examples_in(subpath: str) -> Mapping[str, Path]:
5553

5654

5755
def _examples_by_prefix(subpath: str, prefix: str) -> Mapping[str, Path]:
58-
"""Return ``{stem-without-prefix: path}`` for prefixed files under ``subpath``."""
56+
"""Return `{stem-without-prefix: path}` for prefixed files under `subpath`."""
5957
return {
6058
stem.removeprefix(prefix): path
6159
for stem, path in _examples_in(subpath).items()
@@ -65,9 +63,9 @@ def _examples_by_prefix(subpath: str, prefix: str) -> Mapping[str, Path]:
6563

6664
@contextlib.contextmanager
6765
def _cwd(path: Path) -> Iterator[None]:
68-
"""Chdir to ``path`` for the block; restore on exit.
66+
"""Chdir to `path` for the block; restore on exit.
6967
70-
Required so schemapack's content-schema validator resolves ``content: ../foo.json``
68+
Required so schemapack's content-schema validator resolves `content: ../foo.json`
7169
references relative to the YAML fixture's own directory, not the test runner's cwd.
7270
"""
7371
original = os.getcwd()
@@ -81,7 +79,7 @@ def _cwd(path: Path) -> Iterator[None]:
8179
def _load[ModelT: BaseModel](
8280
path: Path, model: type[ModelT], *, section: str | None = None
8381
) -> ModelT:
84-
"""Load and validate ``model`` from a YAML fixture (optionally a sub-section)."""
82+
"""Load and validate `model` from a YAML fixture."""
8583
with path.open("r") as fh:
8684
data = safe_load(fh)
8785
if section is not None:
@@ -91,17 +89,17 @@ def _load[ModelT: BaseModel](
9189

9290

9391
def load_validated_config(path: Path) -> ValidatedConfig:
94-
"""Load a ``ValidatedConfig`` from a YAML fixture file."""
92+
"""Load a `ValidatedConfig` from a YAML fixture file."""
9593
return _load(path, ValidatedConfig)
9694

9795

9896
def load_raw_config(path: Path) -> RawConfig:
99-
"""Load a ``RawConfig`` from a YAML fixture file."""
97+
"""Load a `RawConfig` from a YAML fixture file."""
10098
return _load(path, RawConfig)
10199

102100

103101
def load_pruning_config(path: Path) -> ValidatedConfig:
104-
"""Load a ``ValidatedConfig`` from a pruning-case YAML's ``config:`` section."""
102+
"""Load a `ValidatedConfig` from a pruning-case YAML's `config` section."""
105103
return _load(path, ValidatedConfig, section="config")
106104

107105

@@ -111,7 +109,7 @@ def load_aem_pack_config(
111109
) -> PersistedConfig:
112110
"""Load a YAML config, derive schemas, and return a PersistedConfig.
113111
114-
``publish_models`` flips ``publish=True`` on the named models.
112+
`publish_models` sets `publish=True` on all models named in the collection.
115113
"""
116114
validated = load_validated_config(path)
117115
deriver = ModelDeriver()
@@ -196,12 +194,12 @@ def model_derivation_fixture(
196194
def mock_apply_workflow(
197195
model_derivation_fixture: ModelDerivationFixture,
198196
) -> Generator[MagicMock]:
199-
"""Patch ``_apply_workflow`` on the deriver and yield the mock."""
197+
"""Patch `_apply_workflow` on the deriver and yield the mock."""
200198
with patch.object(model_derivation_fixture.deriver, "_apply_workflow") as mock:
201199
yield mock
202200

203201

204202
@pytest.fixture
205203
def pruning_fixture(request: pytest.FixtureRequest) -> Generator[ValidatedConfig]:
206-
"""Load a ``ValidatedConfig`` from the YAML's ``config:`` section, via ``indirect``."""
204+
"""Load a `ValidatedConfig` from the YAML's `config:` section, via `indirect`."""
207205
yield load_pruning_config(request.param)

tests/fixtures/joint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ async def seed_config(
9090
) -> PersistedConfig:
9191
"""Derive a config from a YAML fixture and write it to the DB.
9292
93-
Returns the PersistedConfig matching what ``load_config_from_db`` returns.
93+
Returns the PersistedConfig matching `load_config_from_db`.
9494
"""
9595
config = load_aem_pack_config(config_yaml_path, publish_models=publish_models)
9696
await self.insert_config(config)

tests/fixtures/mongo.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
async def mongo_collection(
2929
request: pytest.FixtureRequest, mongodb: MongoDbFixture
3030
) -> AsyncGenerator[AsyncCollection]:
31-
"""Yield a single MongoDB collection by name (passed via ``indirect``)."""
31+
"""Yield a single MongoDB collection by name, passed via `indirect`.
32+
33+
`request.param` holds the collection name.
34+
"""
3235
async with ConfiguredMongoClient(config=mongodb.config) as client:
3336
yield client[mongodb.config.db_name][request.param]

tests/test_aem_pack_registry/test_config_changes.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
"""Tests for processing under config inconsistencies and mid-flight changes.
17-
18-
Covers behavior when the persisted config differs from what was current at the
19-
time a pack was queued: routes/models removed (cleanup of stale derived packs),
20-
the graph config version bumping mid-process (pack freed for reprocessing), and
21-
a pack referencing a model that no longer exists (error propagation).
22-
"""
16+
"""Tests for processing under config inconsistencies and mid-flight changes."""
2317

2418
import logging
2519
from unittest.mock import AsyncMock, patch

tests/test_aem_pack_registry/test_pure_helpers.py renamed to tests/test_aem_pack_registry/test_in_memory_methods.py

Lines changed: 9 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,12 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
"""Tests for the pure in-memory methods of AEMPackRegistry.
17-
18-
These tests run against a ``mock_registry`` (collaborators are mocks) and do
19-
not need MongoDB or Kafka. Covered methods:
20-
21-
* ``_create_aem_pack`` and ``_apply_workflow_to_data`` — wrapper helpers
22-
* ``_traverse_graph`` — the routing/publishing core, exercised with a range of
23-
graph topologies
24-
"""
16+
"""Tests for the in-memory methods of AEMPackRegistry."""
2517

2618
from uuid import uuid4
2719

2820
import pytest
2921
from pydantic import UUID4
30-
from schemapack.spec.datapack import DataPack
3122

3223
from ets.core.aem_pack_registry import AEMPackRegistry
3324
from ets.core.models import AEMPack, Model, PersistedConfig
@@ -44,7 +35,7 @@ def _ingress_model(config: PersistedConfig) -> Model:
4435

4536

4637
def _ingress_for(config: PersistedConfig, name: str | None = None) -> AEMPack:
47-
"""Build an ingress AEMPack (defaults to the configured ingress model)."""
38+
"""Build an ingress AEMPack. Defaults to the configured ingress model."""
4839
return AEMPack(
4940
id=uuid4(),
5041
model_name=name or _ingress_model(config).name,
@@ -60,7 +51,7 @@ def _traverse(
6051
dirty_map: dict[str, UUID4],
6152
config: PersistedConfig,
6253
) -> tuple[list[AEMPack], dict[str, UUID4]]:
63-
"""Run ``_traverse_graph`` seeding ``transformed_map`` with the incoming pack."""
54+
"""Run `_traverse_graph` seeding `transformed_map` with the incoming pack."""
6455
return mock_registry._traverse_graph(
6556
incoming=incoming,
6657
dirty_map=dirty_map,
@@ -69,9 +60,6 @@ def _traverse(
6960
)
7061

7162

72-
# --- _create_aem_pack / _apply_workflow_to_data ------------------------------
73-
74-
7563
@pytest.mark.parametrize(
7664
"aem_id,expected_aem_id",
7765
[(None, False), (EXPECTED_AEM_ID, True)],
@@ -80,7 +68,7 @@ def _traverse(
8068
def test_create_aem_pack(
8169
mock_registry: AEMPackRegistry, aem_id: UUID4 | None, expected_aem_id: bool
8270
):
83-
"""Creating an AEMPack wrapper, with and without a pre-specified ID."""
71+
"""Ensure creating an AEMPack wrapper works, with and without a pre-specified ID."""
8472
aem_pack = mock_registry._create_aem_pack(
8573
aem_id=aem_id,
8674
model_name="TestModel",
@@ -98,26 +86,6 @@ def test_create_aem_pack(
9886
assert aem_pack.id == EXPECTED_AEM_ID
9987

10088

101-
def test_apply_workflow_to_data(mock_registry: AEMPackRegistry):
102-
"""Applying a workflow transforms only the schema, not the resource data."""
103-
config = load_aem_pack_config(AEM_PACK_REGISTRY_CONFIGS["single_route"])
104-
ingress = _ingress_model(config)
105-
106-
result = mock_registry._apply_workflow_to_data(
107-
data=TEST_DATAPACK,
108-
annotation={},
109-
input_schema=ingress.schema_,
110-
workflow=config.workflows[0],
111-
)
112-
113-
assert isinstance(result, DataPack)
114-
# rename_id_property only modifies the schema, not the resource data.
115-
assert result.resources == TEST_DATAPACK.resources
116-
117-
118-
# --- _traverse_graph ---------------------------------------------------------
119-
120-
12189
@pytest.mark.parametrize(
12290
"aem_pack_config, dirty_names",
12391
[
@@ -148,8 +116,8 @@ def test_clears_dirty_map(
148116
aem_pack_config: PersistedConfig,
149117
dirty_names: set[str],
150118
):
151-
"""Traversal clears all non-dangling dirty map entries and only publishes
152-
derived packs whose model has ``publish=True``.
119+
"""Ensure traversal clears all non-dangling dirty map entries and only publishes
120+
derived packs whose model has `publish=True`.
153121
"""
154122
incoming = _ingress_for(aem_pack_config)
155123
dirty_map: dict[str, UUID4] = {name: uuid4() for name in dirty_names}
@@ -165,7 +133,7 @@ def test_clears_dirty_map(
165133

166134

167135
def test_respects_topological_order(mock_registry: AEMPackRegistry):
168-
"""Routes are processed in topological order regardless of fixture listing order."""
136+
"""Ensure routes are processed in topological order regardless of fixture listing order."""
169137
config = load_aem_pack_config(AEM_PACK_REGISTRY_CONFIGS["forking_routes"])
170138
# Swap orders so DerivedModel2 (order=1) is processed before DerivedModel1 (order=2)
171139
by_name = {model.name: model for model in config.models}
@@ -203,9 +171,7 @@ def test_dirty_map_id_handling(
203171
have_dirty_map: bool,
204172
expected_published: int,
205173
):
206-
"""With a dirty map, derived packs reuse the supplied UUIDs; without one,
207-
fresh UUIDs are generated for each derived pack.
208-
"""
174+
"""Ensure derived packs reuse the supplied UUIDs from the dirty map."""
209175
config = load_aem_pack_config(
210176
AEM_PACK_REGISTRY_CONFIGS[config_name], publish_models=publish
211177
)
@@ -246,7 +212,7 @@ def test_bottleneck_topology(
246212
aem_pack_config: PersistedConfig,
247213
ingress_name: str,
248214
):
249-
"""Traversal from each ingress through a bottleneck publishes downstream
215+
"""Ensure traversal from each ingress through a bottleneck publishes downstream
250216
and reuses existing dirty-map IDs for the derived packs.
251217
"""
252218
incoming = _ingress_for(aem_pack_config, name=ingress_name)

tests/test_aem_pack_registry/test_pipeline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
"""Test different configurations with end-to-end tests: queue claim process verify derived packs."""
16+
"""Test different configurations with end-to-end tests: queue - claim - process - verify derived packs."""
1717

1818
from uuid import uuid4
1919

0 commit comments

Comments
 (0)