8000 Improve tests, handle trailing space after value. · sxlstevengit/client_python@8f5ea53 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8f5ea53

Browse files
committed
Improve tests, handle trailing space after value.
Signed-off-by: Brian Brazil <brian.brazil@robustperception.io>
1 parent e325c66 commit 8f5ea53

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

prometheus_client/openmetrics/parser.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ def _parse_sample(text):
127127
else:
128128
timestamp.append(char)
129129

130+
# Trailing space after value.
131+
if state == 'timestamp' and not timestamp:
132+
raise ValueError("Invalid line: " + text)
133+
130134
if not value:
131135
raise ValueError("Invalid line: " + text)
132136
value = ''.join(value)

tests/openmetrics/__init__.py

Whitespace-only changes.

tests/openmetrics/test_parser.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,11 @@ def test_invalid_input(self):
373373
('0a 1\n# EOF\n'),
374374
('a.b 1\n# EOF\n'),
375375
('a-b 1\n# EOF\n'),
376+
# Bad value.
377+
('a a\n# EOF\n'),
378+
('a 1\n# EOF\n'),
379+
('a 1 \n# EOF\n'),
376380
# Bad timestamp.
377-
('a 1 1 \n# EOF\n'),
378381
('a 1 z\n# EOF\n'),
379382
('a 1 1z\n# EOF\n'),
380383
('a 1 1.1.1\n# EOF\n'),

0 commit comments

Comments
 (0)
0