Keep routing and export verification snapshots read-only
This commit is contained in:
parent
9ba1dc048a
commit
8e8c8a7ba0
1 changed files with 158 additions and 19 deletions
|
|
@ -1,3 +1,5 @@
|
|||
import pickle
|
||||
from copy import deepcopy
|
||||
from dataclasses import replace
|
||||
|
||||
import pytest
|
||||
|
|
@ -268,3 +270,51 @@ def test_authored_sbend_length_survives_seed_replay() -> None:
|
|||
options=replace(options, search=replace(search, node_limit=0)),
|
||||
).results_by_net["shift"]
|
||||
assert preserves_length(replay, 95, tolerance=0)
|
||||
|
||||
|
||||
def test_export_and_routing_results_are_detached_snapshots() -> None:
|
||||
track = NetSpec("track", Port(10, 20, 0), Port(90, 20, 0))
|
||||
seeds = {"track": PathSeed((StraightSeed(80),))}
|
||||
problem = RoutingProblem((0, 0, 100, 50), (track,), initial_paths=seeds)
|
||||
seeds.clear()
|
||||
assert tuple(problem.initial_paths) == ("track",)
|
||||
|
||||
run = route(problem, options=_REPLAY, iteration_callback=lambda _, results: results.clear())
|
||||
original = dict(run.results_by_net)
|
||||
export = verify_export_grid(problem, original, grid=1)
|
||||
original.clear()
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
problem.initial_paths["track"] = PathSeed(())
|
||||
with pytest.raises(TypeError):
|
||||
del run.results_by_net["track"]
|
||||
with pytest.raises(TypeError):
|
||||
export.geometry_by_net["track"] = (box(0, 0, 1, 1),)
|
||||
with pytest.raises(TypeError):
|
||||
del export.reports_by_net["track"]
|
||||
with pytest.raises(TypeError):
|
||||
del export.checks_by_net["track"]
|
||||
|
||||
copied = dict(export.geometry_by_net)
|
||||
copied.clear()
|
||||
assert tuple(export.geometry_by_net) == ("track",)
|
||||
assert export.is_valid
|
||||
assert run.results_by_net["track"].is_valid
|
||||
|
||||
|
||||
def test_read_only_snapshots_survive_python_copy_and_pickle() -> None:
|
||||
track = NetSpec("track", Port(10, 20, 0), Port(90, 20, 0))
|
||||
problem = RoutingProblem((0, 0, 100, 50), (track,))
|
||||
run = route(problem)
|
||||
export = verify_export_grid(problem, run.results_by_net, grid=1)
|
||||
for copy in (deepcopy, lambda value: pickle.loads(pickle.dumps(value))):
|
||||
assert copy(problem) == problem
|
||||
assert copy(export) == export
|
||||
restored = copy(run)
|
||||
assert restored == run
|
||||
with pytest.raises(TypeError):
|
||||
del restored.results_by_net["track"]
|
||||
source = dict(run.results_by_net)
|
||||
replacement = replace(run, results_by_net=source)
|
||||
source.clear()
|
||||
assert replacement.results_by_net == run.results_by_net
|
||||
|
|
|
|||
Loading…
Reference in a new issue