Add paperspec correct, check math forms and datasets, and give the tools public names
The work the other paper tools planned for paperspec (paperdesk PLAN M5.4, paperform PLAN 4.2): - paperspec correct and paperspec.revision apply proposed corrections to a package, folder or zip, and write it only once it validates. - doc.math.form is checked: label and style commands always, the form's own spelling when papermath is installed or forms= is passed. - paperspec.datasets and seven doc.dataset.* rules check a package's datasets. - fixtures/invalid gains suspect-witness and math-form-label (33 in all). - Canonical JSON reads numbers as doubles, so 1e20 round-trips. - The registries and the JSON-LD context ship in the wheel. - Public names for what paperdesk and paperform imported as private ones, with the old names kept as aliases. - The text and lossy-projection functions are about three times faster through the gate, tested equal to the old code on every code point. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013XwDhn4LkrKQfw4ArDEr2E
This commit is contained in:
70 files changed
+4470
-270
No files matched your search
@@ -230,6 +230,37 @@ def test_loads_line_refuses_a_line_that_is_not_canonical(line):
|
||||
jcs.loads_line(line)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("x", [1e20, -1e20, 2.0**60, 123456789012345680000.0])
|
||||
def test_loads_line_reads_back_a_whole_double_beyond_2_53(x):
|
||||
# The canonical form of 1e20 is 100000000000000000000, an integer literal beyond 2^53,
|
||||
# which is read as the double it is (spec/01 §1.1), not refused.
|
||||
line = jcs.dumpb({"a": x})
|
||||
assert jcs.loads_line(line) == {"a": x}
|
||||
|
||||
|
||||
def test_loads_line_refuses_an_integer_beyond_2_53_that_is_no_double():
|
||||
with pytest.raises(ValueError, match="not canonical JSON"):
|
||||
jcs.loads_line(b"9007199254740993")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("text", ["NaN", "[Infinity]", '{"a":-Infinity}'])
|
||||
def test_loads_refuses_nan_and_the_infinities(text):
|
||||
with pytest.raises(ValueError, match="no canonical form"):
|
||||
jcs.loads(text)
|
||||
|
||||
|
||||
def test_loads_reads_numbers_as_doubles_without_requiring_canonical_text():
|
||||
assert jcs.loads('{ "b": 100000000000000000000, "a": 7 }') == {"a": 7, "b": 1e20}
|
||||
assert type(jcs.loads("100000000000000000000")) is float
|
||||
assert type(jcs.loads("9007199254740992")) is int
|
||||
|
||||
|
||||
@given(JSON_VALUES)
|
||||
@PROPERTIES
|
||||
def test_loads_line_reads_back_every_canonical_line(value):
|
||||
assert jcs.dumps(jcs.loads_line(jcs.dumpb(value))) == jcs.dumps(value)
|
||||
|
||||
|
||||
def test_loads_line_refuses_bytes_that_are_not_utf8():
|
||||
with pytest.raises(UnicodeDecodeError):
|
||||
jcs.loads_line(b'"\xff"')
|
||||
|
||||
Reference in new issue
Block a user