Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_broken_handler(self):
dumper = datadumper.Dumper()
dumper.handlers.insert(0, (lambda v: 'a' + v is None, lambda l, v: None))
with self.assertRaises(TypeError):
dumper.dump(1)
dumper.raiseconditionerrors = False
assert dumper.dump(1) == 1
def test_dumpdefault(self):
dumper = datadumper.Dumper()
attrplugin.add2dumper(dumper)
dumper.hidedefault = False
assert dumper.dump(Person()) == {'name': 'Turiddu', 'address': None}
def test_dump_iterables(self):
dumper = datadumper.Dumper()
assert dumper.dump([1]) == [1]
assert dumper.dump((1, 2)) == [1, 2]
assert dumper.dump([(1, 1), (0, 0)]) == [[1, 1], [0, 0]]
assert dumper.dump({1, 2}) == [1, 2]
def dump(value: Any, **kwargs) -> Any:
"""
Quick function to dump a data structure into
something that is compatible with json or
other programs and languages.
It is useful to avoid creating the Dumper object,
in case only the default parameters are used.
"""
from . import datadumper
dumper = datadumper.Dumper(**kwargs)
return dumper.dump(value)