MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_odict

Method test_odict

test/base/test_utils.py:135–179  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

133
134class OrderedDictTest(fixtures.TestBase):
135 def test_odict(self):
136 o = util.OrderedDict()
137 o["a"] = 1
138 o["b"] = 2
139 o["snack"] = "attack"
140 o["c"] = 3
141
142 eq_(list(o.keys()), ["a", "b", "snack", "c"])
143 eq_(list(o.values()), [1, 2, "attack", 3])
144
145 o.pop("snack")
146 eq_(list(o.keys()), ["a", "b", "c"])
147 eq_(list(o.values()), [1, 2, 3])
148
149 try:
150 o.pop("eep")
151 assert False
152 except KeyError:
153 pass
154
155 eq_(o.pop("eep", "woot"), "woot")
156
157 try:
158 o.pop("whiff", "bang", "pow")
159 assert False
160 except TypeError:
161 pass
162
163 eq_(list(o.keys()), ["a", "b", "c"])
164 eq_(list(o.values()), [1, 2, 3])
165
166 o2 = util.OrderedDict(d=4)
167 o2["e"] = 5
168
169 eq_(list(o2.keys()), ["d", "e"])
170 eq_(list(o2.values()), [4, 5])
171
172 o.update(o2)
173 eq_(list(o.keys()), ["a", "b", "c", "d", "e"])
174 eq_(list(o.values()), [1, 2, 3, 4, 5])
175
176 o.setdefault("c", "zzz")
177 o.setdefault("f", 6)
178 eq_(list(o.keys()), ["a", "b", "c", "d", "e", "f"])
179 eq_(list(o.values()), [1, 2, 3, 4, 5, 6])
180
181 def test_odict_constructor(self):
182 o = util.OrderedDict(

Callers

nothing calls this directly

Calls 6

eq_Function · 0.90
keysMethod · 0.45
valuesMethod · 0.45
popMethod · 0.45
updateMethod · 0.45
setdefaultMethod · 0.45

Tested by

no test coverage detected