askrobots / dbbasic-object-server
Public
Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.
package_pins.py · 1.6 KB · 34 lines
| 1 | """Assertions for what a package declares, written so an ADDITION cannot break them. |
| 2 | |
| 3 | A package test that says `forms.default.fields == [...]`, `dependencies == |
| 4 | [...]` or `schema["version"] == 3` fails the moment somebody adds a field, |
| 5 | a dependency or a version bump -- a green change turned red by a test that |
| 6 | was only ever meant to say "these are still here". That cost a usability |
| 7 | trial's authors a failing suite on a perfectly good addition (see "A |
| 8 | failing pin on a pure addition is a test bug" in docs/package-authoring.md). |
| 9 | |
| 10 | Use these for lists and versions a package may grow. Keep exact equality |
| 11 | for what must NOT change: a permission rule, a transition target set, a |
| 12 | hidden field, a money computation. Those are behaviour and security, and a |
| 13 | change there SHOULD fail until a person decides it is intended. |
| 14 | """ |
| 15 | |
| 16 | |
| 17 | def assert_includes_in_order(actual, expected): |
| 18 | """`expected` is a subsequence of `actual`: every member is present, and |
| 19 | the members keep the relative order the test names. Extra members, before, |
| 20 | between or after, are fine.""" |
| 21 | actual = list(actual) |
| 22 | remaining = iter(actual) |
| 23 | missing = [item for item in expected if item not in remaining] |
| 24 | assert not missing, ( |
| 25 | f"expected {list(expected)!r} to appear in this order within {actual!r}; " |
| 26 | f"missing or out of order from {missing[0]!r}") |
| 27 | |
| 28 | |
| 29 | def version_at_least(actual, minimum): |
| 30 | """A dotted version (`"0.6.0"`) is at least `minimum`, compared as numbers |
| 31 | so `0.10.0` is above `0.6.0`.""" |
| 32 | def parts(text): |
| 33 | return tuple(int(piece) for piece in str(text).split(".") if piece.isdigit()) |
| 34 | return parts(actual) >= parts(minimum) |