Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/prometheus_client/utils.py: 25%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

28 statements  

1import math 

2from typing import Union 

3 

4INF = float("inf") 

5MINUS_INF = float("-inf") 

6NaN = float("NaN") 

7 

8 

9def floatToGoString(d): 

10 d = float(d) 

11 if d == INF: 

12 return '+Inf' 

13 elif d == MINUS_INF: 

14 return '-Inf' 

15 elif math.isnan(d): 

16 return 'NaN' 

17 else: 

18 s = repr(d) 

19 dot = s.find('.') 

20 # Go switches to exponents sooner than Python. 

21 # We only need to care about positive values for le/quantile. 

22 if d > 0 and dot > 6: 

23 mantissa = f'{s[0]}.{s[1:dot]}{s[dot + 1:]}'.rstrip('0.') 

24 return f'{mantissa}e+0{dot - 1}' 

25 return s 

26 

27 

28def parse_version(version_str: str) -> tuple[Union[int, str], ...]: 

29 version: list[Union[int, str]] = [] 

30 for part in version_str.split('.'): 

31 try: 

32 version.append(int(part)) 

33 except ValueError: 

34 version.append(part) 

35 

36 return tuple(version)