MCPcopy
hub / github.com/pallets/werkzeug / test_basic_interface

Method test_basic_interface

tests/test_datastructures.py:595–634  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

593 storage_class = ds.CombinedMultiDict
594
595 def test_basic_interface(self):
596 d1 = ds.MultiDict([("foo", "1")])
597 d2 = ds.MultiDict([("bar", "2"), ("bar", "3")])
598 d = self.storage_class([d1, d2])
599
600 # lookup
601 assert d["foo"] == "1"
602 assert d["bar"] == "2"
603 assert d.getlist("bar") == ["2", "3"]
604
605 assert sorted(d.items()) == [("bar", "2"), ("foo", "1")]
606 assert sorted(d.items(multi=True)) == [("bar", "2"), ("bar", "3"), ("foo", "1")]
607 assert "missingkey" not in d
608 assert "foo" in d
609
610 # type lookup
611 assert d.get("foo", type=int) == 1
612 assert d.getlist("bar", type=int) == [2, 3]
613
614 # get key errors for missing stuff
615 with pytest.raises(KeyError):
616 d["missing"]
617
618 # make sure that they are immutable
619 with pytest.raises(TypeError):
620 d["foo"] = "blub"
621
622 # copies are mutable
623 d = d.copy()
624 d["foo"] = "blub"
625
626 # make sure lists merges
627 md1 = ds.MultiDict((("foo", "bar"), ("foo", "baz")))
628 md2 = ds.MultiDict((("foo", "blafasel"),))
629 x = self.storage_class((md1, md2))
630 assert list(x.lists()) == [("foo", ["bar", "baz", "blafasel"])]
631
632 # make sure dicts are created properly
633 assert x.to_dict() == {"foo": "bar"}
634 assert x.to_dict(flat=False) == {"foo": ["bar", "baz", "blafasel"]}
635
636 def test_length(self):
637 d1 = ds.MultiDict([("foo", "1")])

Callers

nothing calls this directly

Calls 7

to_dictMethod · 0.80
listFunction · 0.50
getlistMethod · 0.45
itemsMethod · 0.45
getMethod · 0.45
copyMethod · 0.45
listsMethod · 0.45

Tested by

no test coverage detected