How to use the typedload.datadumper.Dumper 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_datetime(self):
        dumper = datadumper.Dumper()
        assert dumper.dump(datetime.date(2011, 12, 12)) == [2011, 12, 12]
        assert dumper.dump(datetime.time(15, 41)) == [15, 41, 0, 0]
        assert dumper.dump(datetime.datetime(2019, 5, 31, 12, 44, 22)) == [2019, 5, 31, 12, 44, 22, 0]
github ltworf / typedload / tests / test_datadumper.py View on Github external
def test_custom_handler(self):
        class Q:
            def __eq__(self, other):
                return isinstance(other, Q)

        dumper = datadumper.Dumper()
        dumper.handlers.append((
            lambda v: isinstance(v, Q),
            lambda l, v: 12
        ))
        assert dumper.dump(Q()) == 12
github ltworf / typedload / tests / test_datadumper.py View on Github external
def test_dump_enums(self):
        dumper = datadumper.Dumper()
        assert dumper.dump(EnumA.A) == 1
        assert dumper.dump(EnumA.B) == '2'
        assert dumper.dump(EnumA.C) == [1, 2]
github ltworf / typedload / tests / test_datadumper.py View on Github external
def test_dump_set(self):
        dumper = datadumper.Dumper()
        assert dumper.dump(set(range(3))) == [0, 1, 2]
        assert dumper.dump(frozenset(range(3))) == [0, 1, 2]
github ltworf / typedload / tests / test_datadumper.py View on Github external
def test_dump_namedtuple(self):
        dumper = datadumper.Dumper()
        assert dumper.dump(NamedA(1, 'a')) == {'a': 1, 'b': 'a'}
        assert dumper.dump(NamedA(1, 'a', 'yes')) == {'a': 1, 'b': 'a', 'c': 'yes'}

        dumper.hidedefault = False
        assert dumper.dump(NamedA(1, 'a')) == {'a': 1, 'b': 'a', 'c': 'no'}