mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-09-17 18:50:11 +02:00
metadata: auto-convert YAML special float values: .nan .inf -.inf
Even for people who know what the special floats not-a-number, infinity, and negative infinity, they don't necessarily know the YAML 1.2 syntax for these. I didn't. And I've spent some quality time fighting things with those values. They are also easy to reliably convert to string values.
This commit is contained in:
parent
8374842faa
commit
9f606d0fbb
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
import git
|
import git
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import math
|
||||||
import platform
|
import platform
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
@ -897,6 +898,14 @@ def _normalize_type_string(v):
|
|||||||
if v:
|
if v:
|
||||||
return 'true'
|
return 'true'
|
||||||
return 'false'
|
return 'false'
|
||||||
|
if isinstance(v, float):
|
||||||
|
# YAML 1.2 values for NaN, Inf, and -Inf
|
||||||
|
if math.isnan(v):
|
||||||
|
return '.nan'
|
||||||
|
if math.isinf(v):
|
||||||
|
if v > 0:
|
||||||
|
return '.inf'
|
||||||
|
return '-.inf'
|
||||||
return str(v)
|
return str(v)
|
||||||
|
|
||||||
|
|
||||||
|
@ -965,6 +965,24 @@ class MetadataTest(unittest.TestCase):
|
|||||||
{'AntiFeatures': {'true': {}}},
|
{'AntiFeatures': {'true': {}}},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_parse_yaml_app_antifeatures_float_nan(self):
|
||||||
|
self.assertEqual(
|
||||||
|
metadata.parse_yaml_metadata(io.StringIO('AntiFeatures: .nan')),
|
||||||
|
{'AntiFeatures': {'.nan': {}}},
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_parse_yaml_app_antifeatures_float_inf(self):
|
||||||
|
self.assertEqual(
|
||||||
|
metadata.parse_yaml_metadata(io.StringIO('AntiFeatures: .inf')),
|
||||||
|
{'AntiFeatures': {'.inf': {}}},
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_parse_yaml_app_antifeatures_float_negative_inf(self):
|
||||||
|
self.assertEqual(
|
||||||
|
metadata.parse_yaml_metadata(io.StringIO('AntiFeatures: -.inf')),
|
||||||
|
{'AntiFeatures': {'-.inf': {}}},
|
||||||
|
)
|
||||||
|
|
||||||
def test_parse_yaml_app_antifeatures_int(self):
|
def test_parse_yaml_app_antifeatures_int(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
metadata.parse_yaml_metadata(io.StringIO('AntiFeatures: 1')),
|
metadata.parse_yaml_metadata(io.StringIO('AntiFeatures: 1')),
|
||||||
|
Loading…
Reference in New Issue
Block a user