Skip to content
Open
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
2 changes: 1 addition & 1 deletion ogcore/model_variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@
"type": "array-like",
"TPI dimensions": "",
"SS dimensions": "J",
"label": "Replacement rate ($\theta_j$)",
"label": "Replacement rate ($\\theta_j$)",
"toGDP_label": ""
},
"factor": {
Expand Down
25 changes: 25 additions & 0 deletions tests/test_constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
Tests of constants.py module and the label metadata loaded from
model_variables.json.
"""

from ogcore import constants


def test_labels_have_no_control_characters():
r"""
Guard against LaTeX label strings in model_variables.json being
written with a single backslash (e.g. "$\theta$"), which JSON parses
into a control character (a tab, in the case of "\t") and which then
fails to render in plots. Backslashes must be escaped ("$\\theta$").
"""
control_chars = set("\t\r\n\x08\x0c\x0b")
for label_map in (constants.VAR_LABELS, constants.ToGDP_LABELS):
for key, label in label_map.items():
assert isinstance(label, str)
bad = control_chars.intersection(label)
assert not bad, (
f"Label for {key!r} contains control character(s) "
f"{[c.encode('unicode_escape').decode() for c in bad]}: "
f"{label!r}. Escape backslashes in model_variables.json."
)