def test_valueConstructorOrEnv(self): l = [10] c1 = from_list(l) assert c1.type_out() == Type.get(int) assert c1.setup((), lambda x: None) with pytest.raises(TypeError) as excinfo: c1.setup((l, ), lambda x: None) assert "type" in str(excinfo.value) c2 = from_list(item_type=int) assert c2.type_out() == Type.get(int) with pytest.raises(TypeError) as excinfo: c2.setup((), lambda x: None) assert "type" in str(excinfo.value) assert c2.setup((l, ), lambda x: None)
def test_valueConstructorOrEnv(self): num = 10 c1 = const(num) assert c1.type_out() == Type.get(int) assert c1.setup((), lambda x: None) == [num, 0] with pytest.raises(TypeError) as excinfo: c1.setup((num, ), lambda x: None) assert "type" in str(excinfo.value) c2 = const(value_type=int) assert c2.type_out() == Type.get(int) with pytest.raises(TypeError) as excinfo: c2.setup((), lambda x: None) assert "value" in str(excinfo.value) assert c2.setup((num, ), lambda x: None) == [num, 0]
def __init__(self): # As with the producer, we need to specify the types of the processor. # As we do not want to restrict on the upstream type, we use a type # variable: _any = Type.get() # init type, result tyoe and consumed type. super(Prints, self).__init__(str, int, _any)
lc = to_list() sp = lp >> dict_values >> lc res = sp.run()[0] print(res) assert ("a", "b") in res assert ("c.d", "e") in res # This is how we get the values we need to replace: we take a string, # turn it to json, search for the placeholders and join this with # our custom dict_values transformation. get_values = tee() >> to_json * search("{{([^}]+)}}") >> dict_values assert get_values.type_in() == Type.get(str) assert get_values.type_out() == Type.get([(str, str)]) example = {"a": "b", "b": "{{a}}", "c": {"d": "e"}, "e": "{{c.d}}"} lp = from_list([json.dumps(example)]) sp = lp >> get_values >> lc res = sp.run()[0] print(res) assert ("a", "b") in res assert ("c.d", "e") in res # We need to expand the keys a to {{a}} to get a map of replacements.
def pi_any2(): tvar = Type.get() return MockPipe(tvar, tvar)
def co_any(): return MockConsumer(Type.get(), 10)
def test_PrStrCombPiAny(self, pr_str, pi_any): pr = pr_str >> pi_any assert pr.type_out() == Type.get(str)
def __init__(self): # We need to pass an init type, an upstream type and a downstream type _any = Type.get() super(Echo, self).__init__(int, _any, _any)
def test_typeOut(self, pipe): assert pipe.type_out() == Type.get(pipe.type_in(), pipe.type_in())
def test_complexTypeOut(self): p = from_list([([10], "foo")]) assert p.type_out() == Type.get([int], str)