Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
848 changes: 424 additions & 424 deletions app/public/data/populations.json

Large diffs are not rendered by default.

848 changes: 424 additions & 424 deletions data/populations.json

Large diffs are not rendered by default.

74 changes: 37 additions & 37 deletions data/uk/ab2025_measures.json

Large diffs are not rendered by default.

13 changes: 3 additions & 10 deletions pipeline/build_ab2025_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import gzip
import json
import re
import sys
from pathlib import Path

Expand All @@ -40,8 +39,10 @@

# Keep the pinned traversal shared with the event-parametrised replay builder.
try:
from pipeline.name_search import name_search as _name_search
from pipeline.uk_engine_registry import engine_dumps as _engine_dumps
except ModuleNotFoundError: # direct script invocation without PYTHONPATH
from name_search import name_search as _name_search
from uk_engine_registry import engine_dumps as _engine_dumps


Expand Down Expand Up @@ -106,15 +107,7 @@ def r10(x):


def ns(pattern):
rx = re.compile(pattern, re.I)
ph = [p for p in P if rx.search(p) and not p.startswith("baseline.")]
vh = [v for v in V if rx.search(v)]
return (
f"Searched BOTH the parameter tree and the VARIABLE list for /{pattern}/. "
f"Parameters: {len(ph)} node(s) {ph[:6]}. Variables: {len(vh)} {vh[:6]}. "
"Both are searched because a parameter-only search misses a variable "
f"(#106). Re-run at policyengine-uk {PIN}."
)
return _name_search(pattern, P, V, PIN)


UPSTREAM = {
Expand Down
21 changes: 21 additions & 0 deletions pipeline/name_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""The name-search string a UK measure registry records for a search pattern.

Pure: it takes the engine's parameter paths and variable names as given, so
tests run it without policyengine-uk installed.
"""

import re


def name_search(pattern, parameters, variables, pin):
rx = re.compile(pattern, re.I)
ph = [p for p in parameters if rx.search(p) and not p.startswith("baseline.")]
# policyengine-core adds variables in glob order, which differs by
# filesystem, so we sort them.
vh = sorted(v for v in variables if rx.search(v))
return (
f"Searched BOTH the parameter tree and the VARIABLE list for /{pattern}/. "
f"Parameters: {len(ph)} node(s) {ph[:6]}. Variables: {len(vh)} {vh[:6]}. "
"Both are searched because a parameter-only search misses a variable "
f"(#106). Re-run at policyengine-uk {pin}."
)
2 changes: 1 addition & 1 deletion tests/fixtures/uk_replay_ab2025_hashes.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,5 +203,5 @@
"results/uk/ab2025/ab2025_option__vat_main_rate_20_to_21_reduced_5_to_6_zero_rated_1pct_2029.json": "ad21653ae722ae38a84b9b3c5ba895e3c2b788004c70844878eb4f8d9eedf089",
"results/uk/ab2025/ab2025_option__vat_main_rate_20_to_21_reduced_5_to_6_zero_rated_1pct_2030.json": "6053ae1387be2b5ec31534c2d0adf8a8928ce9cae8470a262f9b94418edaa172",
"results/uk/staged_ab2025/ab2025_counterparts.jsonl": "dadce5fec5a9bd254338d1b7794e1db2c7a1ad9dd0626f21b8c353967b801213",
"data/uk/ab2025_measures.json": "08b8dbb15a76f3e4b5bfb15e1580935eccac2ebd0e91dbe5cd8a516eb191ece7"
"data/uk/ab2025_measures.json": "a37e8a73c5f0664bb7ade2a90df841ed058f57357a61e179aecd4c62485f228b"
}
34 changes: 34 additions & 0 deletions tests/test_name_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""A registry's name search must not depend on the engine's variable order.

policyengine-core adds variables in glob order, which differs by filesystem,
so build_ab2025_registry.py --check fails wherever that order differs unless
the search text reads the same for every ordering of the variable list.
"""

from hypothesis import given
from hypothesis import strategies as st

from pipeline.name_search import name_search

NAMES = st.lists(
st.text(alphabet="abc_", min_size=1, max_size=6), min_size=0, max_size=30
)


@given(
variables=NAMES.flatmap(lambda vs: st.tuples(st.just(vs), st.permutations(vs))),
parameters=NAMES,
pattern=st.sampled_from(["a", "b", "c", "_", "a|b", "^a", "c$"]),
)
def test_name_search_reads_the_same_for_any_variable_order(
variables, parameters, pattern
):
original, permuted = variables
assert name_search(pattern, parameters, original, "2.89.2") == name_search(
pattern, parameters, permuted, "2.89.2"
)


def test_name_search_lists_the_first_six_variables_in_sorted_order():
text = name_search("x", [], ["x9", "x1", "x8", "x2", "x7", "x3", "x6"], "2.89.2")
assert "Variables: 7 ['x1', 'x2', 'x3', 'x6', 'x7', 'x8']." in text
Loading