How to use the typedload.datadumper function in typedload

To help you get started, we’ve selected a few typedload examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ltworf / typedload / tests / test_datadumper.py View on Github external
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
github ltworf / typedload / tests / test_attrload.py View on Github external
def test_dumpdefault(self):
        dumper = datadumper.Dumper()
        attrplugin.add2dumper(dumper)
        dumper.hidedefault = False
        assert dumper.dump(Person()) == {'name': 'Turiddu', 'address': None}
github ltworf / typedload / tests / test_datadumper.py View on Github external
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]
github ltworf / typedload / typedload / __init__.py View on Github external
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)