Best Python code snippet using uiautomator
testlib.py
Source:testlib.py
1import os2import tempfile3import errno4import virtualchain5import pybitcoin6from config import get_logger, get_bitcoin_regtest_opts7import name_service8from blockchain.session import get_bitcoind_connection9log = get_logger("testlib")10snapshots_dir = None11state_engine = None12class TestAPIProxy(object):13 def __init__(self):14 global utxo_opts15 client_path = os.environ.get("ZONEFILEMANAGE_CLIENT_CONFIG", None)16 assert client_path is not None17class Wallet(object):18 def __init__(self, pk_wif, ignored):19 pk = virtualchain.BitcoinPrivateKey(pk_wif)20 self._pk = pk21 if pk_wif.startswith("c"):22 #already a privkey23 self.privkey = pk_wif24 else:25 self.privkey = pk.to_wif()26 self.pubkey_hex = pk.public_key().to_hex()27 self.addr = pk.public_key().address()28 log.info("Wallet %s(%s)" % (self.privkey, self.addr))29class MultisigWallet(object):30 def __init__(self, m, *pks):31 self.privkey = virtualchain.make_multisig_info( m, pks )32 self.m = m33 self.n = len(pks)34 self.addr = self.privkey['address']35 log.info("Multisig wallet %s " % (self.addr))36def set_default_payment_wallet( w ):37 global default_payment_wallet38 default_payment_wallet = w39# set up for test environment40def set_utxo_opts( opts ):41 global utxo_opts42 utxo_opts = opts43def set_bitcoind( b ):44 global bitcoind45 bitcoind = b46def set_state_engine( s ):47 global state_eigine48 state_eigine = s49def next_block( **kw ):50 """51 Advance the mock blockchain by one block52 """53 global snapshots_dir, state_engine54 if snapshots_dir is None:55 snapshots_dir = tempfile.mkdtemp(prefix='zonefilemanage-test-databases-')56 # Flush all transactions and reset state engine57 kw['next_block_upcall']()58 kw['sync_virtualchain_upcall']()59def zonefilemanage_export_db(path, block_height, **kwargs):60 global state_engine61 try:62 state_engine.export_db(path + (".%s" % block_height))63 except IOError, ie:64 if ie.errno == errno.ENOENT:65 log.error("No such file or directory: %s" + path)66 pass67 else:68 raise69def zonefilemanage_name_register(name, privatekey, status = '0', consensus_hash = None, safety_checks = False):70 """71 Register a name72 """73 log.info("Register a name %s" % name)74 test_proxy = make_proxy()75 name_service.set_default_proxy(test_proxy)76 resp = name_service.do_name_register(status + name, privatekey,77 test_proxy, test_proxy, consensus_hash=consensus_hash,78 proxy=test_proxy)79 return resp80def zonefilemanage_name_update(name, data_hash, privatekey, consensus_hash=None, safety_checks = False):81 """82 Update a name83 """84 log.info("Update a name %s, data_hash is %s" % (name, data_hash ))85 test_proxy = make_proxy()86 name_service.set_default_proxy(test_proxy)87 resp = name_service.do_name_update(name, data_hash, privatekey, test_proxy)88 return resp89def zonefilemanage_name_revoke(name, privatekey):90 """91 Revoke a name92 """93 log.info("Revoke a name %s" % name)94 test_proxy = make_proxy()95 name_service.set_default_proxy(test_proxy)96 resp = name_service.do_name_revoke(name, privatekey, test_proxy)97 return resp98def zonefilemanage_name_transfer(name, previous_privkey, change_privkey):99 """100 Transfer a name101 """102 log.info("Transfer a name %s" % name)103 test_proxy = make_proxy()104 name_service.set_default_proxy(test_proxy)105 resp = name_service.do_name_transfer(name, previous_privkey, change_privkey, test_proxy)106 return resp107def get_utxo_client():108 opts = get_bitcoin_regtest_opts()109 utxo_provider = pybitcoin.BitcoindClient(opts.get("bitcoind_user", None), opts.get("bitcoind_passwd"), \110 use_https=opts.get("bitcoind_use_https", None),server=opts.get("bitcoind_server", None),port=opts.get("bitcoind_port"), version_byte=virtualchain.version_byte)111 return utxo_provider112def make_proxy():113 proxy = get_utxo_client()...
test_jsproxy.py
Source:test_jsproxy.py
...3from ..tests.util import async_test4from ..jsproxy import Error, JSProxy5@async_test6async def test_proxy_attrs():7 proxy = test_proxy()8 eq(str(proxy), "JSProxy")9 eq(str(proxy.attr), "JSProxy.attr")10 eq(str(proxy.foo.bar), "JSProxy.foo.bar")11 eq(await proxy.attr, {"name": "attr", "root": "JSProxy"})12 eq(await proxy.foo.bar, {13 "name": "foo",14 "next": {"name": "bar"},15 "root": "JSProxy",16 })17@async_test18async def test_proxy_getitem():19 proxy = test_proxy()20 eq(str(proxy[0]), "JSProxy[0]")21 eq(str(proxy.attr[1]), "JSProxy.attr[1]")22 eq(await proxy[0], {"name": 0, "root": "JSProxy"})23 eq(await proxy.attr[1], {24 "name": "attr",25 "next": {"name": 1},26 "root": "JSProxy",27 })28@async_test29async def test_proxy_call():30 proxy = test_proxy()31 with assert_raises(TypeError, msg="JSProxy is not callable"):32 proxy()33 eq(str(proxy.call()), "JSProxy.call()")34 eq(str(proxy.attr.call(1)), "JSProxy.attr.call(1,)")35 eq(await proxy.call(), {"name": "call", "args": [], "root": "JSProxy"})36 eq(await proxy.attr.call(1), {37 "name": "attr",38 "next": {"name": "call", "args": [1]},39 "root": "JSProxy",40 })41@async_test42async def test_proxy_call_with_resolved_arg():43 proxy = test_proxy()44 eq(str(proxy.func(proxy.value)), "JSProxy.func(JSProxy.value,)")45 eq(await proxy.func(proxy.value), {"name": "func", "args": [46 {"name": "value", "__resolve__": True, "root": "JSProxy"}47 ], "root": "JSProxy"})48@async_test49async def test_proxy_error():50 proxy = test_proxy(ErrorServer())51 with assert_raises(Error, msg="something is wrong"):52 await proxy.attr53@nottest54def test_proxy(server=None):55 server = server or FakeServer()56 return JSProxy(server, root="JSProxy")57class FakeServer:58 @property59 def lsp(self):60 return self61 @staticmethod62 async def send_request_async(command, params):63 if command == "pyxt.resolve":64 eq(len(params), 1, params)65 return params[0]66 raise RuntimeError(f"unknown command: {command}")67class ErrorServer(FakeServer):68 @staticmethod...
test_aardvark.py
Source:test_aardvark.py
1# Named after an African nocturnal insectivore because for mysterious reasons these2# tests were failing if run towards the end of the test suite.3# def test_name_server(pyro_test_nameserver):4# # Check that it's running.5# assert pyro_test_nameserver.is_alive()6# def test_quantity_argument(test_proxy):7# test_proxy.quantity_argument(550 * u.nm)8# test_proxy.quantity_argument(1.21 * u.GW)9#10#11# def test_quantity_return(test_proxy):12# q = test_proxy.quantity_return()13# assert isinstance(q, u.Quantity)14# assert q == 42 * u.km * u.ng / u.Ms15#16#17# def test_builtin_exception(test_proxy):18# with pytest.raises(RuntimeError):19# test_proxy.raise_runtimeerror()20# with pytest.raises(AssertionError):21# test_proxy.raise_assertionerror()22#23#24# def test_pocs_exception(test_proxy):25# with pytest.raises(error.PanError):26# test_proxy.raise_panerror()27#28#29# def test_pocs_subclass(test_proxy):30# with pytest.raises(error.Timeout):31# test_proxy.raise_timeout()32# with pytest.raises(error.NotSupported):33# test_proxy.raise_notsupported()34# with pytest.raises(error.IllegalValue):35# test_proxy.raise_illegalvalue()36#37#38# def test_undeserialisable(test_proxy):39# with pytest.raises(Pyro4.errors.SerializeError):...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!