def test_init(): lst = List[Int]([1, 2, 3]) assert client.is_delayed(lst) assert lst.params == () assert interpreter.interpret( lst.graft, builtins={"wf.list": lambda *args: list(args)})() == [1, 2, 3]
def test_init_sequence(): b = parameter("b", Bool) tup = Tuple[Int, Str, Int, Bool]([1, "foo", 3, b]) assert client.is_delayed(tup) assert tup.params == (b,) assert interpreter.interpret( tup.graft, builtins={"wf.tuple": lambda *tuple: tuple, b._name: True} )() == (1, "foo", 3, True)
def test_init_iterable(): seq = [1, "foo", 3] def generator(): for x in seq: yield x tup = Tuple[Int, Str, Int](generator()) assert client.is_delayed(tup)
def test_init_kwargs(self): with pytest.raises(TypeError, match="Parameter foo=1 has a default value."): Function[{"foo": Int}, Int](lambda foo=1: foo) func = Function[{"foo": Int}, Int](lambda foo: foo) assert client.is_delayed(func) interpreted_func = interpreter.interpret(func.graft) assert interpreted_func(1) == 1 assert interpreted_func(foo=1) == 1
def test_init_fromkwargs(mock_apply): dct = Dict[Str, Int](a=1, b=2, c=3) apply_args, apply_kwargs = mock_apply.call_args assert apply_args == ("dict.create", ) assert six.viewkeys(apply_kwargs) == {"a", "b", "c"} for value in six.itervalues(apply_kwargs): assert isinstance(value, Int) assert client.is_delayed(dct) assert interpreter.interpret(dct.graft, builtins={"dict.create": dict_builtin})() == dict(a=1, b=2, c=3)
def test_init_fromdict(mock_apply): dct = Dict[Int, Float]({1: 1.1, 2: 2.2}) apply_args, apply_kwargs = mock_apply.call_args assert apply_args[0] == "dict.create" assert len(apply_kwargs) == 0 for (key_item, value_item) in iter_argpairs(apply_args[1:]): assert isinstance(key_item, Int) assert isinstance(value_item, Float) assert client.is_delayed(dct) assert interpreter.interpret(dct.graft, builtins={"dict.create": dict_builtin})() == { 1: 1.1, 2: 2.2 }
def test_init(): b = parameter("b", Str) c = parameter("c", Int) struct = Struct[{ "a": Int, "b": Str, "c": Int, "d": Str }](a=1, b=b, c=c, d=b) assert client.is_delayed(struct) assert struct.params == (b, c) assert isinstance(struct._items_cache["a"], Int) assert isinstance(struct._items_cache["b"], Str) assert isinstance(struct._items_cache["c"], Int) assert isinstance(struct._items_cache["d"], Str)
def test_init_fromdict_andkwargs(mock_apply): dct = Dict[Str, Int]({"a": 0, "z": 100}, a=1, b=2, c=3) apply_args, apply_kwargs = mock_apply.call_args assert apply_args == ("wf.dict.create", ) assert six.viewkeys(apply_kwargs) == {"a", "z", "b", "c"} for value in six.itervalues(apply_kwargs): assert isinstance(value, Int) assert client.is_delayed(dct) assert dct.params == () assert interpreter.interpret(dct.graft, builtins={"wf.dict.create": dict_builtin})() == { "a": 1, "z": 100, "b": 2, "c": 3 }
def test_init_sequence(): tup = Tuple[Int, Str, Int]([1, "foo", 3]) assert client.is_delayed(tup) assert interpreter.interpret(tup.graft, builtins={"wf.tuple": lambda *tuple: tuple })() == (1, "foo", 3)
def test_init(): struct = Struct[{"a": Int, "b": Str}](a=1, b="foo") assert client.is_delayed(struct) assert isinstance(struct._items_cache["a"], Int) assert isinstance(struct._items_cache["b"], Str)
def test_init_callable(self): func = Function[{}, Int](lambda: 1) assert client.is_delayed(func) interpreted_func = interpreter.interpret(func.graft) assert interpreted_func() == 1