Completed
Pull Request — master (#872)
by
unknown
01:32
created

test_doc_differentiates()   A

Complexity

Conditions 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 2
dl 0
loc 8
rs 9.4286
1
from copy import copy, deepcopy
2
from pickle import loads, dumps
3
from unittest import TestCase
4
from weakref import ref
5
6
from zipline.utils.sentinel import sentinel
7
8
9
class SentinelTestCase(TestCase):
10
    def tearDown(self):
11
        sentinel._cache.clear()  # don't pollute cache.
12
13
    def test_name(self):
14
        self.assertEqual(sentinel('a').__name__, 'a')
15
16
    def test_doc(self):
17
        self.assertEqual(sentinel('a', 'b').__doc__, 'b')
18
19
    def test_doc_differentiates(self):
20
        a = sentinel('sentinel-name', 'original-doc')
21
        with self.assertRaises(ValueError) as e:
22
            sentinel(a.__name__, 'new-doc')
23
24
        msg = str(e.exception)
25
        self.assertIn(a.__name__, msg)
26
        self.assertIn(a.__doc__, msg)
27
28
    def test_memo(self):
29
        self.assertIs(sentinel('a'), sentinel('a'))
30
31
    def test_copy(self):
32
        a = sentinel('a')
33
        self.assertIs(copy(a), a)
34
35
    def test_deepcopy(self):
36
        a = sentinel('a')
37
        self.assertIs(deepcopy(a), a)
38
39
    def test_repr(self):
40
        self.assertEqual(
41
            repr(sentinel('a')),
42
            "sentinel('a')",
43
        )
44
45
    def test_new(self):
46
        with self.assertRaises(TypeError):
47
            type(sentinel('a'))()
48
49
    def test_pickle_roundtrip(self):
50
        a = sentinel('a')
51
        self.assertIs(loads(dumps(a)), a)
52
53
    def test_weakreferencable(self):
54
        ref(sentinel('a'))
55