[BuildLibrary] misc simplifications
This commit is contained in:
parent
08bbb10827
commit
c420ac8085
2 changed files with 114 additions and 74 deletions
|
|
@ -100,21 +100,6 @@ def test_build_library_validate_is_retryable_after_failure() -> None:
|
|||
assert report.dependency_graph["parent"] == frozenset({"child"})
|
||||
|
||||
|
||||
def test_build_library_check_on_register_rolls_back_failed_declarations() -> None:
|
||||
builder = BuildLibrary(check_on_register=True)
|
||||
|
||||
def make_parent(lib: BuildLibrary) -> Pattern:
|
||||
pat = Pattern()
|
||||
pat.ref("child")
|
||||
lib.abstract("child")
|
||||
return pat
|
||||
|
||||
with pytest.raises(BuildError, match='Failed while building declared cell "parent"'):
|
||||
builder.cells.parent = cell(make_parent)(builder)
|
||||
|
||||
assert "parent" not in builder
|
||||
|
||||
|
||||
def test_build_library_depends_on_supports_hidden_dependencies_for_partial_validation() -> None:
|
||||
builder = BuildLibrary()
|
||||
builder["child"] = Pattern()
|
||||
|
|
@ -179,6 +164,49 @@ def test_build_library_preserves_source_cells_and_records_source_provenance() ->
|
|||
assert report.provenance["src"].kind == "source"
|
||||
|
||||
|
||||
def test_build_library_add_source_can_rename_every_source_cell() -> None:
|
||||
source = Library()
|
||||
source["child"] = Pattern()
|
||||
parent = Pattern()
|
||||
parent.ref("child")
|
||||
source["parent"] = parent
|
||||
|
||||
builder = BuildLibrary()
|
||||
rename_map = builder.add_source(
|
||||
source,
|
||||
rename_theirs=lambda _lib, name: f"mapped_{name}",
|
||||
rename_when="always",
|
||||
)
|
||||
built, report = builder.build()
|
||||
|
||||
assert rename_map == {
|
||||
"child": "mapped_child",
|
||||
"parent": "mapped_parent",
|
||||
}
|
||||
assert "mapped_child" in built["mapped_parent"].refs
|
||||
assert report.provenance["mapped_child"].source_name == "child"
|
||||
|
||||
|
||||
def test_build_library_rejects_source_cells_added_after_add_source() -> None:
|
||||
source = Library({"src": Pattern()})
|
||||
builder = BuildLibrary()
|
||||
builder.add_source(source)
|
||||
source["late"] = Pattern()
|
||||
|
||||
with pytest.raises(BuildError, match="Do not structurally mutate source libraries"):
|
||||
builder.build()
|
||||
|
||||
|
||||
def test_build_library_rejects_source_cells_removed_after_add_source() -> None:
|
||||
source = Library({"src": Pattern()})
|
||||
builder = BuildLibrary()
|
||||
builder.add_source(source)
|
||||
del source["src"]
|
||||
|
||||
with pytest.raises(BuildError, match="Do not structurally mutate source libraries"):
|
||||
builder.build()
|
||||
|
||||
|
||||
def test_build_library_rejects_add_source_during_build() -> None:
|
||||
builder = BuildLibrary()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue