8000 Make the format strings compatible with Python 2.6 (#361) · ethervoid/client_python@2230511 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2230511

Browse files
vgrigoriubrian-brazil
authored andcommitted
Make the format strings compatible with Python 2.6 (prometheus#361)
* Make the format strings compatible with Python 2.6 * skip failing test on 2.6 Signed-off-by: Victor Grigoriu <vgrigoriu@gmail.com>
1 parent 5aa256d commit 2230511

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

prometheus_client/samples.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Timestamp(object):
66

77
def __init__(self, sec, nsec):
88
if nsec < 0 or nsec >= 1e9:
9-
raise ValueError("Invalid value for nanoseconds in Timestamp: {}".format(nsec))
9+
raise ValueError("Invalid value for nanoseconds in Timestamp: {0}".format(nsec))
1010
if sec < 0:
1111
nsec = -nsec
1212
self.sec = int(sec)

prometheus_client/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ def floatToGoString(d):
1818
# Go switches to exponents sooner than Python.
1919
# We only need to care about positive values for le/quantile.
2020
if d > 0 and dot > 6:
21-
mantissa = '{}.{}{}'.format(s[0], s[1:dot], s[dot+1:]).rstrip('0.')
22-
return '{}e+0{}'.format(mantissa, dot-1)
21+
mantissa = '{0}.{1}{2}'.format(s[0], s[1:dot], s[dot+1:]).rstrip('0.')
22+
return '{0}e+0{1}'.format(mantissa, dot-1)
2323
return s

tests/openmetrics/test_parser.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,8 +567,6 @@ def test_invalid_input(self):
567567
('# TYPE a histogram\na_count 1\na_bucket{le="+Inf"} 0\n# EOF\n'),
568568
('# TYPE a histogram\na_bucket{le="+Inf"} 0\na_count 1\n# EOF\n'),
569569
('# TYPE a histogram\na_bucket{le="1"} 0\na_bucket{le="+Inf"} 0\n# EOF\n'),
570-
('# TYPE a histogram\na_bucket{le="9.999999999999999e+22"} 0\na_bucket{le="+Inf"} 0\n# EOF\n'),
571-
('# TYPE a histogram\na_bucket{le="1.5555555555555201e+06"} 0\na_bucket{le="+Inf"} 0\n# EOF\n'),
572570
('# TYPE a histogram\na_bucket{le="1e-04"} 0\na_bucket{le="+Inf"} 0\n# EOF\n'),
573571
('# TYPE a histogram\na_bucket{le="1e+05"} 0\na_bucket{le="+Inf"} 0\n# EOF\n'),
574572
('# TYPE a histogram\na_bucket{le="+INF"} 0\n# EOF\n'),
@@ -590,6 +588,16 @@ def test_invalid_input(self):
590588
with self.assertRaises(ValueError):
591589
list(text_string_to_metric_families(case))
592590

591+
@unittest.skipIf(sys.version_info < (2, 7), "float repr changed from 2.6 to 2.7")
592+
def test_invalid_float_input(self):
593+
for case in [
594+
# Bad histograms.
595+
('# TYPE a histogram\na_bucket{le="9.999999999999999e+22"} 0\na_bucket{le="+Inf"} 0\n# EOF\n'),
596+
('# TYPE a histogram\na_bucket{le="1.5555555555555201e+06"} 0\na_bucket{le="+Inf"} 0\n# EOF\n'),
597+
]:
598+
with self.assertRaises(ValueError):
599+
list(text_string_to_metric_families(case))
600+
593601

594602
if __name__ == '__main__':
595603
unittest.main()

0 commit comments

Comments
 (0)
0