def test_as_type(self): class User(Immutable): name: str age: int results = List((Dict({'name': 'bob', 'age': 32}), )) assert sql.as_type(User)(results).run(None) == List( (User('bob', 32), ) )
def test_fetch(self): with asynctest.patch('pfun.sql.asyncpg.connect') as connect_mock: connect_mock.return_value.close = asynctest.CoroutineMock() connect_mock.return_value.fetch = asynctest.CoroutineMock( return_value=({ 'name': 'bob', 'age': 32 }, ) ) assert sql.fetch('select * from users').run(HasSQL()) == List( (Dict({ 'name': 'bob', 'age': 32 }), ) )
def test_right_identity_law(self, l): assert l.and_then(lambda v: List([v])) == l
def test_left_identity_law(self, v, f): assert List([v]).and_then(f) == f(v)
def test_inequality(self, first, second): assume(first != second) assert List(first) != List(second)
def test_equality(self, t): assert List(t) == List(t)
def test_right_append_identity_law(self, l): assert l + List() == l
def test_reduce(self, l): i = sum(l) assert List(l).reduce(lambda a, b: a + b, 0) == i
def test_zip(self, l1, l2): assert List(l1.zip(l2)) == List(zip(l1, l2))
def test_pfun_nested_list(): l = List([List([-1])]) assert lens()[0][0](1)(l) == List([List([1])]) assert l == List([List([-1])])
def test_pfun_list_index_error(): l = List([]) with pytest.raises(IndexError): lens()[0]('')(l)
def test_pfun_list_root(): l = List([-1]) assert lens()[0](1)(l) == List([1]) assert l == List([-1])
def test_pfun_list_immutable_attribute(): x = ImmutableClass(List([0])) assert lens().attribute[0](1)(x) == ImmutableClass(List([1])) assert x == ImmutableClass(List([0]))
def test_pfun_list_attribute(): x = VanillaClass(List([0])) assert lens().attribute[0](1)(x).attribute == List([1]) assert x.attribute == List([0])
def test_reverse(self, l): assert List(l).reverse() == List(reversed(l))
def test_filter(self, l): def p(v): return id(v) % 2 == 0 assert List(l).filter(p) == List(builtins.filter(p, l))
def test_empty(self): assert List().empty() == List()
def test_flatten(self, maybe_list): assert flatten(maybe_list) == List(m.get for m in maybe_list if m)
def test_left_append_identity_law(self, l): assert List() + l == l