Spaces:
Running
Running
Download tests/test_bench_fold_tile.py from WINTER4000/syntheogenesis: direct link, hf CLI and curl.
- Browser
- Download file 4.09 kB
-
https://huggingface.co/spaces/WINTER4000/syntheogenesis/resolve/main/tests/test_bench_fold_tile.py
- Command line
-
hf download hf://spaces/WINTER4000/syntheogenesis/tests/test_bench_fold_tile.py
-
curl -L -o test_bench_fold_tile.py https://huggingface.co/spaces/WINTER4000/syntheogenesis/resolve/main/tests/test_bench_fold_tile.py
4.09 kB
| """The bench header's specimen tile is the project's protein, turning. | |
| It was a fixed glyph — the same curve on every project — in the one place on | |
| the bench that names what you are working on. It is now Mission Control's | |
| fold (structcard.js: the AlphaFold model's alpha-carbon trace in pLDDT | |
| colours) on a slow turntable. These tests pin the parts that keep it honest | |
| and cheap: the same drawing code as the cards, only a real accession gets a | |
| fold, the view is framed on the confidently-modelled core, and the animation | |
| stops when nobody can see it. | |
| """ | |
| import pathlib | |
| import re | |
| from _frontend import app_js | |
| _ROOT = pathlib.Path(__file__).resolve().parents[1] | |
| def _read(rel): | |
| return (_ROOT / rel).read_text(encoding="utf-8") | |
| def _setthumb(): | |
| app = app_js() | |
| body = app[app.index("function setThumb(id)"):] | |
| return body[:body.index("\n }\n")] | |
| def test_the_tile_uses_mission_controls_own_fold_drawing(): | |
| sc = _read("dee/static/structcard.js") | |
| assert "spin: spin" in sc and "stop: stopSpin" in sc | |
| # Same fetch, same colours: spin goes through fetchTrace and plddtColor. | |
| spin = sc[sc.index("function spin(canvas, accession)"):] | |
| assert "fetchTrace(acc)" in spin | |
| frame = sc[sc.index("function spinFrame"):sc.index("function spinModel")] | |
| assert "plddtColor(" in frame | |
| assert "window.TDStructCard.spin(cv, a)" in _setthumb() | |
| def test_only_a_real_accession_gets_a_fold(): | |
| """structcard.js's rule: never a squiggle that could pass for a structure.""" | |
| fn = _setthumb() | |
| assert "const ACC_OK = /^[A-Z0-9]{6,10}$/;" in app_js() | |
| assert "if (ACC_OK.test(acc)) { turn(acc); return; }" in fn | |
| assert "/api/structure/resolve?gene=" in fn, "the same resolver the cards use" | |
| assert "THUMB_GLYPH" in fn and "glyph();" in fn, "no accession keeps the plain glyph" | |
| assert ".then((ok) => { if (!ok) glyph(); })" in fn, "a failed fetch falls back" | |
| def test_the_view_is_framed_on_the_confident_core(): | |
| """HLA-A's ~70-residue disordered tail shrank the domain to a speck.""" | |
| sc = _read("dee/static/structcard.js") | |
| model = sc[sc.index("function spinModel"):sc.index("function stopSpin")] | |
| assert "trace.plddt[i] >= 70" in model | |
| assert "project(trace.pts, core)" in model | |
| assert "if (core.length < 20) core = trace.pts;" in model | |
| def test_it_costs_nothing_when_nobody_can_see_it(): | |
| sc = _read("dee/static/structcard.js") | |
| spin = sc[sc.index("function spin(canvas, accession)"):sc.index("/* Lazy paint.")] | |
| assert "reducedMotion()" in spin, "prefers-reduced-motion draws one still frame" | |
| assert "document.hidden" in spin | |
| assert "IntersectionObserver" in spin | |
| assert "if (!canvas.isConnected) { stopSpin(canvas); return; }" in spin | |
| assert "stopSpin(canvas);" in spin.split("if (!ACC_RE.test(acc))")[0], ( | |
| "a second spin on the same canvas must end the first") | |
| def test_the_tile_follows_the_project_and_the_name(): | |
| app = app_js() | |
| opener = app[app.index("function openConstruct(c)"):] | |
| opener = opener[:opener.index("\n }\n")] | |
| assert "setThumb({ acc: current.uniprot || st.acc" in opener, ( | |
| "the project's recorded structure decides the tile on open") | |
| update = app[app.index(" function update(patch)"):] | |
| update = update[:update.index("\n }\n")] | |
| assert "setThumb({ acc: patch.uniprot" in update | |
| close = app[app.index(" function close() {\n if (window.TDProject) window.TDProject.park();"):] | |
| assert "setThumb(null)" in close[:400], "closing the bench stops the turntable" | |
| cockpit = _read("dee/static/cockpit.js") | |
| name = cockpit[cockpit.index("function nameConstruct()"):] | |
| name = name[:name.index("\n }\n")] | |
| assert 'uniprot: state.ident.uniprot || ""' in name | |
| def test_the_tile_is_drawn_from_the_design_tokens(): | |
| css = _read("dee/static/app.css") | |
| rule = re.search(r"\.bench-spec-thumb\.has-fold \{(.*?)\}", css, re.S).group(1) | |
| assert "var(--r-3)" in rule and "var(--bg-subtle)" in rule and "var(--line)" in rule | |
| assert "44px" in rule, "the 56px strip leaves room for 44" | |