necoherence 0.2.1__tar.gz → 0.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {necoherence-0.2.1 → necoherence-0.2.2}/PKG-INFO +1 -1
- {necoherence-0.2.1 → necoherence-0.2.2}/pyproject.toml +1 -1
- {necoherence-0.2.1 → necoherence-0.2.2}/src/necoherence/signature_values.py +28 -2
- {necoherence-0.2.1 → necoherence-0.2.2}/tests/test_lean_value_decisions.py +65 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/.gitignore +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/LICENSE +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/README-ja.md +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/README.md +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/examples/01_fold_arithmetic.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/examples/02_recurse_gcd.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/examples/03_closure_reachability.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/src/necoherence/__init__.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/src/necoherence/call.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/src/necoherence/core.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/src/necoherence/dynamic_admission.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/src/necoherence/files.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/src/necoherence/iteration.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/src/necoherence/network_effect.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/src/necoherence/reconcile.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/src/necoherence/record.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/src/necoherence/request_progression.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/src/necoherence/signature_support.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/src/necoherence/store.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/src/necoherence/transition.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/src/necoherence/type_signatures.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/tests/test_call.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/tests/test_core.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/tests/test_default_materialization.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/tests/test_dynamic_admission.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/tests/test_examples.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/tests/test_files.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/tests/test_format_rule_inclusion.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/tests/test_iteration.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/tests/test_mutation_detection.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/tests/test_network_effect.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/tests/test_network_effect_progression.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/tests/test_profile_artifact_admission.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/tests/test_profile_predicate_vectors.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/tests/test_profile_wire_vectors.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/tests/test_reconcile.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/tests/test_record.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/tests/test_recursive_values.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/tests/test_representation_acceptance.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/tests/test_request_progression.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/tests/test_semantic_discriminator.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/tests/test_semantic_grapheme.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/tests/test_store.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/tests/test_transition.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/tests/test_type_signatures.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/tests/test_wrapper_base64_vectors.py +0 -0
- {necoherence-0.2.1 → necoherence-0.2.2}/tests/v4_samples.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: necoherence
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: Revision-aware state transition utilities for Python
|
|
5
5
|
Project-URL: Homepage, https://github.com/barineco/necoherence
|
|
6
6
|
Project-URL: Repository, https://github.com/barineco/necoherence
|
|
@@ -21,6 +21,11 @@ class DecimalLiteral:
|
|
|
21
21
|
spelling: str
|
|
22
22
|
|
|
23
23
|
def __post_init__(self):
|
|
24
|
+
if not isinstance(self.spelling, str) or re.fullmatch(
|
|
25
|
+
r"-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?",
|
|
26
|
+
self.spelling,
|
|
27
|
+
) is None:
|
|
28
|
+
raise ValueError("invalid decimal literal")
|
|
24
29
|
try:
|
|
25
30
|
value = Decimal(self.spelling)
|
|
26
31
|
except InvalidOperation as error:
|
|
@@ -978,10 +983,31 @@ class ValueContext:
|
|
|
978
983
|
def _validate_data(self, reference, value, path, trace):
|
|
979
984
|
def reject(condition, observed=value, at=path):
|
|
980
985
|
raise ValueFailure(reference, at, condition, observed, trace)
|
|
981
|
-
if type(value) is int
|
|
986
|
+
if type(value) is int:
|
|
982
987
|
_, failure = _integer_value(self.profile, {}, value)
|
|
983
988
|
if failure:
|
|
984
|
-
reject("IntegerDomain"
|
|
989
|
+
reject("IntegerDomain")
|
|
990
|
+
elif isinstance(value, (float, DecimalLiteral, Decimal)):
|
|
991
|
+
text = value.spelling if isinstance(value, DecimalLiteral) else str(value)
|
|
992
|
+
if re.fullmatch(r"-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?", text) is None:
|
|
993
|
+
reject("InvalidDataModel")
|
|
994
|
+
decimal_value = Decimal(text)
|
|
995
|
+
if not decimal_value.is_finite():
|
|
996
|
+
reject("InvalidDataModel")
|
|
997
|
+
default_name = self.profile.get("default_integer_domain")
|
|
998
|
+
binding = _named(self.profile.get("integer_domains", ()), default_name)
|
|
999
|
+
integral_form = binding is not None and "IntegralDecimal" in {
|
|
1000
|
+
_unit(form) for form in binding.get("forms", ())
|
|
1001
|
+
}
|
|
1002
|
+
if integral_form and decimal_value == decimal_value.to_integral_value():
|
|
1003
|
+
domain = binding.get("range", {"tag": "Unbounded"})
|
|
1004
|
+
if sum_tag(domain) == "Inclusive":
|
|
1005
|
+
bounds = payload(domain)
|
|
1006
|
+
if decimal_value < Decimal(integer(bounds["minimum"])) or decimal_value > Decimal(integer(bounds["maximum"])):
|
|
1007
|
+
reject("IntegerDomain")
|
|
1008
|
+
return
|
|
1009
|
+
if not self.profile.get("numbers", {}).get("decimals", False):
|
|
1010
|
+
reject("InvalidDataModel")
|
|
985
1011
|
elif type(value) is str:
|
|
986
1012
|
if not _unicode_scalar_text(value):
|
|
987
1013
|
reject("InvalidDataModel")
|
|
@@ -124,3 +124,68 @@ def test_element_contract_null_is_decided_by_nullable_or_child_type():
|
|
|
124
124
|
assert context.validate("unknown-map-required", {"x": None}) == {"x": None}
|
|
125
125
|
with pytest.raises(ValueFailure):
|
|
126
126
|
context.validate("integer-map-required", {"x": None})
|
|
127
|
+
@pytest.mark.parametrize("value", [1.25, -1.25, 6.02e23])
|
|
128
|
+
def test_unknown_any_accepts_profile_admitted_decimals(value):
|
|
129
|
+
graph = representative_graph()
|
|
130
|
+
graph["profile"]["integer_domains"][0]["forms"] = [variant("Number")]
|
|
131
|
+
context = ValueContext(graph)
|
|
132
|
+
assert context.validate("unknown-any", value) == value
|
|
133
|
+
assert context.validate("unknown-array-required", [value]) == [value]
|
|
134
|
+
assert context.validate("unknown-map-required", {"nested": [value]}) == {"nested": [value]}
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def test_unknown_any_integral_decimal_precedes_decimal_admission():
|
|
138
|
+
from necoherence.signature_values import DecimalLiteral
|
|
139
|
+
|
|
140
|
+
graph = representative_graph()
|
|
141
|
+
graph["profile"]["integer_domains"][0]["range"] = variant("Inclusive", fields={"minimum": "-10", "maximum": "10"})
|
|
142
|
+
context = ValueContext(graph)
|
|
143
|
+
assert context.validate("unknown-any", DecimalLiteral("1.0")) == DecimalLiteral("1.0")
|
|
144
|
+
assert context.validate("unknown-any", DecimalLiteral("1.25")) == DecimalLiteral("1.25")
|
|
145
|
+
with pytest.raises(ValueFailure) as caught:
|
|
146
|
+
context.validate("unknown-any", DecimalLiteral("11.0"))
|
|
147
|
+
assert caught.value.condition == "IntegerDomain"
|
|
148
|
+
with pytest.raises(ValueFailure) as caught:
|
|
149
|
+
context.validate("unknown-any", DecimalLiteral("1e999999"))
|
|
150
|
+
assert caught.value.condition == "IntegerDomain"
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def test_unknown_any_rejects_decimals_when_profile_disables_them():
|
|
154
|
+
graph = representative_graph()
|
|
155
|
+
graph["profile"]["numbers"]["decimals"] = False
|
|
156
|
+
graph["profile"]["integer_domains"][0]["range"] = variant("Inclusive", fields={"minimum": "-10", "maximum": "10"})
|
|
157
|
+
context = ValueContext(graph)
|
|
158
|
+
from necoherence.signature_values import DecimalLiteral
|
|
159
|
+
|
|
160
|
+
assert context.validate("unknown-any", DecimalLiteral("10.0")) == DecimalLiteral("10.0")
|
|
161
|
+
with pytest.raises(ValueFailure) as caught:
|
|
162
|
+
context.validate("unknown-any", DecimalLiteral("11.0"))
|
|
163
|
+
assert caught.value.condition == "IntegerDomain"
|
|
164
|
+
for value in (1.25, -1.25):
|
|
165
|
+
with pytest.raises(ValueFailure) as caught:
|
|
166
|
+
context.validate("unknown-any", value)
|
|
167
|
+
assert caught.value.condition == "InvalidDataModel"
|
|
168
|
+
with pytest.raises(ValueFailure) as caught:
|
|
169
|
+
context.validate("unknown-any", 6.02e23)
|
|
170
|
+
assert caught.value.condition == "IntegerDomain"
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
@pytest.mark.parametrize("text", ["01.2", "1.", "1e", "+1.0"])
|
|
174
|
+
def test_unknown_any_rejects_malformed_decimal_json(text):
|
|
175
|
+
from necoherence.signature_values import decode_wire_json
|
|
176
|
+
|
|
177
|
+
with pytest.raises(ValueError):
|
|
178
|
+
decode_wire_json(text)
|
|
179
|
+
|
|
180
|
+
from necoherence.signature_values import DecimalLiteral
|
|
181
|
+
|
|
182
|
+
for text in ("01.2", "1.", "1e", "+1.0", "NaN", "Infinity"):
|
|
183
|
+
with pytest.raises(ValueError):
|
|
184
|
+
DecimalLiteral(text)
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
@pytest.mark.parametrize("value", [float("nan"), float("inf")])
|
|
188
|
+
def test_unknown_any_rejects_non_json_native_floats(value):
|
|
189
|
+
with pytest.raises(ValueFailure) as caught:
|
|
190
|
+
ValueContext(representative_graph()).validate("unknown-any", value)
|
|
191
|
+
assert caught.value.condition == "InvalidDataModel"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|