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_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]
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
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]
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]
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'}