paces 0.0.28__tar.gz → 0.0.29__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {paces-0.0.28 → paces-0.0.29}/PKG-INFO +1 -1
- {paces-0.0.28 → paces-0.0.29}/paces/edits.py +202 -1
- {paces-0.0.28 → paces-0.0.29}/pyproject.toml +1 -1
- {paces-0.0.28 → paces-0.0.29}/tests/test_edits.py +110 -0
- {paces-0.0.28 → paces-0.0.29}/.gitignore +0 -0
- {paces-0.0.28 → paces-0.0.29}/LICENSE +0 -0
- {paces-0.0.28 → paces-0.0.29}/README.md +0 -0
- {paces-0.0.28 → paces-0.0.29}/docs/README.md +0 -0
- {paces-0.0.28 → paces-0.0.29}/docs/alignment/README.md +0 -0
- {paces-0.0.28 → paces-0.0.29}/docs/poc-reference/README.md +0 -0
- {paces-0.0.28 → paces-0.0.29}/docs/poc-reference/artifacts/clips.json +0 -0
- {paces-0.0.28 → paces-0.0.29}/paces/__init__.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/paces/__main__.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/paces/ask.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/paces/ask_contract.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/paces/bodies/__init__.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/paces/bodies/_base.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/paces/bodies/derivation.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/paces/bodies/document.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/paces/bodies/signal.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/paces/bodies/step.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/paces/corrections.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/paces/cues.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/paces/data/ask/ask.css +0 -0
- {paces-0.0.28 → paces-0.0.29}/paces/data/ask/ask.html +0 -0
- {paces-0.0.28 → paces-0.0.29}/paces/data/ask/ask.js +0 -0
- {paces-0.0.28 → paces-0.0.29}/paces/derivation.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/paces/evidence.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/paces/excerpts.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/paces/known_k.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/paces/measure.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/paces/model.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/paces/pose.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/paces/projection.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/paces/render.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/paces/segmentation.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/paces/segmenters.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/paces/timed_text.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/paces/tools.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/tests/audio_synth.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/tests/data/body_schemas.json +0 -0
- {paces-0.0.28 → paces-0.0.29}/tests/data/routine.json +0 -0
- {paces-0.0.28 → paces-0.0.29}/tests/poc_fixture.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/tests/test_ask.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/tests/test_chapters.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/tests/test_cli_surface.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/tests/test_corrections.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/tests/test_cues.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/tests/test_derivation.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/tests/test_edit_protection_residuals.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/tests/test_evidence.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/tests/test_evidence_schemas.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/tests/test_excerpts.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/tests/test_known_k.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/tests/test_measure.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/tests/test_pose.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/tests/test_render_media.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/tests/test_roundtrip_poc.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/tests/test_segment.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/tests/test_smoke.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/tests/test_vertical_slice.py +0 -0
- {paces-0.0.28 → paces-0.0.29}/tests/video_synth.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: paces
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.29
|
|
4
4
|
Summary: Turn instructional media into structured, interactive learning material
|
|
5
5
|
Project-URL: Homepage, https://github.com/thorwhalen/paces
|
|
6
6
|
Project-URL: Repository, https://github.com/thorwhalen/paces
|
|
@@ -56,7 +56,7 @@ from __future__ import annotations
|
|
|
56
56
|
|
|
57
57
|
import copy
|
|
58
58
|
import re
|
|
59
|
-
from collections.abc import Mapping, Sequence
|
|
59
|
+
from collections.abc import Iterator, Mapping, Sequence
|
|
60
60
|
from datetime import datetime, timezone
|
|
61
61
|
from typing import Any
|
|
62
62
|
|
|
@@ -435,6 +435,198 @@ def _renamed_from(committed: list[dict]) -> dict[str, dict]:
|
|
|
435
435
|
return out
|
|
436
436
|
|
|
437
437
|
|
|
438
|
+
def _occurrence_start(step: Mapping) -> float | None:
|
|
439
|
+
"""Where a step first starts in its media (its first span's start), if anywhere."""
|
|
440
|
+
spans = step.get("spans") or []
|
|
441
|
+
return float(spans[0]["start"]) if spans else None
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
def _walk(steps: list[dict]) -> Iterator[dict]:
|
|
445
|
+
"""Every step of a tree, parents before children."""
|
|
446
|
+
for step in steps:
|
|
447
|
+
yield step
|
|
448
|
+
yield from _walk(step.get("steps", []))
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
def _renamed_was(step: Mapping) -> str | None:
|
|
452
|
+
"""The id a step had before an ``/id`` lock renamed it, if one did."""
|
|
453
|
+
for lock in step.get("locks", []):
|
|
454
|
+
if lock.get("path") == "/id" and lock.get("was") is not None:
|
|
455
|
+
return str(lock["was"])
|
|
456
|
+
return None
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
def _generated_family(name: str, sid: str) -> str | None:
|
|
460
|
+
"""The family of a generated id: the slug of ``name`` when ``sid`` is that
|
|
461
|
+
slug or it with a ``-N`` repeat suffix (:func:`paces.segmenters.unique_slug_ids`);
|
|
462
|
+
``None`` for an unnamed step or an id the name did not generate.
|
|
463
|
+
|
|
464
|
+
>>> _generated_family("Turn", "turn-3"), _generated_family("Turn", "spin"), _generated_family("", "seg-1")
|
|
465
|
+
('turn', None, None)
|
|
466
|
+
"""
|
|
467
|
+
from paces.segmenters import _slugify
|
|
468
|
+
|
|
469
|
+
if not name:
|
|
470
|
+
return None # unnamed (``seg-1``): its id is its place
|
|
471
|
+
base = _slugify(name)
|
|
472
|
+
if sid == base or re.fullmatch(rf"{re.escape(base)}-\d+", sid):
|
|
473
|
+
return base
|
|
474
|
+
return None
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
def _time_matching(a: list[float], b: list[float]) -> list[tuple[int, int]]:
|
|
478
|
+
"""The order-preserving pairing of times ``a`` with times ``b`` (each sorted;
|
|
479
|
+
each used at most once, as many pairs as the shorter list) of least total
|
|
480
|
+
distance.
|
|
481
|
+
|
|
482
|
+
>>> _time_matching([0.0, 20.0], [0.0, 5.0, 20.0])
|
|
483
|
+
[(0, 0), (1, 2)]
|
|
484
|
+
>>> _time_matching([0.0, 5.0, 20.0], [0.0, 20.0])
|
|
485
|
+
[(0, 0), (2, 1)]
|
|
486
|
+
"""
|
|
487
|
+
if len(a) > len(b):
|
|
488
|
+
return [(i, j) for j, i in _time_matching(b, a)]
|
|
489
|
+
n, m = len(a), len(b)
|
|
490
|
+
inf = float("inf")
|
|
491
|
+
# cost[i][j]: best pairing of a[:i] into b[:j] with every a used (i <= j)
|
|
492
|
+
cost = [[inf] * (m + 1) for _ in range(n + 1)]
|
|
493
|
+
cost[0] = [0.0] * (m + 1)
|
|
494
|
+
for i in range(1, n + 1):
|
|
495
|
+
for j in range(i, m + 1):
|
|
496
|
+
cost[i][j] = min(
|
|
497
|
+
cost[i][j - 1], cost[i - 1][j - 1] + abs(a[i - 1] - b[j - 1])
|
|
498
|
+
)
|
|
499
|
+
pairs, i, j = [], n, m
|
|
500
|
+
while i > 0:
|
|
501
|
+
if j > i and cost[i][j] == cost[i][j - 1]:
|
|
502
|
+
j -= 1
|
|
503
|
+
else:
|
|
504
|
+
pairs.append((i - 1, j - 1))
|
|
505
|
+
i, j = i - 1, j - 1
|
|
506
|
+
return pairs[::-1]
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
def _repeat_ids(committed: list[dict], fresh: list[dict]) -> dict[str, str]:
|
|
510
|
+
"""``{fresh id: id to use}`` that keeps repeated steps' identity by name and
|
|
511
|
+
time rather than by the place a generated ``-N`` suffix encodes (paces#50).
|
|
512
|
+
|
|
513
|
+
Generated ids of repeats are numbered by position (``turn``, ``turn-2``), so
|
|
514
|
+
a repeat inserted earlier shifts every later one's suffix, and a lock on the
|
|
515
|
+
committed ``turn-2`` would land on the new second Turn. Over the WHOLE tree
|
|
516
|
+
(ids are unique document-wide), each family of generated ids (a name's slug
|
|
517
|
+
and its repeats) on both sides, with a repeat or a moved id, is paired by
|
|
518
|
+
start time (:func:`_time_matching`, each side in time order). A fresh
|
|
519
|
+
occurrence takes its committed partner's id (the id an ``/id`` lock renamed
|
|
520
|
+
away from, for a renamed one, so the rename rule finds it); an unpaired one
|
|
521
|
+
the first id of its family that no committed or other fresh step holds
|
|
522
|
+
(or held, before a rename); and a fresh step outside these families whose id
|
|
523
|
+
an assignment takes is re-identified the same way. Families without times
|
|
524
|
+
on every occurrence are left as they are.
|
|
525
|
+
"""
|
|
526
|
+
c_steps, f_steps = list(_walk(committed)), list(_walk(fresh))
|
|
527
|
+
families: dict[str, tuple[list[tuple[dict, str]], list[dict]]] = {}
|
|
528
|
+
for step in c_steps:
|
|
529
|
+
was = _renamed_was(step)
|
|
530
|
+
key = was or step["id"]
|
|
531
|
+
family = _generated_family(step.get("name", ""), key)
|
|
532
|
+
if family is None and step.get("name"):
|
|
533
|
+
# a name (or id) a human edited: the id it was generated with says the
|
|
534
|
+
# family; it pairs only with a family analysis generates from a name
|
|
535
|
+
family = re.sub(r"-\d+$", "", key)
|
|
536
|
+
if family is not None:
|
|
537
|
+
families.setdefault(family, ([], []))[0].append((step, key))
|
|
538
|
+
for step in f_steps:
|
|
539
|
+
family = _generated_family(step.get("name", ""), step["id"])
|
|
540
|
+
if family is not None:
|
|
541
|
+
families.setdefault(family, ([], []))[1].append(step)
|
|
542
|
+
|
|
543
|
+
mapping: dict[str, str] = {}
|
|
544
|
+
unpaired: list[tuple[str, str]] = [] # (fresh id, family)
|
|
545
|
+
for family, (cs, fs) in families.items():
|
|
546
|
+
if not cs or not fs:
|
|
547
|
+
continue
|
|
548
|
+
if len(cs) == 1 and len(fs) == 1 and cs[0][1] == fs[0]["id"]:
|
|
549
|
+
continue # one each, same id: nothing to re-identify
|
|
550
|
+
if any(_occurrence_start(s) is None for s, _ in cs) or any(
|
|
551
|
+
_occurrence_start(s) is None for s in fs
|
|
552
|
+
):
|
|
553
|
+
continue # no clock to tell occurrences apart: keep the positional ids
|
|
554
|
+
cs = sorted(cs, key=lambda c: _occurrence_start(c[0]))
|
|
555
|
+
fs = sorted(fs, key=_occurrence_start)
|
|
556
|
+
pairs = _time_matching(
|
|
557
|
+
[_occurrence_start(s) for s, _ in cs], [_occurrence_start(s) for s in fs]
|
|
558
|
+
)
|
|
559
|
+
paired = {j for _, j in pairs}
|
|
560
|
+
for i, j in pairs:
|
|
561
|
+
mapping[fs[j]["id"]] = cs[i][1]
|
|
562
|
+
unpaired += [(fs[j]["id"], family) for j in range(len(fs)) if j not in paired]
|
|
563
|
+
|
|
564
|
+
used = {s["id"] for s in c_steps} | {w for s in c_steps if (w := _renamed_was(s))}
|
|
565
|
+
used |= set(mapping.values())
|
|
566
|
+
used |= {s["id"] for s in f_steps if s["id"] not in mapping}
|
|
567
|
+
|
|
568
|
+
def free(base: str) -> str:
|
|
569
|
+
candidate, n = base, 1
|
|
570
|
+
while candidate in used:
|
|
571
|
+
n += 1
|
|
572
|
+
candidate = f"{base}-{n}"
|
|
573
|
+
used.add(candidate)
|
|
574
|
+
return candidate
|
|
575
|
+
|
|
576
|
+
held = {s["id"] for s in c_steps} | {w for s in c_steps if (w := _renamed_was(s))}
|
|
577
|
+
held |= set(mapping.values())
|
|
578
|
+
for sid, family in unpaired:
|
|
579
|
+
if sid in held: # its positional id is a committed occurrence's: move it
|
|
580
|
+
mapping[sid] = free(family)
|
|
581
|
+
# a fresh step the mapping does not move, whose id an assignment now takes
|
|
582
|
+
taken = {new for old, new in mapping.items() if old != new}
|
|
583
|
+
for step in f_steps:
|
|
584
|
+
sid = step["id"]
|
|
585
|
+
if sid not in mapping and sid in taken:
|
|
586
|
+
family = _generated_family(step.get("name", ""), sid) or re.sub(
|
|
587
|
+
r"-\d+$", "", sid
|
|
588
|
+
)
|
|
589
|
+
mapping[sid] = free(family)
|
|
590
|
+
return {old: new for old, new in mapping.items() if old != new}
|
|
591
|
+
|
|
592
|
+
|
|
593
|
+
def _renumbered(
|
|
594
|
+
doc: dict, ids: Mapping[str, str], *, renamed: Mapping[str, str] | None = None
|
|
595
|
+
) -> dict:
|
|
596
|
+
"""``doc`` (a fresh dump) with its step ids, and every reference to one (a
|
|
597
|
+
cue's anchor, a step's ``variant_of``), replaced through ``ids``. A
|
|
598
|
+
reference that lands on an id an ``/id`` lock renamed (``renamed``: was ->
|
|
599
|
+
now) follows the rename, as the step itself will in the merge."""
|
|
600
|
+
if not ids:
|
|
601
|
+
return doc
|
|
602
|
+
renamed = renamed or {}
|
|
603
|
+
ref = {old: renamed.get(new, new) for old, new in ids.items()}
|
|
604
|
+
|
|
605
|
+
def steps(rows: list[dict]) -> list[dict]:
|
|
606
|
+
out = []
|
|
607
|
+
for step in rows:
|
|
608
|
+
step = dict(step)
|
|
609
|
+
step["id"] = ids.get(step["id"], step["id"])
|
|
610
|
+
if step.get("variant_of") is not None:
|
|
611
|
+
step["variant_of"] = ref.get(step["variant_of"], step["variant_of"])
|
|
612
|
+
step["steps"] = steps(step.get("steps", []))
|
|
613
|
+
out.append(step)
|
|
614
|
+
return out
|
|
615
|
+
|
|
616
|
+
doc = dict(doc)
|
|
617
|
+
doc["steps"] = steps(doc["steps"])
|
|
618
|
+
cues = []
|
|
619
|
+
for cue in doc.get("cues", []):
|
|
620
|
+
cue = dict(cue)
|
|
621
|
+
anchor = dict(cue.get("anchor") or {})
|
|
622
|
+
if anchor.get("step") is not None:
|
|
623
|
+
anchor["step"] = ref.get(anchor["step"], anchor["step"])
|
|
624
|
+
cue["anchor"] = anchor
|
|
625
|
+
cues.append(cue)
|
|
626
|
+
doc["cues"] = cues
|
|
627
|
+
return doc
|
|
628
|
+
|
|
629
|
+
|
|
438
630
|
def _merge_steps(committed: list[dict], fresh: list[dict]) -> list[dict]:
|
|
439
631
|
committed_by_id: dict[str, dict] = {}
|
|
440
632
|
for step in committed: # first occurrence wins, matching apply_edits
|
|
@@ -540,6 +732,9 @@ def merge_regenerated(committed: StepDocument, fresh: StepDocument) -> StepDocum
|
|
|
540
732
|
4. Cues, questions and sources are unioned by id (fresh wins on shared
|
|
541
733
|
ids) — analysis rarely regenerates them, and dropping committed
|
|
542
734
|
content silently is the failure this module exists to prevent.
|
|
735
|
+
5. Repeated steps are matched by name and time, not by their generated
|
|
736
|
+
``-N`` suffix (:func:`_repeat_ids`): a repeat inserted earlier
|
|
737
|
+
does not move a lock onto the wrong occurrence (paces#50).
|
|
543
738
|
|
|
544
739
|
Edits made through :func:`apply_edits` are always locked, so "hand edit"
|
|
545
740
|
and "protected" coincide by construction; edits made by hand-editing the
|
|
@@ -547,6 +742,12 @@ def merge_regenerated(committed: StepDocument, fresh: StepDocument) -> StepDocum
|
|
|
547
742
|
"""
|
|
548
743
|
committed_dump = committed.model_dump(mode="python", by_alias=False)
|
|
549
744
|
out = fresh.model_dump(mode="python", by_alias=False)
|
|
745
|
+
renamed = {
|
|
746
|
+
was: s["id"] for s in _walk(committed_dump["steps"]) if (was := _renamed_was(s))
|
|
747
|
+
}
|
|
748
|
+
out = _renumbered(
|
|
749
|
+
out, _repeat_ids(committed_dump["steps"], out["steps"]), renamed=renamed
|
|
750
|
+
)
|
|
550
751
|
out["steps"] = _merge_steps(committed_dump["steps"], out["steps"])
|
|
551
752
|
for key in ("cues", "questions", "sources"):
|
|
552
753
|
out[key] = _union_by_id(committed_dump[key], out[key])
|
|
@@ -453,3 +453,113 @@ def test_scalar_list_edits_do_not_survive_but_keep_their_record():
|
|
|
453
453
|
merged = merge_regenerated(committed, fresh)
|
|
454
454
|
assert merged.steps[0].tags == ["wrong-tag"] # not protected, by design
|
|
455
455
|
assert merged.steps[0].locks # but the record survives
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
def _repeats(names_and_starts) -> StepDocument:
|
|
459
|
+
"""A document of steps named and timed as given, with the generated ids
|
|
460
|
+
a segmenter makes for repeats (``turn``, ``turn-2``, ...)."""
|
|
461
|
+
from paces.segmenters import unique_slug_ids
|
|
462
|
+
|
|
463
|
+
names = [n for n, _ in names_and_starts]
|
|
464
|
+
return _doc(
|
|
465
|
+
steps=[
|
|
466
|
+
Step(
|
|
467
|
+
id=sid,
|
|
468
|
+
name=name,
|
|
469
|
+
duration=Measure(value="1", unit="eight"),
|
|
470
|
+
spans=[SourceSpan(source="vid", start=str(start), end=str(start + 4))],
|
|
471
|
+
origin=Origin(generated_by="segmenter:grid-placed"),
|
|
472
|
+
)
|
|
473
|
+
for sid, (name, start) in zip(unique_slug_ids(names), names_and_starts)
|
|
474
|
+
]
|
|
475
|
+
)
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
def test_a_lock_on_a_repeat_stays_on_it_when_a_repeat_is_inserted_before_it():
|
|
479
|
+
"""paces#50: committed [Turn, Kick, Turn] (turn, kick, turn-2) with a lock
|
|
480
|
+
on turn-2; regeneration finds a new Turn at 5 s, so its ids shift to turn,
|
|
481
|
+
turn-2, kick, turn-3. The lock stays on the Turn at 20 s, and the new one
|
|
482
|
+
gets an id no committed step holds."""
|
|
483
|
+
committed = apply_edits(
|
|
484
|
+
_repeats([("Turn", 0), ("Kick", 10), ("Turn", 20)]),
|
|
485
|
+
[{"op": "set", "path": "/steps/turn-2/name", "value": "Turn (left)"}],
|
|
486
|
+
by="user:thor",
|
|
487
|
+
)
|
|
488
|
+
fresh = _repeats([("Turn", 0), ("Turn", 5), ("Kick", 10), ("Turn", 20)])
|
|
489
|
+
merged = merge_regenerated(committed, fresh)
|
|
490
|
+
by_start = {str(s.spans[0].start): s for s in merged.steps}
|
|
491
|
+
assert by_start["20"].name == "Turn (left)" and by_start["20"].id == "turn-2"
|
|
492
|
+
assert by_start["5"].name == "Turn" and by_start["5"].id not in {"turn", "turn-2", "kick"}
|
|
493
|
+
assert by_start["0"].id == "turn"
|
|
494
|
+
assert len({s.id for s in merged.steps}) == 4
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
def test_repeats_without_times_keep_their_positional_ids():
|
|
498
|
+
"""With no span to tell occurrences apart, the merge matches by id as before."""
|
|
499
|
+
committed = _repeats([("Turn", 0), ("Turn", 20)])
|
|
500
|
+
for step in committed.steps:
|
|
501
|
+
step.spans = []
|
|
502
|
+
fresh = committed.model_copy(deep=True)
|
|
503
|
+
assert [s.id for s in merge_regenerated(committed, fresh).steps] == ["turn", "turn-2"]
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
def _ids(doc) -> list[str]:
|
|
507
|
+
out = []
|
|
508
|
+
|
|
509
|
+
def walk(steps):
|
|
510
|
+
for s in steps:
|
|
511
|
+
out.append(s.id)
|
|
512
|
+
walk(s.steps)
|
|
513
|
+
|
|
514
|
+
walk(doc.steps)
|
|
515
|
+
return out
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
def test_repeat_identity_never_makes_two_steps_one_id():
|
|
519
|
+
"""paces#58 review: a step named "Turn 2" holds the id a second Turn would
|
|
520
|
+
take; a nested repeat must not take its parent's id; and ids stay unique."""
|
|
521
|
+
committed = _repeats([("Turn", 0), ("Turn", 20)]) # turn, turn-2
|
|
522
|
+
fresh = _repeats([("Turn 2", 10), ("Turn", 0), ("Turn", 20)]) # turn-2, turn, turn-3
|
|
523
|
+
merged = merge_regenerated(committed, fresh)
|
|
524
|
+
ids = _ids(merged)
|
|
525
|
+
assert len(ids) == len(set(ids)), ids
|
|
526
|
+
assert {str(s.spans[0].start): s.id for s in merged.steps}["20"] == "turn-2"
|
|
527
|
+
|
|
528
|
+
parent = _repeats([("Turn", 0)])
|
|
529
|
+
nested = _repeats([("Turn", 0)])
|
|
530
|
+
nested.steps[0].steps = _repeats([("Turn", 1), ("Turn", 2)]).steps # ids turn, turn-2
|
|
531
|
+
nested.steps[0].steps[0].id, nested.steps[0].steps[1].id = "turn-2", "turn-3"
|
|
532
|
+
ids = _ids(merge_regenerated(parent, nested))
|
|
533
|
+
assert len(ids) == len(set(ids)), ids
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
def test_repeat_identity_reads_time_order_not_list_order():
|
|
537
|
+
committed = _repeats([("Turn", 0), ("Turn", 20)])
|
|
538
|
+
committed.steps.reverse() # [turn-2 @20, turn @0]
|
|
539
|
+
merged = merge_regenerated(committed, _repeats([("Turn", 0), ("Turn", 20)]))
|
|
540
|
+
assert {str(s.spans[0].start): s.id for s in merged.steps} == {"0": "turn", "20": "turn-2"}
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
def test_a_renamed_repeat_and_a_cue_on_it_stay_with_their_occurrence():
|
|
544
|
+
"""An ``/id`` rename (``turn-2`` -> ``my-turn``) keeps to the Turn at 20 s
|
|
545
|
+
when a Turn is inserted earlier, and a fresh cue anchored to the fresh id
|
|
546
|
+
of that Turn is re-anchored with it."""
|
|
547
|
+
from paces.model import Anchor, Cue
|
|
548
|
+
|
|
549
|
+
committed = apply_edits(
|
|
550
|
+
_repeats([("Turn", 0), ("Kick", 10), ("Turn", 20)]),
|
|
551
|
+
[{"op": "set", "path": "/steps/turn-2/id", "value": "my-turn"}],
|
|
552
|
+
by="user:thor",
|
|
553
|
+
)
|
|
554
|
+
fresh = _repeats([("Turn", 0), ("Turn", 5), ("Kick", 10), ("Turn", 20)])
|
|
555
|
+
fresh.cues = [Cue(id="clap", kind="count", text="clap", anchor=Anchor(step="turn-3"))]
|
|
556
|
+
merged = merge_regenerated(committed, fresh)
|
|
557
|
+
by_start = {str(s.spans[0].start): s.id for s in merged.steps}
|
|
558
|
+
assert by_start["20"] == "my-turn" and by_start["5"] not in {"my-turn", "turn"}
|
|
559
|
+
assert merged.cues[0].anchor.step == "my-turn"
|
|
560
|
+
|
|
561
|
+
|
|
562
|
+
def test_unnamed_steps_keep_their_place_ids():
|
|
563
|
+
committed = _repeats([("", 0), ("", 10)])
|
|
564
|
+
fresh = _repeats([("", 0), ("", 5), ("", 10)])
|
|
565
|
+
assert _ids(merge_regenerated(committed, fresh)) == _ids(fresh)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|