MCPcopy Create free account
hub / github.com/dask/dask / test_dict_class

Function test_dict_class

dask/tests/test_task_spec.py:970–1031  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

968
969
970def test_dict_class():
971 t = Dict(k=Task("key-1", func, "a", "b"), v=Task("key-2", func, "c", "d"))
972 assert not t.dependencies
973 assert t() == {"k": "a-b", "v": "c-d"}
974 t2 = Dict({"k": Task("key-1", func, "a", "b"), "v": Task("key-2", func, "c", "d")})
975 assert t == t2
976 assert t() == t2()
977 t = Dict(k=Task("key-1", func, "a", TaskRef("b")), v=Task("key-2", func, "c", "d"))
978 assert t.dependencies == {"b"}
979 assert t({"b": "b"}) == {"k": "a-b", "v": "c-d"}
980
981 t = Dict(
982 {
983 "k": Task("key-1", func, "a", TaskRef("b")),
984 # Use a hashable key that isn't a string. This cannot be used as
985 # kwargs, for instance
986 ("v", 1): Task("key-2", func, "c", "d"),
987 }
988 )
989 assert t.dependencies == {"b"}
990 assert t({"b": "b"}) == {"k": "a-b", ("v", 1): "c-d"}
991
992 t = Dict(
993 k=Task("key-1", func, "a", "b"),
994 v=Task("key-2", func, "c", "d"),
995 )
996 t2 = Dict(
997 v=Task("key-2", func, "c", "d"),
998 k=Task("key-1", func, "a", "b"),
999 )
1000 assert t == t2
1001 assert tokenize(t) == tokenize(t2)
1002
1003 d = Dict(
1004 [
1005 ["k", Task("key-1", func, "a", TaskRef("b"))],
1006 ["v", Task("key-2", func, TaskRef("c"), "d")],
1007 ]
1008 )
1009 assert d.dependencies == {"c", "b"}
1010 assert d({"b": "b", "c": "c"}) == {"k": "a-b", "v": "c-d"}
1011
1012 d = Dict([("columns", ["a", "b"])])
1013 assert d() == {"columns": ["a", "b"]}
1014
1015 d = Dict([["columns", ["a", "b"]]])
1016 assert d() == {"columns": ["a", "b"]}
1017 # Can be converted to a dict, e.g. also used as **kwargs
1018 assert isinstance(t, Mapping)
1019 assert dict(t) == {
1020 "k": Task("key-1", func, "a", "b"),
1021 "v": Task("key-2", func, "c", "d"),
1022 }
1023 assert len(t) == len(dict(t)) == 2
1024
1025 def as_kwargs(**kwargs):
1026 return kwargs == {
1027 "k": Task("key-1", func, "a", "b"),

Callers

nothing calls this directly

Calls 5

DictClass · 0.90
TaskClass · 0.90
TaskRefClass · 0.90
tokenizeFunction · 0.90
as_kwargsFunction · 0.85

Tested by

no test coverage detected