Beispiel #1
0
    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), )
        )
Beispiel #2
0
 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
             }), )
         )
Beispiel #3
0
 def test_right_identity_law(self, l):
     assert l.and_then(lambda v: List([v])) == l
Beispiel #4
0
 def test_left_identity_law(self, v, f):
     assert List([v]).and_then(f) == f(v)
Beispiel #5
0
 def test_inequality(self, first, second):
     assume(first != second)
     assert List(first) != List(second)
Beispiel #6
0
 def test_equality(self, t):
     assert List(t) == List(t)
Beispiel #7
0
 def test_right_append_identity_law(self, l):
     assert l + List() == l
Beispiel #8
0
 def test_reduce(self, l):
     i = sum(l)
     assert List(l).reduce(lambda a, b: a + b, 0) == i
Beispiel #9
0
 def test_zip(self, l1, l2):
     assert List(l1.zip(l2)) == List(zip(l1, l2))
Beispiel #10
0
def test_pfun_nested_list():
    l = List([List([-1])])
    assert lens()[0][0](1)(l) == List([List([1])])
    assert l == List([List([-1])])
Beispiel #11
0
def test_pfun_list_index_error():
    l = List([])
    with pytest.raises(IndexError):
        lens()[0]('')(l)
Beispiel #12
0
def test_pfun_list_root():
    l = List([-1])
    assert lens()[0](1)(l) == List([1])
    assert l == List([-1])
Beispiel #13
0
def test_pfun_list_immutable_attribute():
    x = ImmutableClass(List([0]))
    assert lens().attribute[0](1)(x) == ImmutableClass(List([1]))
    assert x == ImmutableClass(List([0]))
Beispiel #14
0
def test_pfun_list_attribute():
    x = VanillaClass(List([0]))
    assert lens().attribute[0](1)(x).attribute == List([1])
    assert x.attribute == List([0])
Beispiel #15
0
 def test_reverse(self, l):
     assert List(l).reverse() == List(reversed(l))
Beispiel #16
0
    def test_filter(self, l):
        def p(v):
            return id(v) % 2 == 0

        assert List(l).filter(p) == List(builtins.filter(p, l))
Beispiel #17
0
 def test_empty(self):
     assert List().empty() == List()
Beispiel #18
0
 def test_flatten(self, maybe_list):
     assert flatten(maybe_list) == List(m.get for m in maybe_list if m)
Beispiel #19
0
 def test_left_append_identity_law(self, l):
     assert List() + l == l