File: test_serializers.py

package info (click to toggle)
python-eliot 1.16.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 964 kB
  • sloc: python: 8,641; makefile: 151
file content (36 lines) | stat: -rw-r--r-- 885 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
Tests for L{eliot.serializers}.
"""

from unittest import TestCase
from datetime import datetime
from hashlib import md5

from ..serializers import timestamp, identity, md5hex


class SerializerTests(TestCase):
    """
    Tests for standard serializers.
    """

    def test_timestamp(self):
        """
        L{timestamp} converts a UTC L{datetime} to a Unicode strings.
        """
        dt = datetime(2012, 9, 28, 14, 53, 6, 123456)
        self.assertEqual(timestamp(dt), "2012-09-28T14:53:06.123456Z")

    def test_identity(self):
        """
        L{identity} returns the input object.
        """
        obj = object()
        self.assertIs(identity(obj), obj)

    def test_md5hex(self):
        """
        L{md5hex} returns the hex value of a MD5 checksum.
        """
        data = b"01234456789"
        self.assertEqual(md5hex(data), md5(data).hexdigest())