File: test_util.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 (45 lines) | stat: -rw-r--r-- 1,242 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
37
38
39
40
41
42
43
44
45
"""
Tests for L{eliot._util}.
"""

from unittest import TestCase
import pprint

from .._util import load_module


class LoadModuleTests(TestCase):
    """
    Tests for L{load_module}.
    """

    maxDiff = None

    def test_returns_module(self):
        """
        L{load_module} returns an object with same methods as original module.
        """
        loaded = load_module(str("copy"), pprint)
        obj = [1, 2, b"hello"]
        self.assertEqual(loaded.pformat(obj), pprint.pformat(obj))

    def test_name(self):
        """
        L{load_module} returns an object with the given name.
        """
        name = str("my_copy")
        loaded = load_module(name, pprint)
        self.assertEqual(loaded.__name__, name)

    def test_distinct_from_original(self):
        """
        L{load_module} returns a distinct object from the original module.
        """
        loaded = load_module(str("copy"), pprint)
        # Override repr in copy:
        loaded.repr = lambda o: str("OVERRIDE")
        # Demonstrate that override applies to copy but not original:
        self.assertEqual(
            dict(original=pprint.pformat(123), loaded=loaded.pformat(123)),
            dict(original="123", loaded="OVERRIDE"),
        )