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_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')
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({})})
def test_pfun_dict_root(): d = Dict({}) assert lens()['key']('value')(d) == Dict({'key': 'value'}) assert d == Dict({})
def test_pfun_dict_attribute(): x = VanillaClass(Dict({})) assert lens().attribute['key']('value')(x).attribute == Dict( {'key': 'value'}) assert x.attribute == Dict({})