|
5 | 5 |
|
6 | 6 | import json as _json |
7 | 7 |
|
8 | | -from plotly.utils import PlotlyJSONEncoder, get_by_path, memoize, node_generator |
| 8 | +from plotly.utils import PlotlyJSONEncoder, get_by_path, node_generator |
9 | 9 |
|
10 | 10 |
|
11 | 11 | class TestJSONEncoder(TestCase): |
@@ -48,98 +48,3 @@ def test_node_generator(self): |
48 | 48 | ] |
49 | 49 | for i, item in enumerate(node_generator(node0)): |
50 | 50 | self.assertEqual(item, expected_node_path_tuples[i]) |
51 | | - |
52 | | - |
53 | | -class TestMemoizeDecorator(TestCase): |
54 | | - |
55 | | - # In Python 2.x, globals should be module-scoped. By defining and |
56 | | - # instantiating a class, we *access* the global first before attempting |
57 | | - # to update a value. I.e., you *cannot* simply mutate the global value |
58 | | - # on it's own. |
59 | | - class Namespace(object): |
60 | | - pass |
61 | | - |
62 | | - def test_memoize(self): |
63 | | - name_space = self.Namespace() |
64 | | - name_space.call_count = 0 |
65 | | - |
66 | | - @memoize() |
67 | | - def add(a, b): |
68 | | - name_space.call_count += 1 |
69 | | - return a + b |
70 | | - |
71 | | - tests = [[(1, 1), 2], [(2, 3), 5], [(3, -3), 0]] |
72 | | - |
73 | | - self.assertEqual(name_space.call_count, 0) |
74 | | - for i, (inputs, result) in enumerate(tests, 1): |
75 | | - for _ in range(10): |
76 | | - self.assertEqual(add(*inputs), result) |
77 | | - self.assertEqual(name_space.call_count, i) |
78 | | - |
79 | | - def test_memoize_maxsize(self): |
80 | | - name_space = self.Namespace() |
81 | | - name_space.call_count = 0 |
82 | | - |
83 | | - maxsize = 10 |
84 | | - |
85 | | - @memoize(maxsize=maxsize) |
86 | | - def identity(a): |
87 | | - name_space.call_count += 1 |
88 | | - return a |
89 | | - |
90 | | - # Function hasn't been called yet, we should get *up to* maxsize cache. |
91 | | - for i in range(maxsize): |
92 | | - self.assertEqual(identity(i), i) |
93 | | - self.assertEqual(name_space.call_count, i + 1) |
94 | | - |
95 | | - # Nothing should have been discarded yet. no additional calls. |
96 | | - for i in range(maxsize): |
97 | | - self.assertEqual(identity(i), i) |
98 | | - self.assertEqual(name_space.call_count, maxsize) |
99 | | - |
100 | | - # Make a new call... |
101 | | - self.assertEqual(identity(maxsize), maxsize) |
102 | | - self.assertEqual(name_space.call_count, maxsize + 1) |
103 | | - |
104 | | - # All but the first call should be remembered. |
105 | | - for i in range(1, maxsize + 1): |
106 | | - self.assertEqual(identity(i), i) |
107 | | - self.assertEqual(name_space.call_count, maxsize + 1) |
108 | | - |
109 | | - # The *initial* call should now be forgotten for each new call. |
110 | | - for i in range(maxsize): |
111 | | - self.assertEqual(identity(i), i) |
112 | | - self.assertEqual(name_space.call_count, maxsize + 1 + i + 1) |
113 | | - |
114 | | - def test_memoize_maxsize_none(self): |
115 | | - name_space = self.Namespace() |
116 | | - name_space.call_count = 0 |
117 | | - |
118 | | - @memoize(maxsize=None) |
119 | | - def identity(a): |
120 | | - name_space.call_count += 1 |
121 | | - return a |
122 | | - |
123 | | - # Function hasn't been called yet, we should get *up to* maxsize cache. |
124 | | - for i in range(400): |
125 | | - self.assertEqual(identity(i), i) |
126 | | - self.assertEqual(name_space.call_count, i + 1) |
127 | | - |
128 | | - # Nothing should have been discarded. no additional calls. |
129 | | - for i in range(400): |
130 | | - self.assertEqual(identity(i), i) |
131 | | - self.assertEqual(name_space.call_count, 400) |
132 | | - |
133 | | - def test_memoize_function_info(self): |
134 | | - # We use the decorator module to assure that function info is not |
135 | | - # overwritten by the decorator. |
136 | | - |
137 | | - @memoize() |
138 | | - def foo(a, b, c="see?"): |
139 | | - """Foo is foo.""" |
140 | | - pass |
141 | | - |
142 | | - self.assertEqual(foo.__doc__, "Foo is foo.") |
143 | | - self.assertEqual(foo.__name__, "foo") |
144 | | - self.assertEqual(getargspec(foo).args, ["a", "b", "c"]) |
145 | | - self.assertEqual(getargspec(foo).defaults, ("see?",)) |
0 commit comments