def test_complex_value(self): value = { "root": { "foo": 1234, "bar": [True, None, {"nestedString": "value", "nestedArray": [92747, "test"]}, [False]], "foobar": "foobar", } } expected = """ root.foo: 1234 root.bar: [ 0: true 1: null 2: nestedString: "value" nestedArray: [ 0: 92747 1: "test" ] 3: [ 0: false ] ] root.foobar: "foobar" """ expected = expected.replace("[", self._left_square_bracket) expected = expected.replace("]", self._right_square_bracket) expected = expected.replace(":", self._colon) self.assertEqual(expected, format_json(value))
def test_non_empty_object(self): value = {"path": {"to": {"foo": "foo"}}, "longPath": {"to": {"bar": "bar"}}} expected = """ path.to.foo: "foo" longPath.to.bar: "bar" """ expected = expected.replace(":", self._colon) self.assertEqual(expected, format_json(value))
def test_leaf(self): test_data = ( ("null", None), ("true", True), ("false", False), ("42", 42), ("42.12345", 42.12345), ('"foo"', "foo"), ("{}", {}), ("[]", []), ) for expected, value in test_data: with self.subTest(expected=expected, value=value): self.assertEqual(expected, format_json(value))
def test_non_empty_array(self): value = [x for x in range(11)] expected = """[ 0: 0 1: 1 2: 2 3: 3 4: 4 5: 5 6: 6 7: 7 8: 8 9: 9 10: 10 ]""" expected = expected.replace("[", self._left_square_bracket) expected = expected.replace("]", self._right_square_bracket) expected = expected.replace(":", self._colon) self.assertEqual(expected, format_json(value))