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

test_weakreferencable()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 2
rs 10
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
        self.assertIsNot(sentinel('a', 'b'), sentinel('a', 'c'))
21
22
    def test_memo(self):
23
        self.assertIs(sentinel('a'), sentinel('a'))
24
25
    def test_copy(self):
26
        a = sentinel('a')
27
        self.assertIs(copy(a), a)
28
29
    def test_deepcopy(self):
30
        a = sentinel('a')
31
        self.assertIs(deepcopy(a), a)
32
33
    def test_repr(self):
34
        self.assertEqual(
35
            repr(sentinel('a')),
36
            "sentinel('a')",
37
        )
38
39
    def test_new(self):
40
        with self.assertRaises(TypeError):
41
            type(sentinel('a'))()
42
43
    def test_pickle_roundtrip(self):
44
        a = sentinel('a')
45
        self.assertIs(loads(dumps(a)), a)
46
47
    def test_weakreferencable(self):
48
        ref(sentinel('a'))
49