Skip to content

Commit

Permalink
Add checks for various other float formats.
Browse files Browse the repository at this point in the history
Check for new stuff Go added in 1.13, and also
make sure leading 0s are permitted as some users
want to be able to do fixed-size output.

Signed-off-by: Brian Brazil <brian.brazil@robustperception.io>
  • Loading branch information
brian-brazil committed Sep 5, 2019
1 parent dd59d9a commit 3eafa33
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/openmetrics/test_parser.py
Expand Up @@ -53,6 +53,22 @@ def test_float_gauge(self):
""")
self.assertEqual([GaugeMetricFamily("a", "help", value=1.2)], list(families))

def test_leading_zeros_simple_gauge(self):
families = text_string_to_metric_families("""# TYPE a gauge
# HELP a help
a 0000000000000000000000000000000000000000001
# EOF
""")
self.assertEqual([GaugeMetricFamily("a", "help", value=1)], list(families))

def test_leading_zeros_float_gauge(self):
families = text_string_to_metric_families("""# TYPE a gauge
# HELP a help
a 0000000000000000000000000000000000000000001.2e-1
# EOF
""")
self.assertEqual([GaugeMetricFamily("a", "help", value=.12)], list(families))

def test_nan_gauge(self):
families = text_string_to_metric_families("""# TYPE a gauge
# HELP a help
Expand Down Expand Up @@ -610,14 +626,25 @@ def test_invalid_input(self):
('a 1\n# EOF\n'),
('a 1\t\n# EOF\n'),
('a 1 \n# EOF\n'),
('a 1_2\n# EOF\n'),
('a 0x1p-3\n# EOF\n'),
('a 0x1P-3\n# EOF\n'),
('a 0b1\n# EOF\n'),
('a 0B1\n# EOF\n'),
('a 0x1\n# EOF\n'),
('a 0X1\n# EOF\n'),
('a 0o1\n# EOF\n'),
('a 0O1\n# EOF\n'),
# Bad timestamp.
('a 1 z\n# EOF\n'),
('a 1 1z\n# EOF\n'),
('a 1 1_2\n# EOF\n'),
('a 1 1.1.1\n# EOF\n'),
('a 1 NaN\n# EOF\n'),
('a 1 Inf\n# EOF\n'),
('a 1 +Inf\n# EOF\n'),
('a 1 -Inf\n# EOF\n'),
('a 1 0x1p-3\n# EOF\n'),
# Bad exemplars.
('# TYPE a histogram\na_bucket{le="+Inf"} 1 #\n# EOF\n'),
('# TYPE a histogram\na_bucket{le="+Inf"} 1# {} 1\n# EOF\n'),
Expand All @@ -627,6 +654,8 @@ def test_invalid_input(self):
('# TYPE a histogram\na_bucket{le="+Inf"} 1 # {} 1 1 \n# EOF\n'),
('# TYPE a histogram\na_bucket{le="+Inf"} 1 # '
'{a="2345678901234567890123456789012345678901234567890123456789012345"} 1 1\n# EOF\n'),
('# TYPE a histogram\na_bucket{le="+Inf"} 1 # {} 0x1p-3\n# EOF\n'),
('# TYPE a histogram\na_bucket{le="+Inf"} 1 # {} 1 0x1p-3\n# EOF\n'),
# Exemplars on unallowed samples.
('# TYPE a histogram\na_sum 1 # {a="b"} 0.5\n# EOF\n'),
('# TYPE a gaugehistogram\na_sum 1 # {a="b"} 0.5\n# EOF\n'),
Expand Down

0 comments on commit 3eafa33

Please sign in to comment.