This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
catfish/tests/test_utils/test_logfmt.py
Jake Howard af45867376
Add custom logfmt parser based off python-logfmt
This specifically doesn't add quotes where they're not necessary
2018-12-21 15:37:42 +00:00

58 lines
1.8 KiB
Python

from catfish.utils.logfmt import logfmt
from tests import BaseTestCase
class LogFmtTestCase(BaseTestCase):
def test_simple_logfmt(self):
self.assertEqual(
logfmt({"key1": "value1", "key2": "value2"}), "key1=value1 key2=value2"
)
def test_quotes_space(self):
self.assertEqual(
logfmt({"key1": "value1 valuea", "key2": "value2 valueb"}),
'key1="value1 valuea" key2="value2 valueb"',
)
def test_quotes_equals(self):
self.assertEqual(
logfmt({"key1": "value1=valuea", "key2": "value2=valueb"}),
'key1="value1=valuea" key2="value2=valueb"',
)
def test_quotes_quotes(self):
self.assertEqual(
logfmt({"key1": '"value1"', "key2": '"value2"'}),
'key1="\\"value1\\"" key2="\\"value2\\""',
)
self.assertEqual(
logfmt({"key1": "'value1'", "key2": "'value2'"}),
"key1=\"'value1'\" key2=\"'value2'\"",
)
def test_empty(self):
self.assertEqual(logfmt({}), "")
def test_boolean_values(self):
self.assertEqual(logfmt({"key1": True, "key2": False}), "key1=true key2=false")
def test_none_values(self):
self.assertEqual(logfmt({"key1": None, "key2": None}), "key1= key2=")
def test_numbers(self):
self.assertEqual(
logfmt({"key1": 12345, "key2": -12345}), "key1=12345 key2=-12345"
)
self.assertEqual(
logfmt({"key1": "12345", "key2": "-12345"}), "key1=12345 key2=-12345"
)
def test_float(self):
self.assertEqual(
logfmt({"key1": 12345.67, "key2": -12345.67}),
"key1=12345.67 key2=-12345.67",
)
self.assertEqual(
logfmt({"key1": "12345.67", "key2": "-12345.67"}),
"key1=12345.67 key2=-12345.67",
)