Example #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), )
        )
Example #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
             }), )
         )
Example #3
0
def test_setitem(d):
    new_d = d.set('key', 'value')
    assert new_d == Dict(d).set('key', 'value')
    assert d != new_d
    assert 'key' not in d
    assert Dict({'key': 'value'}) == Dict().set('key', 'value')
Example #4
0
def test_nested_pfun_dict():
    d = Dict({'key': Dict({})})
    assert lens()['key']['key']('value')(d) == Dict(
        {'key': Dict({'key': 'value'})})
    assert d == Dict({'key': Dict({})})
Example #5
0
def test_pfun_dict_root():
    d = Dict({})
    assert lens()['key']('value')(d) == Dict({'key': 'value'})
    assert d == Dict({})
Example #6
0
def test_pfun_dict_attribute():
    x = VanillaClass(Dict({}))
    assert lens().attribute['key']('value')(x).attribute == Dict(
        {'key': 'value'})
    assert x.attribute == Dict({})