|
5 | 5 | # Licensed under a 3-clause BSD style license (see LICENSE)
|
6 | 6 | import json
|
7 | 7 | import logging
|
| 8 | +import math |
8 | 9 | import os
|
9 | 10 | import re
|
10 | 11 | from typing import Any # noqa: F401
|
@@ -50,6 +51,39 @@ def test_load_config():
|
50 | 51 | AgentCheck.load_config(':')
|
51 | 52 |
|
52 | 53 |
|
| 54 | +def test_parse_special_values_in_load_config(): |
| 55 | + assert AgentCheck.load_config("boolean: true") == {"boolean": True} |
| 56 | + assert AgentCheck.load_config("boolean: false") == {"boolean": False} |
| 57 | + |
| 58 | + assert AgentCheck.load_config("number: .inf") == {"number": float("inf")} |
| 59 | + assert AgentCheck.load_config("number: .INF") == {"number": float("inf")} |
| 60 | + |
| 61 | + assert AgentCheck.load_config("number: -.inf") == {"number": float("-inf")} |
| 62 | + assert AgentCheck.load_config("number: -.INF") == {"number": float("-inf")} |
| 63 | + |
| 64 | + assert AgentCheck.load_config("number: 0xF") == {"number": 15.0} # Hexadecimal |
| 65 | + assert AgentCheck.load_config("number: 0b1111") == {"number": 15.0} # Binary |
| 66 | + |
| 67 | + assert AgentCheck.load_config("number: !!int 1 ") == {"number": 1} |
| 68 | + assert isinstance(AgentCheck.load_config("number: !!int 1 ")["number"], int) |
| 69 | + |
| 70 | + assert AgentCheck.load_config("number: !!float 1 ") == {"number": 1} |
| 71 | + assert isinstance(AgentCheck.load_config("number: !!float 1 ")["number"], float) |
| 72 | + |
| 73 | + # Check that "inf" is still a string |
| 74 | + assert AgentCheck.load_config("string: inf") == {"string": "inf"} |
| 75 | + assert isinstance(AgentCheck.load_config("string: inf")["string"], str) |
| 76 | + |
| 77 | + # Check that quoted ".inf" is still a string |
| 78 | + assert AgentCheck.load_config("string: \".inf\"") == {"string": ".inf"} |
| 79 | + assert isinstance(AgentCheck.load_config("string: \".inf\"")["string"], str) |
| 80 | + |
| 81 | + # nan values are not equal to themselves |
| 82 | + config = AgentCheck.load_config("number: .nan") |
| 83 | + assert "number" in config |
| 84 | + assert math.isnan(config["number"]) |
| 85 | + |
| 86 | + |
53 | 87 | def test_persistent_cache(datadog_agent):
|
54 | 88 | check = AgentCheck()
|
55 | 89 | check.check_id = 'test'
|
|
0 commit comments