def test_echo_console(): """ Test EchoConsoleDoer class Must run in WindIDE with Debug I/O configured as external console """ port = os.ctermid() # default to console try: # check to see if running in external console fd = os.open(port, os.O_NONBLOCK | os.O_RDWR | os.O_NOCTTY) except OSError as ex: # maybe complain here return # not in external console else: os.close(fd) # cleanup tock = 0.03125 ticks = 16 limit = 0.0 # limit = ticks * tock doist = doing.Doist(tock=tock, real=True, limit=limit) assert doist.tyme == 0.0 # on next cycle assert doist.tock == tock == 0.03125 assert doist.real == True assert doist.limit == 0.0 # assert doist.limit == limit == 0.5 assert doist.doers == [] console = serialing.Console() echoer = serialing.EchoConsoleDoer(console=console) doers = [echoer] doist.do(doers=doers) # assert doist.tyme == limit assert console.opened == False
def runController(doers, expire=0.0): """ Utiitity Function to create doist to run doers """ tock = 0.03125 doist = doing.Doist(limit=expire, tock=tock, real=True) doist.do(doers=doers)
def test_wirelog_doer(): """ Test WireLogDoer class """ tock = 0.03125 ticks = 4 limit = ticks * tock doist = doing.Doist(tock=tock, real=True, limit=limit) assert doist.tyme == 0.0 # on next cycle assert doist.tock == tock == 0.03125 assert doist.real == True assert doist.limit == limit == 0.125 assert doist.doers == [] wl = wiring.WireLog(samed=True, temp=True) wiredoer = wiring.WireLogDoer(tymth=doist.tymen(), wl=wl) assert wiredoer.wl == wl assert wiredoer.tock == 0.0 # ASAP doers = [wiredoer] doist.do(doers=doers) assert doist.tyme == limit assert wiredoer.wl.opened == False """End Test """
def test_keeperdoer(): """ KeeperDoer """ keep0 = keeping.Keeper(name='test0', temp=True, reopen=False) assert keep0.opened == False assert keep0.path == None assert keep0.env == None kpDoer0 = keeping.KeeperDoer(keeper=keep0) assert kpDoer0.keeper == keep0 assert kpDoer0.keeper.opened == False keep1 = keeping.Keeper(name='test1', temp=True, reopen=False) assert keep1.opened == False assert keep1.path == None assert keep1.env == None kpDoer1 = keeping.KeeperDoer(keeper=keep1) assert kpDoer1.keeper == keep1 assert kpDoer1.keeper.opened == False limit = 0.25 tock = 0.03125 doist = doing.Doist(limit=limit, tock=tock) doers = [kpDoer0, kpDoer1] dogs = doist.ready(doers=doers) assert len(dogs) == 2 assert [val[1] for val in dogs] == [0.0, 0.0] # retymes for doer in doers: assert doer._tymist == doist assert doer.keeper.opened assert "_test/keri/keep/test" in doer.keeper.path doist.once(dogs) assert doist.tyme == 0.03125 # on next cycle assert len(dogs) == 2 for doer in doers: assert doer.keeper.opened == True for dog, retyme, index in dogs: dog.close() for doer in doers: assert doer.keeper.opened == False assert doer.keeper.env == None assert not os.path.exists(doer.keeper.path) #start over doist.tyme = 0.0 doist.do(doers=doers) assert doist.tyme == limit for doer in doers: assert doer.keeper.opened == False assert doer.keeper.env == None assert not os.path.exists(doer.keeper.path) """End Test"""
def test_consoler(): """ Test Consoler class Must run in WindIDE with Debug I/O configured as external console This test really is only meant for manual testing. For automated unit tests we will have to mock the serial port interface with a string or file of command lines for the input. """ tock = 0.03125 ticks = 8 limit = tock * ticks doist = doing.Doist(tock=tock, real=True, limit=limit) assert doist.tyme == 0.0 # on next cycle assert doist.tock == tock == 0.03125 assert doist.real == True assert doist.limit == limit assert doist.doers == [] doer = apping.Consoler() doers = [doer] try: doist.do(doers=doers) assert doist.tyme == limit except IOError: # pytest runner blocks opening of console have to test manually pass assert doer.console.opened == False
def runController(doers, limit=0.0): """ run the doers for limit time. 0.0 means no limit. """ # run components tock = 0.03125 doist = doing.Doist(limit=limit, tock=tock, real=True, doers=doers) doist.do()
def runAgent(controller, name="agent", httpPort=5620, tcp=5621, adminHttpPort=5623, adminTcpPort=5624, expire=0.0): """ Setup and run one agent """ logger = help.ogler.getLogger() ks = keeping.Keeper(name=name, temp=False) # not opened by default, doer opens ksDoer = keeping.KeeperDoer( keeper=ks) # doer do reopens if not opened and closes db = basing.Baser(name=name, temp=False, reload=True) # not opened by default, doer opens dbDoer = basing.BaserDoer( baser=db) # doer do reopens if not opened and closes # setup habitat hab = habbing.Habitat(name=name, ks=ks, db=db, temp=False, create=False) habDoer = habbing.HabitatDoer(habitat=hab) # setup doer # kvy = eventing.Kevery(db=hab.db, local=False) # setup doers server = tcpServing.Server(host="", port=tcp) tcpServerDoer = tcpServing.ServerDoer(server=server) directant = directing.Directant(hab=hab, server=server) wallet = walleting.Wallet(hab=hab, name=name) jsonSchema = scheming.JSONSchema(resolver=scheming.jsonSchemaCache) issueHandler = handling.IssueHandler(wallet=wallet, typ=jsonSchema) requestHandler = handling.RequestHandler(wallet=wallet, typ=jsonSchema) exchanger = exchanging.Exchanger(hab=hab, handlers=[issueHandler, requestHandler]) app = falcon.App() exnServer = httping.AgentExnServer(exc=exchanger, app=app) httpKelServer = httping.AgentKelServer(hab=hab, app=app) server = http.Server(port=httpPort, app=exnServer.app) httpServerDoer = http.ServerDoer(server=server) doers = [ ksDoer, dbDoer, habDoer, exchanger, directant, tcpServerDoer, exnServer, httpServerDoer, httpKelServer ] doers.extend(adminInterface(controller, hab, adminHttpPort, adminTcpPort)) try: tock = 0.03125 doist = doing.Doist(limit=expire, tock=tock, real=True) doist.do(doers=doers) except kering.ConfigurationError: print(f"prefix for {name} does not exist, incept must be run first", )
def runController(doers, limit=0.0): """ Utility function to run the doers that comprise a controller for limit time. 0.0 means no limit, run forever until cntl-C or all doers exit. Parameters: doers is list of doist compatible generators. Either Doer generator instances or doified or doized generator functions limit is maximum run time in seconds. Useful for testing. """ # run components tock = 0.03125 doist = doing.Doist(limit=limit, tock=tock, real=True, doers=doers) doist.do()
def test_doist(): """ Test basic doist """ doist = doing.Doist() assert doist.tyme == 0.0 # on next cycle assert doist.tock == 0.03125 assert doist.real == False assert doist.limit == None assert doist.doers == [] assert doist.timer.duration == doist.tock doist.do() # defaults make sure no exceptions """End Test """
def launch(args): app = falcon.App() server = http.Server(port=args.http, app=app) httpServerDoer = http.ServerDoer(server=server) serving.loadEnds(app, schemaDir=args.schemaDir, credDir=args.credDir, oobiDir=args.oobiDir) doers = [httpServerDoer] tock = 0.03125 doist = doing.Doist(limit=0.0, tock=tock, real=True) doist.do(doers=doers)
def test_echo_server_client(): """ Test EchoServerDoer ClientDoer classes """ tock = 0.03125 ticks = 16 limit = ticks * tock doist = doing.Doist(tock=tock, real=True, limit=limit) assert doist.tyme == 0.0 # on next cycle assert doist.tock == tock == 0.03125 assert doist.real == True assert doist.limit == limit == 0.5 assert doist.doers == [] port = 6120 server = serving.Server(host="", port=port) client = clienting.Client(tymth=doist.tymen(), host="localhost", port=port) serdoer = doing.EchoServerDoer(tymth=doist.tymen(), server=server) assert serdoer.server == server assert serdoer.tyme == serdoer.server.tyme == doist.tyme clidoer = doing.ClientDoer(tymth=doist.tymen(), client=client) assert clidoer.client == client assert clidoer.tyme == clidoer.client.tyme == doist.tyme assert serdoer.tock == 0.0 # ASAP assert clidoer.tock == 0.0 # ASAP doers = [serdoer, clidoer] msgTx = b"Hello me maties!" clidoer.client.tx(msgTx) doist.do(doers=doers) assert doist.tyme == limit assert server.opened == False assert client.opened == False assert not client.txbs msgEx = bytes(client.rxbs) # echoed back message assert msgEx == msgTx ca, ix = list(server.ixes.items())[0] assert bytes(ix.rxbs) == b"" # empty server rxbs becaue echoed """End Test """
def main(): args = parseArgs() help.ogler.level = logging.INFO help.ogler.reopen(name=args.name, temp=True, clear=True) logger = help.ogler.getLogger() logger.info("\n******* Starting Demo ******") conDoer = apping.Consoler() tock = 1.03125 doist = doing.Doist(limit=0.0, tock=tock, real=True) doist.do(doers=[conDoer]) return
def test_server_client(): """ Test ServerDoer ClientDoer classes """ tock = 0.03125 ticks = 16 limit = ticks * tock doist = doing.Doist(tock=tock, real=True, limit=limit) assert doist.tyme == 0.0 # on next cycle assert doist.tock == tock == 0.03125 assert doist.real == True assert doist.limit == limit == 0.5 assert doist.doers == [] port = 6120 server = serving.Server(host="", port=port) # client needs tymth in order to init its .tymer client = clienting.Client(tymth=doist.tymen(), host="localhost", port=port) assert client.tyme == doist.tyme serdoer = doing.ServerDoer(tymth=doist.tymen(), server=server) assert serdoer.server == server assert serdoer.tyme == serdoer.server.tyme == doist.tyme clidoer = doing.ClientDoer(tymth=doist.tymen(), client=client) assert clidoer.client == client assert clidoer.tyme == clidoer.client.tyme == doist.tyme assert serdoer.tock == 0.0 # ASAP assert clidoer.tock == 0.0 # ASAP doers = [serdoer, clidoer] msgTx = b"Hello me maties!" clidoer.client.tx(msgTx) doist.do(doers=doers) assert doist.tyme == limit assert server.opened == False assert client.opened == False assert not client.txbs ca, ix = list(server.ixes.items())[0] msgRx = bytes(ix.rxbs) assert msgRx == msgTx """End Test """
def handle(args): print(args) hab = habbing.Habitat(name='kli', temp=False) tock = 0.03125 host = '127.0.0.1' port = args.port klis = koming.Komer(db=hab.db, schema=KLIRecord, subkey='kli.') klis.put((hab.pre, ), KLIRecord( host=host, port=port, )) # doist = doing.Doist(tock=tock, real=True) # print("client", host, port) # client = clienting.Client(host=host, port=port, tymth=doist.tymen()) # clientDoer = clienting.ClientDoer(client=client) # initDoer = InitDoer(client=client, tymth=doist.tymen()) # # doist.doers = [clientDoer, initDoer] # doist.do() doist = doing.Doist(tock=tock, real=True) server = serving.Server(host='127.0.0.1', port=5678) serverDoer = serving.ServerDoer(server=server) servingDoDoer = Serving(server=server, doers=doist.doers) doist.extend([serverDoer, servingDoDoer]) daemon = daemonocle.Daemon( worker=doist.do, # update to use pidPath serving.getPIDPath() pid_file='/tmp/klid.pid', # detach=detach, ) daemon.do_action('start')
def runController(secrets, name="who", role="initiator", remotePort=5621, localPort=5620, limit=0.0): """ Setup and run the demo for name """ print("Direct Mode demo of {} as {} on TCP port {} to port {}.\n\n" "".format(name, role, localPort, remotePort)) with dbing.openLogger(name=name) as db: # setup components kevers = dict() hab = Habitat(secrets=secrets, kevers=kevers, db=db) client = clienting.Client(host='127.0.0.1', port=remotePort) clientDoer = doing.ClientDoer(client=client) if role == "initiator": director = BobDirector(hab=hab, client=client, tock=0.125) elif role == "other": director = SamDirector(hab=hab, client=client, tock=0.125) else: director = EveDirector(hab=hab, client=client, tock=0.125) reactor = Reactor(hab=hab, client=client) server = serving.Server(host="", port=localPort) serverDoer = doing.ServerDoer(server=server) directant = Directant(hab=hab, server=server) # Reactants created on demand # run components tock = 0.03125 doist = doing.Doist(limit=limit, tock=tock, real=True) doers = [clientDoer, director, reactor, serverDoer, directant] doist.do(doers=doers)
def test_console_doer(): """ Test ConsoleDoer class Must run in WindIDE with Debug I/O configured as external console """ tock = 0.03125 ticks = 8 limit = tock * ticks doist = doing.Doist(tock=tock, real=True, limit=limit) assert doist.tyme == 0.0 # on next cycle assert doist.tock == tock == 0.03125 assert doist.real == True assert doist.limit == limit assert doist.doers == [] console = serialing.Console() doer = serialing.ConsoleDoer(console=console) doers = [doer] doist.do(doers=doers) assert doist.tyme == limit assert console.opened == False
def test_run_sam_eve_demo(): """ Test demo setupController and run with DoDoers and Doist """ help.ogler.resetLevel(level=logging.DEBUG) tock = 0.03125 expire = 2.0 doist = doing.Doist(limit=expire, tock=tock, real=True) name = "sam" remote = 5621 local = 5620 secrets = [ 'ArwXoACJgOleVZ2PY7kXn7rA0II0mHYDhc6WrBH8fDAc', 'A6zz7M08-HQSFq92sJ8KJOT2cZ47x7pXFQLPB0pckB3Q', 'AcwFTk-wgk3ZT2buPRIbK-zxgPx-TKbaegQvPEivN90Y', 'Alntkt3u6dDgiQxTATr01dy8M72uuaZEf9eTdM-70Gk8', 'A1-QxDkso9-MR1A8rZz_Naw6fgaAtayda8hrbkRVVu1E', 'AKuYMe09COczwf2nIoD5AE119n7GLFOVFlNLxZcKuswc', 'AxFfJTcSuEE11FINfXMqWttkZGnUZ8KaREhrnyAXTsjw', 'ALq-w1UKkdrppwZzGTtz4PWYEeWm0-sDHzOv5sq96xJY' ] # sams is list of Doers sams = demoing.setupDemoController(secrets=secrets, name=name, remotePort=remote, localPort=local) name = "eve" remote = 5620 local = 5621 # set of secrets (seeds for private keys) secrets = [ 'AgjD4nRlycmM5cPcAkfOATAp8wVldRsnc9f1tiwctXlw', 'AKUotEE0eAheKdDJh9QvNmSEmO_bjIav8V_GmctGpuCQ', 'AK-nVhMMJciMPvmF5VZE_9H-nhrgng9aJWf7_UHPtRNM', 'AT2cx-P5YUjIw_SLCHQ0pqoBWGk9s4N1brD-4pD_ANbs', 'Ap5waegfnuP6ezC18w7jQiPyQwYYsp9Yv9rYMlKAYL8k', 'Aqlc_FWWrxpxCo7R12uIz_Y2pHUH2prHx1kjghPa8jT8', 'AagumsL8FeGES7tYcnr_5oN6qcwJzZfLKxoniKUpG4qc', 'ADW3o9m3udwEf0aoOdZLLJdf1aylokP0lwwI_M2J9h0s' ] eves = demoing.setupDemoController(secrets=secrets, name=name, remotePort=remote, localPort=local) samDoer = doing.DoDoer(doers=sams) eveDoer = doing.DoDoer(doers=eves) # run components # doist = doing.Doist(limit=expire, tock=tock, real=True, doers=[eveDoer, samDoer]) doist.do(doers=[eveDoer, samDoer]) help.ogler.resetLevel(level=help.ogler.level) """End Test"""
def test_direct_mode_bob_eve_demo(): """ Test direct mode bob and eve """ help.ogler.resetLevel(level=logging.DEBUG) # set of secrets (seeds for private keys) bobSecrets = [ 'ArwXoACJgOleVZ2PY7kXn7rA0II0mHYDhc6WrBH8fDAc', 'A6zz7M08-HQSFq92sJ8KJOT2cZ47x7pXFQLPB0pckB3Q', 'AcwFTk-wgk3ZT2buPRIbK-zxgPx-TKbaegQvPEivN90Y', 'Alntkt3u6dDgiQxTATr01dy8M72uuaZEf9eTdM-70Gk8', 'A1-QxDkso9-MR1A8rZz_Naw6fgaAtayda8hrbkRVVu1E', 'AKuYMe09COczwf2nIoD5AE119n7GLFOVFlNLxZcKuswc', 'AxFfJTcSuEE11FINfXMqWttkZGnUZ8KaREhrnyAXTsjw', 'ALq-w1UKkdrppwZzGTtz4PWYEeWm0-sDHzOv5sq96xJY' ] bobSecrecies = [] for secret in bobSecrets: # convert secrets to secrecies bobSecrecies.append([secret]) # create bob signers bobSigners = [coring.Signer(qb64=secret) for secret in bobSecrets] assert [signer.qb64 for signer in bobSigners] == bobSecrets # bob inception transferable (nxt digest not empty) bobSerder = eventing.incept( keys=[bobSigners[0].verfer.qb64], nxt=coring.Nexter(keys=[bobSigners[1].verfer.qb64]).qb64, code=coring.MtrDex.Blake3_256) bob = bobSerder.ked["i"] assert bob == 'EH7Oq9oxCgYa-nnNLvwhp9sFZpALILlRYyB-6n4WDi7w' # set of secrets (seeds for private keys) eveSecrets = [ 'AgjD4nRlycmM5cPcAkfOATAp8wVldRsnc9f1tiwctXlw', 'AKUotEE0eAheKdDJh9QvNmSEmO_bjIav8V_GmctGpuCQ', 'AK-nVhMMJciMPvmF5VZE_9H-nhrgng9aJWf7_UHPtRNM', 'AT2cx-P5YUjIw_SLCHQ0pqoBWGk9s4N1brD-4pD_ANbs', 'Ap5waegfnuP6ezC18w7jQiPyQwYYsp9Yv9rYMlKAYL8k', 'Aqlc_FWWrxpxCo7R12uIz_Y2pHUH2prHx1kjghPa8jT8', 'AagumsL8FeGES7tYcnr_5oN6qcwJzZfLKxoniKUpG4qc', 'ADW3o9m3udwEf0aoOdZLLJdf1aylokP0lwwI_M2J9h0s' ] eveSecrecies = [] for secret in eveSecrets: # convert secrets to secrecies eveSecrecies.append([secret]) # create eve signers eveSigners = [coring.Signer(qb64=secret) for secret in eveSecrets] assert [signer.qb64 for signer in eveSigners] == eveSecrets # eve inception transferable (nxt digest not empty) eveSerder = eventing.incept( keys=[eveSigners[0].verfer.qb64], nxt=coring.Nexter(keys=[eveSigners[1].verfer.qb64]).qb64, code=coring.MtrDex.Blake3_256) eve = eveSerder.ked["i"] assert eve == 'EpDA1n-WiBA0A8YOqnKrB-wWQYYC49i5zY_qrIZIicQg' with dbing.openDB(name="eve") as eveDB, keeping.openKS(name="eve") as eveKS, \ dbing.openDB(name="bob") as bobDB, keeping.openKS(name="bob") as bobKS: limit = 1.0 tock = 0.03125 doist = doing.Doist(limit=limit, tock=tock) bobPort = 5620 # bob's TCP listening port for server evePort = 5621 # eve's TCP listneing port for server bobKevers = dict() eveKevers = dict() # setup bob bobHab = directing.Habitat(name='Bob', ks=bobKS, db=bobDB, kevers=bobKevers, secrecies=bobSecrecies, temp=True) assert bobHab.ks == bobKS assert bobHab.db == bobDB assert bobHab.iserder.dig == bobSerder.dig assert bobHab.pre == bob bobClient = clienting.Client(tymth=doist.tymen(), host='127.0.0.1', port=evePort) bobClientDoer = doing.ClientDoer(client=bobClient) bobDirector = demoing.BobDirector(hab=bobHab, client=bobClient, tock=0.125) assert bobDirector.hab == bobHab assert bobDirector.client == bobClient assert bobDirector.hab.kvy.kevers == bobKevers assert bobDirector.hab.kvy.db == bobDB assert bobDirector.tock == 0.125 bobReactor = directing.Reactor(hab=bobHab, client=bobClient) assert bobReactor.hab == bobHab assert bobReactor.client == bobClient assert bobReactor.hab.kvy.kevers == bobKevers assert bobReactor.hab.kvy.db == bobDB assert bobReactor.hab.kvy.ims == bobReactor.client.rxbs bobServer = serving.Server(host="", port=bobPort) bobServerDoer = doing.ServerDoer(server=bobServer) bobDirectant = directing.Directant(hab=bobHab, server=bobServer) assert bobDirectant.hab == bobHab assert bobDirectant.server == bobServer # Bob's Reactants created on demand # setup eve eveHab = directing.Habitat(name='Eve', ks=eveKS, db=eveDB, kevers=eveKevers, secrecies=eveSecrecies, temp=True) assert eveHab.ks == eveKS assert eveHab.db == eveDB assert eveHab.iserder.dig == eveSerder.dig assert eveHab.pre == eve eveClient = clienting.Client(tymth=doist.tymen(), host='127.0.0.1', port=bobPort) eveClientDoer = doing.ClientDoer(client=eveClient) eveDirector = demoing.EveDirector(hab=eveHab, client=eveClient, tock=0.125) assert eveDirector.hab == eveHab assert eveDirector.client == eveClient assert eveDirector.hab.kvy.kevers == eveKevers assert eveDirector.hab.kvy.db == eveDB eveReactor = directing.Reactor(hab=eveHab, client=eveClient) assert eveReactor.hab == eveHab assert eveReactor.client == eveClient assert eveReactor.hab.kvy.kevers == eveKevers assert eveReactor.hab.kvy.db == eveDB assert eveReactor.hab.kvy.ims == eveReactor.client.rxbs eveServer = serving.Server(host="", port=evePort) eveServerDoer = doing.ServerDoer(server=eveServer) eveDirectant = directing.Directant(hab=eveHab, server=eveServer) assert eveDirectant.hab == eveHab assert eveDirectant.server == eveServer # Eve's Reactants created on demand doers = [ bobClientDoer, bobDirector, bobReactor, bobServerDoer, bobDirectant, eveClientDoer, eveDirector, eveReactor, eveServerDoer, eveDirectant ] doist.do(doers=doers) assert doist.tyme == limit assert bobClient.opened == False assert bobServer.opened == False assert eveClient.opened == False assert eveServer.opened == False assert bobHab.pre in bobHab.kevers assert eveHab.pre in eveHab.kevers assert not bobClient.txbs assert bobHab.pre in eveHab.kevers # verify final event states assert not os.path.exists(eveDB.path) assert not os.path.exists(bobDB.path) help.ogler.resetLevel(level=help.ogler.level) """End Test"""
def test_doist_remove(): """ Test Doist.remove of doers """ tock = 1.0 limit = 5.0 # start over with full set to test remove doer0 = TryDoer(stop=1) doer1 = TryDoer(stop=2) doer2 = TryDoer(stop=3) doer3 = TryDoer(stop=2) doer4 = TryDoer(stop=3) doers = [doer0, doer1, doer2, doer3, doer4] doist = doing.Doist(tock=tock, doers=list(doers), always=True) assert doist.tock == tock == 1.0 assert doist.tyme == 0.0 assert doist.doers == doers for doer in doist.doers: assert doer.done == None assert doist.done == None assert not doist.deeds doist.enter() assert doist.done == None # did not call .do so stays None not False doist.recur() doist.recur() assert doist.tyme == 2.0 assert not doist.done # doist not done assert doer0.done assert not doer1.done assert not doer2.done assert not doer3.done assert not doer4.done assert len(doist.deeds) == 4 # deeds still there doers = [doer for dog, retyme, doer in doist.deeds] assert doers == [doer1, doer2, doer3, doer4] # doer0 is removed for dog, retyme, doer in doist.deeds: assert not doer.done doist.remove(doers=[doer0, doer1, doer3]) assert doist.doers == [doer2, doer4] assert len(doist.deeds) == 2 doers = [doer for dog, retyme, doer in doist.deeds] assert doers == [doer2, doer4] # others are removed for dog, retyme, doer in doist.deeds: assert not doer.done assert not doer1.done # forced exit assert not doer3.done # forced exit doist.recur() doist.recur() assert doist.tyme == 4.0 assert doist.done == None # never called .do assert len(doist.deeds) == 0 # all done assert len(doist.doers) == 2 # not removed but completed for doer in doist.doers: assert doer.done assert doer0.done # already clean done before remove assert not doer1.done # forced exit upon remove before done assert doer2.done # clean done assert not doer3.done # forced exit upon remove before done assert doer4.done # clean done doist.recur() doist.recur() # does not complete because always == True """Done Test"""
def test_doist_remove_own_doer(): """ Test .remove method of Doist called by a doer of Doist that removes all doers including itself. """ tock = 1.0 limit = 5.0 # create doist first so can inject it into removeDo doist = doing.Doist(tock=tock, limit=limit) # create doized function that removes doers @doing.doize(tock=0.0, doist=doist) def removeDo(tymth=None, tock=0.0, doist=None, **opts): """ Returns generator function (doer dog) to process to remove all doers of doist but itself Parameters: tymth is injected function wrapper closure returned by .tymen() of Tymist instance (e.e. Doist/DoDoer). Calling tymth() returns associated Tymist .tyme. tock is injected initial tock value from doer.tock opts is dict of injected optional additional parameters from doer.opts Injected attributes by doize decorator as parameters to this method: gf.tock = tock # default tock attribute for doer gf.opts = {} # default opts for doer Usage: add to doers list """ yield # enter context also makes generator method # recur context doist.remove(list( doist.doers)) # attept to remove all doers including itself yield # extra yield for testing so does a couple of passes after removed yield # extra yield for testing so does a couple of passes after removed return True # once removed then return to remove itself as doer # create other doers to remove doer0 = TryDoer(stop=1) doer1 = TryDoer(stop=2) doer2 = TryDoer(stop=3) doer3 = TryDoer(stop=2) doer4 = TryDoer(stop=3) doers = [doer0, doer1, doer2, doer3, doer4, removeDo] doist.doers = list(doers) # make copy assert doist.tock == tock == 1.0 assert doist.tyme == 0.0 assert doist.limit == limit == 5.0 assert doist.doers == doers assert removeDo in doist.doers for doer in doist.doers: assert doer.done == None assert doist.done == None assert not doist.deeds doist.enter() assert not doist.done doist.recur() # should run removeDo and remove all but itself assert doist.tyme == 1.0 assert doist.deeds # doer removed by not deed. assert not doist.done # doist not done assert not doist.doers assert not removeDo in doist.doers # force exited so not done assert not doer0.done assert not doer1.done assert not doer2.done assert not doer3.done assert not doer4.done assert not removeDo.done doist.recur() assert doist.tyme == 2.0 assert doist.deeds assert not doist.done # dodoer not done assert doist.deeds assert not doist.doers doist.recur() assert doist.tyme == 3.0 assert not doist.deeds assert not doist.done assert removeDo.done # finished on it own """Done Test"""
def test_doist_dos(): """ Test doist.do with dos generator functions not generator methods """ tock = 0.03125 doist = doing.Doist(tock=tock) assert doist.tyme == 0.0 # on next cycle assert doist.tock == tock == 0.03125 assert doist.real == False assert doist.limit == None assert doist.doers == [] doer0 = doing.doify(doing.doifyExDo, name='gf0', tock=tock, states=None) assert inspect.isgeneratorfunction(doer0) assert doer0.opts["states"] == None doer0.opts['states'] = [] assert doer0.tock == tock assert doer0.done == None doer1 = doing.doify(doing.doifyExDo, name='gf1', tock=tock*2) assert inspect.isgeneratorfunction(doer1) assert not doer1.opts doer1.opts['states'] = [] assert doer1.tock == tock * 2 assert doer1.done == None assert doer0 is not doer1 doer2 = doing.doizeExDo assert inspect.isgeneratorfunction(doer2) assert doer2.opts["states"] == None doer2.opts["states"] = [] doer2.tock = tock * 2 assert doer2.done == None doers = [doer0, doer1, doer2] for doer in doers: assert doer.opts['states'] == [] ticks = 4 limit = tock * ticks doist.do(doers=doers, limit=limit) assert doist.tyme == limit == 0.125 assert doer0.opts["states"] == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1), State(tyme=0.03125, context='recur', feed=0.03125, count=2), State(tyme=0.0625, context='recur', feed=0.0625, count=3), State(tyme=0.09375, context='recur', feed=0.09375, count=4), State(tyme=0.09375, context='exit', feed=None, count=5)] assert doer0.done == True assert doer1.opts["states"] == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1), State(tyme=0.0625, context='recur', feed=0.0625, count=2), State(tyme=0.125, context='close', feed=None, count=3), State(tyme=0.125, context='exit', feed=None, count=4)] assert doer1.done == False assert doer2.opts["states"] == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1), State(tyme=0.0625, context='recur', feed=0.0625, count=2), State(tyme=0.125, context='close', feed=None, count=3), State(tyme=0.125, context='exit', feed=None, count=4)] assert doer2.done == False # repeat but real time doist = doing.Doist(tock=tock, real=True, limit=limit) assert doist.tyme == 0.0 # on next cycle assert doist.tock == tock == 0.03125 assert doist.real == True assert doist.limit == limit == 0.125 assert doist.doers == [] for doer in doers: doer.opts['states'] = [] assert doer.opts['states'] == [] doer.done = None doist.do(doers=doers) assert doist.tyme == limit == 0.125 assert doer0.opts["states"] == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1), State(tyme=0.03125, context='recur', feed=0.03125, count=2), State(tyme=0.0625, context='recur', feed=0.0625, count=3), State(tyme=0.09375, context='recur', feed=0.09375, count=4), State(tyme=0.09375, context='exit', feed=None, count=5)] assert doer1.opts["states"] == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1), State(tyme=0.0625, context='recur', feed=0.0625, count=2), State(tyme=0.125, context='close', feed=None, count=3), State(tyme=0.125, context='exit', feed=None, count=4)] assert doer2.opts["states"] == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1), State(tyme=0.0625, context='recur', feed=0.0625, count=2), State(tyme=0.125, context='close', feed=None, count=3), State(tyme=0.125, context='exit', feed=None, count=4)] # Low limit force close ticks = 2 limit = tock * ticks doist = doing.Doist(tock=tock, real=False, limit=limit) assert doist.tyme == 0.0 # on next cycle assert doist.tock == tock == 0.03125 assert doist.real == False assert doist.limit == limit == 0.0625 assert doist.doers == [] for doer in doers: doer.opts['states'] = [] assert doer.opts['states'] == [] doer.tock = 0.0 # run asap doist.do(doers=doers) assert doist.tyme == limit assert doer0.opts["states"] == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1), State(tyme=0.03125, context='recur', feed=0.03125, count=2), State(tyme=0.0625, context='close', feed=None, count=3), State(tyme=0.0625, context='exit', feed=None, count=4)] assert doer0.opts["states"] == doer1.opts["states"] == doer2.opts["states"] # low limit force close real time doist = doing.Doist(tock=tock, real=True, limit=limit) assert doist.tyme == 0.0 # on next cycle assert doist.tock == tock == 0.03125 assert doist.real == True assert doist.limit == limit == 0.0625 assert doist.doers == [] for doer in doers: doer.opts['states'] = [] assert doer.opts['states'] == [] doer.tock = 0.0 # run asap doist.do(doers=doers) assert doist.tyme == limit assert doer0.opts["states"] == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1), State(tyme=0.03125, context='recur', feed=0.03125, count=2), State(tyme=0.0625, context='close', feed=None, count=3), State(tyme=0.0625, context='exit', feed=None, count=4)] assert doer0.opts["states"] == doer1.opts["states"] == doer2.opts["states"] """End Test """
def test_nested_doers(): """ Test Doist running nested DoDoers and Doers """ tock = 0.03125 doist = doing.Doist(tock=tock) assert doist.tyme == 0.0 # on next cycle assert doist.tock == tock == 0.03125 assert doist.real == False assert doist.limit == None assert doist.doers == [] doer0 = doing.ExDoer(tock=0.0, tymth=doist.tymen()) doer1 = doing.ExDoer(tock=tock*2, tymth=doist.tymen()) assert doer0.tock == 0.0 assert doer1.tock == tock * 2 aDoers = [doer0, doer1] for doer in aDoers: assert doer.states == [] assert doer.count == None assert doer.done == None aDoer = doing.DoDoer(tock=0.0, tymth=doist.tymen(), doers=aDoers) assert aDoer.doers == aDoers assert aDoer.done == None doer2 = doing.ExDoer(tock=0.0, tymth=doist.tymen()) doer3 = doing.ExDoer(tock=tock*4, tymth=doist.tymen()) assert doer2.tock == 0.0 assert doer3.tock == tock * 4 bDoers = [doer2, doer3] for doer in bDoers: assert doer.states == [] assert doer.count == None assert doer.done == None bDoer = doing.DoDoer(tock=tock*2, tymth=doist.tymen(), doers=bDoers) assert bDoer.doers == bDoers assert bDoer.done == None doers = [aDoer, bDoer] ticks = 8 limit = tock * ticks doist.do(doers=doers, limit=limit) # run em all assert doist.tyme == limit == 0.25 assert aDoer.done == True assert bDoer.done == False assert doer0.states == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1), State(tyme=0.03125, context='recur', feed=0.03125, count=2), State(tyme=0.0625, context='recur', feed=0.0625, count=3), State(tyme=0.09375, context='recur', feed=0.09375, count=4), State(tyme=0.09375, context='exit', feed=None, count=5)] assert doer1.done == True assert doer1.states == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1), State(tyme=0.0625, context='recur', feed=0.0625, count=2), State(tyme=0.125, context='recur', feed=0.125, count=3), State(tyme=0.1875, context='recur', feed=0.1875, count=4), State(tyme=0.1875, context='exit', feed=None, count=5)] assert doer1.done == True assert doer2.states == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1), State(tyme=0.0625, context='recur', feed=0.0625, count=2), State(tyme=0.125, context='recur', feed=0.125, count=3), State(tyme=0.1875, context='recur', feed=0.1875, count=4), State(tyme=0.1875, context='exit', feed=None, count=5)] assert doer2.done == True assert doer3.states == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1), State(tyme=0.125, context='recur', feed=0.125, count=2), State(tyme=0.25, context='close', feed=None, count=3), State(tyme=0.25, context='exit', feed=None, count=4)] assert doer3.done == False """End Test """
def test_doist_once(): """ Test doist.once with deeds """ doist = doing.Doist(tock=0.25) assert doist.tyme == 0.0 # on next cycle assert doist.tock == 0.25 assert doist.real == False assert doist.limit == None assert doist.doers == [] doer0 = doing.ExDoer(tock=0.25, tymth=doist.tymen()) doer1 = doing.ExDoer(tock=0.5, tymth=doist.tymen()) doers = [doer0, doer1] doist.doers = doers deeds = doist.ready() assert len(deeds) == 2 assert [val[1] for val in deeds] == [0.0, 0.0] for doer in doers: assert doer.states == [State(tyme=0.0, context='enter', feed=0.0, count=0)] assert doer.done == False doist.once(deeds) assert doist.tyme == 0.25 # on next cycle assert len(deeds) == 2 assert [val[1] for val in deeds] == [0.25, 0.5] assert doer0.states == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1)] assert doer1.states == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1)] doist.once(deeds) assert doist.tyme == 0.5 # on next cycle assert len(deeds) == 2 assert [val[1] for val in deeds] == [0.5, 0.5] assert doer0.states == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1), State(tyme=0.25, context='recur', feed=0.25, count=2)] assert doer1.states == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1)] doist.once(deeds) assert doist.tyme == 0.75 # on next cycle assert len(deeds) == 2 assert [val[1] for val in deeds] == [0.75, 1.0] assert doer0.states == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1), State(tyme=0.25, context='recur', feed=0.25, count=2), State(tyme=0.5, context='recur', feed=0.5, count=3)] assert doer1.states == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1), State(tyme=0.5, context='recur', feed=0.5, count=2)] doist.once(deeds) assert doist.tyme == 1.0 # on next cycle assert len(deeds) == 1 assert [val[1] for val in deeds] == [1.0] assert doer0.states == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1), State(tyme=0.25, context='recur', feed=0.25, count=2), State(tyme=0.5, context='recur', feed=0.5, count=3), State(tyme=0.75, context='recur', feed=0.75, count=4), State(tyme=0.75, context='exit', feed=None, count=5)] assert doer0.done == True assert doer1.states == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1), State(tyme=0.5, context='recur', feed=0.5, count=2)] doist.once(deeds) assert doist.tyme == 1.25 # on next cycle assert len(deeds) == 1 assert doer0.states == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1), State(tyme=0.25, context='recur', feed=0.25, count=2), State(tyme=0.5, context='recur', feed=0.5, count=3), State(tyme=0.75, context='recur', feed=0.75, count=4), State(tyme=0.75, context='exit', feed=None, count=5)] assert doer1.states == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1), State(tyme=0.5, context='recur', feed=0.5, count=2), State(tyme=1.0, context='recur', feed=1.0, count=3)] doist.once(deeds) assert doist.tyme == 1.50 # on next cycle assert len(deeds) == 1 assert doer0.states == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1), State(tyme=0.25, context='recur', feed=0.25, count=2), State(tyme=0.5, context='recur', feed=0.5, count=3), State(tyme=0.75, context='recur', feed=0.75, count=4), State(tyme=0.75, context='exit', feed=None, count=5)] assert doer1.states == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1), State(tyme=0.5, context='recur', feed=0.5, count=2), State(tyme=1.0, context='recur', feed=1.0, count=3)] doist.once(deeds) assert doist.tyme == 1.75 # on next cycle assert len(deeds) == 0 assert doer0.states == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1), State(tyme=0.25, context='recur', feed=0.25, count=2), State(tyme=0.5, context='recur', feed=0.5, count=3), State(tyme=0.75, context='recur', feed=0.75, count=4), State(tyme=0.75, context='exit', feed=None, count=5)] assert doer1.states == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1), State(tyme=0.5, context='recur', feed=0.5, count=2), State(tyme=1.0, context='recur', feed=1.0, count=3), State(tyme=1.5, context='recur', feed=1.5, count=4), State(tyme=1.5, context='exit', feed=None, count=5)] assert doer1.done == True """End Test """
def test_doist_doers(): """ Test doist.do with .close of deeds """ tock = 0.03125 doist = doing.Doist(tock=tock) assert doist.tyme == 0.0 # on next cycle assert doist.tock == tock == 0.03125 assert doist.real == False assert doist.limit == None assert doist.doers == [] doer0 = doing.ExDoer(tock=tock, tymth=doist.tymen()) doer1 = doing.ExDoer(tock=tock*2, tymth=doist.tymen()) assert doer0.tock == tock assert doer1.tock == tock * 2 doers = [doer0, doer1] for doer in doers: assert doer.states == [] assert doer.count == None assert doer.done == None ticks = 4 limit = tock * ticks doist.do(doers=doers, limit=limit) assert doist.tyme == limit == 0.125 assert doer0.states == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1), State(tyme=0.03125, context='recur', feed=0.03125, count=2), State(tyme=0.0625, context='recur', feed=0.0625, count=3), State(tyme=0.09375, context='recur', feed=0.09375, count=4), State(tyme=0.09375, context='exit', feed=None, count=5)] assert doer0.done == True assert doer1.states == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1), State(tyme=0.0625, context='recur', feed=0.0625, count=2), State(tyme=0.125, context='close', feed=None, count=3), State(tyme=0.125, context='exit', feed=None, count=4)] assert doer1.done == False doist = doing.Doist(tock=tock, real=True, limit=limit) assert doist.tyme == 0.0 # on next cycle assert doist.tock == tock == 0.03125 assert doist.real == True assert doist.limit == limit == 0.125 assert doist.doers == [] for doer in doers: doer.states = [] assert doer.states == [] doist.do(doers=doers) assert doist.tyme == limit == 0.125 assert doer0.states == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1), State(tyme=0.03125, context='recur', feed=0.03125, count=2), State(tyme=0.0625, context='recur', feed=0.0625, count=3), State(tyme=0.09375, context='recur', feed=0.09375, count=4), State(tyme=0.09375, context='exit', feed=None, count=5)] assert doer0.done == True assert doer1.states == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1), State(tyme=0.0625, context='recur', feed=0.0625, count=2), State(tyme=0.125, context='close', feed=None, count=3), State(tyme=0.125, context='exit', feed=None, count=4)] assert doer1.done == False # doers passed to Doist init doist = doing.Doist(tock=tock, real=True, limit=limit, doers=doers) assert doist.tyme == 0.0 # on next cycle assert doist.tock == tock == 0.03125 assert doist.real == True assert doist.limit == limit == 0.125 assert doist.doers == doers for doer in doers: doer.states = [] assert doer.states == [] doist.do() assert doist.tyme == limit == 0.125 assert doer0.states == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1), State(tyme=0.03125, context='recur', feed=0.03125, count=2), State(tyme=0.0625, context='recur', feed=0.0625, count=3), State(tyme=0.09375, context='recur', feed=0.09375, count=4), State(tyme=0.09375, context='exit', feed=None, count=5)] assert doer0.done == True assert doer1.states == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1), State(tyme=0.0625, context='recur', feed=0.0625, count=2), State(tyme=0.125, context='close', feed=None, count=3), State(tyme=0.125, context='exit', feed=None, count=4)] assert doer1.done == False # Run ASAP doist = doing.Doist(tock=tock, real=False, limit=limit) assert doist.tyme == 0.0 # on next cycle assert doist.tock == tock == 0.03125 assert doist.real == False assert doist.limit == limit == 0.125 assert doist.doers == [] for doer in doers: doer.states = [] assert doer.states == [] doer.tock = 0.0 # run asap assert doer.tock == 0.0 doist.do(doers=doers) assert doist.tyme == limit assert doer0.states == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1), State(tyme=0.03125, context='recur', feed=0.03125, count=2), State(tyme=0.0625, context='recur', feed=0.0625, count=3), State(tyme=0.09375, context='recur', feed=0.09375, count=4), State(tyme=0.09375, context='exit', feed=None, count=5)] assert doer0.done == doer1.done == True assert doer1.states == doer0.states doist = doing.Doist(tock=tock, real=True, limit=limit) assert doist.tyme == 0.0 # on next cycle assert doist.tock == tock == 0.03125 assert doist.real == True assert doist.limit == limit == 0.125 assert doist.doers == [] for doer in doers: doer.states = [] assert doer.states == [] doer.tock = 0.0 # run asap assert doer.tock == 0.0 doist.do(doers=doers) assert doist.tyme == limit assert doer0.states == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1), State(tyme=0.03125, context='recur', feed=0.03125, count=2), State(tyme=0.0625, context='recur', feed=0.0625, count=3), State(tyme=0.09375, context='recur', feed=0.09375, count=4), State(tyme=0.09375, context='exit', feed=None, count=5)] assert doer0.done == doer1.done == True assert doer1.states == doer0.states # Low limit force close ticks = 2 limit = tock * ticks doist = doing.Doist(tock=tock, real=False, limit=limit) assert doist.tyme == 0.0 # on next cycle assert doist.tock == tock == 0.03125 assert doist.real == False assert doist.limit == limit == 0.0625 assert doist.doers == [] for doer in doers: doer.states = [] assert doer.states == [] doer.tock = 0.0 # run asap assert doer.tock == 0.0 doist.do(doers=doers) assert doist.tyme == limit assert doer0.states == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1), State(tyme=0.03125, context='recur', feed=0.03125, count=2), State(tyme=0.0625, context='close', feed=None, count=3), State(tyme=0.0625, context='exit', feed=None, count=4)] assert doer0.done == doer1.done == False assert doer1.states == doer0.states # low limit force close real time doist = doing.Doist(tock=tock, real=True, limit=limit) assert doist.tyme == 0.0 # on next cycle assert doist.tock == tock == 0.03125 assert doist.real == True assert doist.limit == limit == 0.0625 assert doist.doers == [] for doer in doers: doer.states = [] assert doer.states == [] doer.tock = 0.0 # run asap assert doer.tock == 0.0 doist.do(doers=doers) assert doist.tyme == limit assert doer0.states == [State(tyme=0.0, context='enter', feed=0.0, count=0), State(tyme=0.0, context='recur', feed=0.0, count=1), State(tyme=0.03125, context='recur', feed=0.03125, count=2), State(tyme=0.0625, context='close', feed=None, count=3), State(tyme=0.0625, context='exit', feed=None, count=4)] assert doer0.done == doer1.done == False assert doer1.states == doer0.states """End Test """
def test_filer_doer(): """ Test FilerDoer """ filer0 = filing.Filer(name='test0', temp=True, reopen=False) assert filer0.opened == False assert filer0.path == None assert filer0.file == None filerDoer0 = filing.FilerDoer(filer=filer0) assert filerDoer0.filer == filer0 assert filerDoer0.filer.opened == False filer1 = filing.Filer(name='test1', temp=True, reopen=False) assert filer1.opened == False assert filer1.path == None assert filer0.file == None filerDoer1 = filing.FilerDoer(filer=filer1) assert filerDoer1.filer == filer1 assert filerDoer1.filer.opened == False limit = 0.25 tock = 0.03125 doist = doing.Doist(limit=limit, tock=tock) doers = [filerDoer0, filerDoer1] doist.doers = doers doist.enter() assert len(doist.deeds) == 2 assert [val[1] for val in doist.deeds] == [0.0, 0.0] # retymes for doer in doers: assert doer.filer.opened assert "_test/hio/test" in doer.filer.path doist.recur() assert doist.tyme == 0.03125 # on next cycle assert len(doist.deeds) == 2 for doer in doers: assert doer.filer.opened == True for dog, retyme, index in doist.deeds: dog.close() for doer in doers: assert doer.filer.opened == False assert not os.path.exists(doer.filer.path) # start over doist.tyme = 0.0 doist.do(doers=doers) assert doist.tyme == limit for doer in doers: assert doer.filer.opened == False assert not os.path.exists(doer.filer.path) # test with filed == True filer0 = filing.Filer(name='test0', temp=True, reopen=False, filed=True) assert filer0.opened == False assert filer0.path == None assert filer0.file == None filerDoer0 = filing.FilerDoer(filer=filer0) assert filerDoer0.filer == filer0 assert filerDoer0.filer.opened == False filer1 = filing.Filer(name='test1', temp=True, reopen=False, filed=True) assert filer1.opened == False assert filer1.path == None assert filer0.file == None filerDoer1 = filing.FilerDoer(filer=filer1) assert filerDoer1.filer == filer1 assert filerDoer1.filer.opened == False limit = 0.25 tock = 0.03125 doist = doing.Doist(limit=limit, tock=tock) doers = [filerDoer0, filerDoer1] doist.doers = doers doist.enter() assert len(doist.deeds) == 2 assert [val[1] for val in doist.deeds] == [0.0, 0.0] # retymes for doer in doers: assert doer.filer.opened assert "_test/hio/test" in doer.filer.path assert doer.filer.path.endswith(".text") assert doer.filer.file is not None assert not doer.filer.file.closed doist.recur() assert doist.tyme == 0.03125 # on next cycle assert len(doist.deeds) == 2 for doer in doers: assert doer.filer.opened assert doer.filer.file is not None assert not doer.filer.file.closed for dog, retyme, index in doist.deeds: dog.close() for doer in doers: assert doer.filer.opened == False assert not os.path.exists(doer.filer.path) assert doer.filer.file is None # start over doist.tyme = 0.0 doist.do(doers=doers) assert doist.tyme == limit for doer in doers: assert doer.filer.opened == False assert not os.path.exists(doer.filer.path) assert doer.filer.file is None """End Test"""
def test_proving(): sidSalt = coring.Salter(raw=b'0123456789abcdef').qb64 hanSalt = coring.Salter(raw=b'abcdef0123456789').qb64 vicSalt = coring.Salter(raw=b'fedcba9876543210').qb64 with basing.openDB(name="sid") as sidDB, \ keeping.openKS(name="sid") as sidKS, \ basing.openDB(name="vic") as vicDB, \ keeping.openKS(name="vic") as vicKS, \ basing.openDB(name="han") as hanDB, \ keeping.openKS(name="han") as hanKS, \ openPocket(name="han") as hanPDB: limit = 1.0 tock = 1.0 doist = doing.Doist(limit=limit, tock=tock) sidHab = habbing.Habitat(ks=sidKS, db=sidDB, salt=sidSalt, temp=True) assert sidHab.pre == "E4YPqsEOaPNaZxVIbY-Gx2bJgP-c7AH_K7pEE-YfcI9E" sidIcpMsg = sidHab.makeOwnInception() hanKvy = eventing.Kevery(db=hanDB) parsing.Parser().parse(ims=bytearray(sidIcpMsg), kvy=hanKvy) assert hanKvy.kevers[sidHab.pre].sn == 0 # accepted event hanHab = habbing.Habitat(ks=hanKS, db=hanDB, salt=hanSalt, temp=True) assert hanHab.pre == "EKDWzykRd45o5UQyprm_9e8UcltXGo1tZCrdfGBTA8tc" hanIcpMsg = hanHab.makeOwnInception() vicKvy = eventing.Kevery(db=vicDB) parsing.Parser().parse(ims=bytearray(hanIcpMsg), kvy=vicKvy) assert vicKvy.kevers[hanHab.pre].sn == 0 # accepted event vicHab = habbing.Habitat(ks=vicKS, db=vicDB, salt=vicSalt, temp=True) assert vicHab.pre == "E8HQASAgOnZnQ4T7rv3dcvj0-UydrTTtyCprhEASk__o" vicIcpMsg = vicHab.makeOwnInception() parsing.Parser().parse(ims=bytearray(vicIcpMsg), kvy=hanKvy) assert hanKvy.kevers[vicHab.pre].sn == 0 # accepted event sed = dict() sed["$id"] = "" sed["$schema"] = "http://json-schema.org/draft-07/schema#" sed.update( dict(type="object", properties=dict(id=dict(type="string"), lei=dict(type="string")))) schemer = scheming.Schemer(sed=sed, typ=scheming.JSONSchema(), code=coring.MtrDex.Blake3_256) cache = CacheResolver() cache.add(schemer.said, schemer.raw) jsonSchema = JSONSchema(resolver=cache) credSubject = dict( id= "did:keri:Efaavv0oadfghasdfn443fhbyyr4v", # this needs to be generated from a KEL lei="254900OPPU84GM83MG36", issuanceDate="2021-06-27T21:26:21.233257+00:00", ) creder = credential(issuer=sidHab.pre, schema=schemer.said, subject=credSubject, typ=JSONSchema(resolver=cache)) assert creder.said == "EgaaYOPdG7vootT99cmClvwOoM-hjUIpv5Xl6hFuTcyM" msg = sidHab.endorse(serder=creder) hanWallet = Wallet(hab=hanHab, db=hanPDB) parseCredential(ims=msg, wallet=hanWallet, typ=JSONSchema(resolver=cache)) # verify we can load serialized VC by SAID key = creder.said.encode("utf-8") assert hanPDB.getSers(key) is not None # Create Red's wallet and Issue Handler for receiving the credential hanRequestHandler = RequestHandler(wallet=hanWallet, typ=jsonSchema) hanExc = exchanging.Exchanger(hab=hanHab, tymth=doist.tymen(), handlers=[hanRequestHandler]) # Create the issue credential payload pl = dict(input_descriptors=[dict(x=schemer.said)]) # Create the `exn` message for presentation request vicExcSrdr = exchanging.exchange(route="/presentation/request", payload=pl) excMsg = vicHab.sanction(vicExcSrdr) # Parse the exn presentation request message on Han's side parsing.Parser().parse(ims=bytearray(excMsg), kvy=hanKvy, exc=hanExc) doist.do(doers=[hanExc]) assert doist.tyme == limit resp = hanRequestHandler.cues.popleft() assert resp is not None respSer = coring.Serder(raw=resp.raw) assert respSer.ked['t'] == coring.Ilks.exn assert respSer.ked['r'] == "/presentation/proof" data = respSer.ked['q'] assert "presentation_submission" in data pe = data["presentation_submission"] assert "descriptor_map" in pe dm = pe["descriptor_map"] assert len(dm) == 1 assert dm[0]["id"] == schemer.said assert "verifiableCredential" in data vcs = data["verifiableCredential"] assert len(vcs) == 1 proof = ( "-FABE4YPqsEOaPNaZxVIbY-Gx2bJgP-c7AH_K7pEE-YfcI9E0AAAAAAAAAAAAAAAAAAAAAAAElHzHwX3V6itsD2Ksg_CNBbUNTBYzLYw" "-AxDNI7_ZmaI-AABAA0pXbQllgzXr88IczAnsPrdhgFKs9wNQvfSfzyrtcvbTwq-U1DmBluAklntCqH1AbBL6TWLZIDGi83BHLWJ82CA" ) assert vcs[0]["proof"] == proof
def test_dodoer_always(): """ Test DoDoer class with tryDoer and always """ # create some TryDoers for doers doer0 = TryDoer(stop=1) doer1 = TryDoer(stop=2) doer2 = TryDoer(stop=3) doers = [doer0, doer1, doer2] tock = 1.0 dodoer = doing.DoDoer(tock=tock, doers=list(doers)) assert dodoer.tock == tock == 1.0 assert dodoer.doers == doers for doer in dodoer.doers: assert doer.done == None assert dodoer.always == False limit = 5.0 doist = doing.Doist(tock=tock, limit=limit, doers=[dodoer]) assert doist.tock == tock == 1.0 assert doist.limit == limit == 5.0 assert doist.doers == [dodoer] assert dodoer.done == None assert dodoer.always == False assert not dodoer.deeds # limit = 5 is long enough that all TryDoers complete doist.do() assert doist.tyme == 4.0 assert dodoer.done assert dodoer.tyme == doist.tyme assert dodoer.always == False for doer in dodoer.doers: assert doer.done assert doer.tyme == dodoer.tyme == doist.tyme assert not dodoer.deeds # redo but with limit == so not all complete doist.do(limit=2) assert doist.tyme == 6.0 assert not dodoer.done assert dodoer.always == False assert doer0.done assert not doer1.done assert not doer2.done assert not dodoer.deeds # redo but with ddoer.always == True but limit enough to complete dodoer.always = True assert dodoer.always == True doist.do(limit=5) assert doist.tyme == 11.0 assert not dodoer.done # dodoer not done assert dodoer.always == True for doer in dodoer.doers: # but all its doers are done assert doer.done assert not dodoer.deeds # redo but with ddoer.always == True but limit not enought to complete assert dodoer.always == True doist.do(limit=2) assert doist.tyme == 13.0 assert not dodoer.done # dodoer not done assert dodoer.always == True assert doer0.done assert not doer1.done assert not doer2.done assert not dodoer.deeds # redo but with ddoer.always == True but manual run doist so does not # force complete doers assert dodoer.always == True assert doist.tyme == 13.0 deeds = doist.ready(doers=[dodoer]) doist.once(deeds) doist.once(deeds) assert doist.tyme == 15.0 assert not dodoer.done # dodoer not done assert dodoer.always == True assert doer0.done assert not doer1.done assert not doer2.done assert len(dodoer.deeds) == 2 # deeds still there # now extend deeds doer3 = TryDoer(stop=1) doer4 = TryDoer(stop=2) moredoers = [doer3, doer4] dodoer.extend(doers=list(moredoers)) assert dodoer.doers == doers + moredoers assert len(dodoer.deeds) == 4 indices = [index for dog, retyme, index in dodoer.deeds] assert indices == [1, 2, 3, 4] doist.once(deeds) doist.once(deeds) assert doist.tyme == 17.0 assert not dodoer.done # dodoer not done assert dodoer.always == True assert doer0.done assert doer1.done assert doer2.done assert doer3.done assert not doer4.done assert len(dodoer.deeds) == 1 # deeds still there doist.close(deeds) assert dodoer.done == False # forced close so not done assert doer0.done assert doer1.done assert doer2.done assert doer3.done assert not doer4.done # forced close so not done assert not deeds # start over with full set to test remove doer0 = TryDoer(stop=1) doer1 = TryDoer(stop=2) doer2 = TryDoer(stop=3) doer3 = TryDoer(stop=2) doer4 = TryDoer(stop=3) doers = [doer0, doer1, doer2, doer3, doer4] dodoer = doing.DoDoer(tock=tock, doers=list(doers), always=True) assert dodoer.tock == tock == 1.0 assert dodoer.doers ==doers for doer in dodoer.doers: assert doer.done == None assert dodoer.always == True limit = 5.0 doist = doing.Doist(tock=tock, limit=limit, doers=[dodoer]) assert doist.tock == tock == 1.0 assert doist.limit == limit == 5.0 assert doist.doers == [dodoer] assert dodoer.done == None assert dodoer.always == True assert not dodoer.deeds deeds = doist.ready(doers=[dodoer]) assert not dodoer.done doist.once(deeds) doist.once(deeds) assert doist.tyme == 2.0 assert not dodoer.done # dodoer not done assert dodoer.always == True assert doer0.done assert not doer1.done assert not doer2.done assert not doer3.done assert not doer4.done assert len(dodoer.deeds) == 4 # deeds still there dodoer.remove(doers=[doer0, doer1, doer3]) assert dodoer.doers == [doer2, doer4] assert len(dodoer.deeds) == 2 """End Test """
def test_doize_dodoer_with_bound_method(): """ Test decorator @doize with bound method returning generator """ # run until complete normal exit so done==True class A(): def __init__(self): self.x = 1 @doing.doize(tock=0.25) def myDo(self, tymth=None, tock=0.0, **opts): while self.x <= 3: tyme = yield(tock) self.x += 1 return True a = A() assert a.x == 1 assert inspect.ismethod(a.myDo) assert inspect.isgeneratorfunction(a.myDo) # read of bound method attribute is allowed assert a.myDo.__func__.tock == a.myDo.tock == 0.25 assert a.myDo.__func__.done == a.myDo.done == None assert a.myDo.__func__.opts == a.myDo.opts == dict() with pytest.raises(AttributeError): a.myDo.tock = 0.2 # can't write to bound method attribute a.myDo.__func__.tock = 0.2 # can write to bound method.__func__ attribute assert a.myDo.tock == 0.2 doist = doing.Doist(limit=1.0) myGen = a.myDo(tymth=doist.tymen(), tock=a.myDo.tock, **a.myDo.opts) assert inspect.isgenerator(myGen) doist.do(doers=[a.myDo]) assert a.myDo.done assert a.x == 4 a.x = 1 assert a.x == 1 doist.tyme = 0.0 dodoer = doing.DoDoer(doers=[a.myDo]) doist.do(doers=[dodoer]) assert a.myDo.done assert a.x == 4 # run forever so forced complete done == False class B(): def __init__(self): self.x = 1 @doing.doize(tock=0.25) def myDo(self, tymth=None, tock=0.0, **opts): while True: tyme = yield(tock) self.x += 1 return True b = B() assert b.x == 1 assert inspect.ismethod(b.myDo) assert inspect.isgeneratorfunction(b.myDo) # read of bound method attribute is allowed assert b.myDo.__func__.tock == b.myDo.tock == 0.25 assert b.myDo.__func__.done == b.myDo.done == None assert b.myDo.__func__.opts == b.myDo.opts == dict() with pytest.raises(AttributeError): b.myDo.tock = 0.2 # can't write to bound method attribute b.myDo.__func__.tock = 0.2 # can write to bound method.__func__ attribute assert b.myDo.tock == 0.2 doist = doing.Doist(limit=1.0) myGen = b.myDo(tymth=doist.tymen(), tock=b.myDo.tock, **b.myDo.opts) assert inspect.isgenerator(myGen) doist.do(doers=[b.myDo]) assert b.myDo.done == False assert b.x == 6 b.x = 1 assert b.x == 1 doist.tyme = 0.0 dodoer = doing.DoDoer(doers=[b.myDo]) doist.do(doers=[dodoer]) assert b.myDo.done == False assert b.x == 6 """End Test"""
def test_issuing(): sidSalt = coring.Salter(raw=b'0123456789abcdef').qb64 with basing.openDB(name="sid") as sidDB, \ keeping.openKS(name="sid") as sidKS, \ basing.openDB(name="red") as redDB, \ openPocket(name="red") as redPDB: limit = 1.0 tock = 1.0 doist = doing.Doist(limit=limit, tock=tock) sidHab = habbing.Habitat(ks=sidKS, db=sidDB, salt=sidSalt, temp=True) sidPre = sidHab.pre assert sidPre == "E4YPqsEOaPNaZxVIbY-Gx2bJgP-c7AH_K7pEE-YfcI9E" sidIcpMsg = sidHab.makeOwnInception() redKvy = eventing.Kevery(db=redDB) parsing.Parser().parse(ims=bytearray(sidIcpMsg), kvy=redKvy) assert redKvy.kevers[sidPre].sn == 0 # accepted event sed = dict() sed["$id"] = "" sed["$schema"] = "http://json-schema.org/draft-07/schema#" sed.update( dict(type="object", properties=dict(id=dict(type="string"), lei=dict(type="string")))) schemer = scheming.Schemer(sed=sed, code=coring.MtrDex.Blake3_256) assert schemer.said == "EeCCZi1R5xHUlhsyQNm_7NrUQTEKZH5P9vBomnc9AihY" cache = scheming.CacheResolver() cache.add(schemer.said, schemer.raw) jsonSchema = JSONSchema(resolver=cache) # Create Red's wallet and Issue Handler for receiving the credential redWallet = Wallet(hab=sidHab, db=redPDB) redIssueHandler = IssueHandler(wallet=redWallet, typ=jsonSchema) redExc = exchanging.Exchanger(hab=sidHab, tymth=doist.tymen(), handlers=[redIssueHandler]) # Build the credential subject and then the Credentialer for the full credential credSubject = dict( id= "did:keri:Efaavv0oadfghasdfn443fhbyyr4v", # this needs to be generated from a KEL lei="254900OPPU84GM83MG36", issuanceDate="2021-06-27T21:26:21.233257+00:00", ) creder = credential(issuer=sidHab.pre, schema=schemer.said, subject=credSubject, typ=jsonSchema) assert creder.said == "EgaaYOPdG7vootT99cmClvwOoM-hjUIpv5Xl6hFuTcyM" msg = sidHab.endorse(serder=creder) assert msg == ( b'{"v":"KERI10JSON000136_","i":"EgaaYOPdG7vootT99cmClvwOoM-hjUIpv5Xl6hFuTcyM",' b'"x":"EeCCZi1R5xHUlhsyQNm_7NrUQTEKZH5P9vBomnc9AihY","ti":"E4YPqsEOaPNaZxVIbY-Gx2bJgP-c7AH_K7pEE-YfcI9E",' b'"d":{"id":"did:keri:Efaavv0oadfghasdfn443fhbyyr4v","lei":"254900OPPU84GM83MG36",' b'"issuanceDate":"2021-06-27T21:26:21.233257+00:00"}}-VA0-FABE4YPqsEOaPNaZxVIbY-Gx2bJgP-c7AH_K7pEE' b'-YfcI9E0AAAAAAAAAAAAAAAAAAAAAAAElHzHwX3V6itsD2Ksg_CNBbUNTBYzLYw-AxDNI7_ZmaI' b'-AABAA0pXbQllgzXr88IczAnsPrdhgFKs9wNQvfSfzyrtcvbTwq-U1DmBluAklntCqH1AbBL6TWLZIDGi83BHLWJ82CA' ) # Create the issue credential payload pl = dict(vc=[envelope(msg, typ=jsonSchema)]) # Create the `exn` message for issue credential sidExcSrdr = exchanging.exchange(route="/credential/issue", payload=pl) excMsg = sidHab.sanction(sidExcSrdr) # Parse the exn issue credential message on Red's side parsing.Parser().parse(ims=bytearray(excMsg), kvy=redKvy, exc=redExc) doist.do(doers=[redExc]) assert doist.tyme == limit ser = ( b'{"v":"KERI10JSON000136_","i":"EgaaYOPdG7vootT99cmClvwOoM-hjUIpv5Xl6hFuTcyM",' b'"x":"EeCCZi1R5xHUlhsyQNm_7NrUQTEKZH5P9vBomnc9AihY","ti":"E4YPqsEOaPNaZxVIbY-Gx2bJgP-c7AH_K7pEE-YfcI9E",' b'"d":{"id":"did:keri:Efaavv0oadfghasdfn443fhbyyr4v","lei":"254900OPPU84GM83MG36",' b'"issuanceDate":"2021-06-27T21:26:21.233257+00:00"}}') sig0 = ( b'AA0pXbQllgzXr88IczAnsPrdhgFKs9wNQvfSfzyrtcvbTwq-U1DmBluAklntCqH1AbBL6TWLZIDGi83BHLWJ82CA' ) # verify we can load serialized VC by SAID key = creder.said.encode("utf-8") assert redPDB.getSers(key) == ser # verify the signature sigs = redPDB.getSigs(key) assert len(sigs) == 1 assert sigs[0] == sig0 # verify we can look up credential by Schema SAID schema = redPDB.getSchms(schemer.saider.qb64b) assert len(schema) == 1 assert schema[0] == key
def test_directing_basic(): """ Test directing """ help.ogler.resetLevel(level=logging.DEBUG) # set of secrets (seeds for private keys) bobSecrets = [ 'ArwXoACJgOleVZ2PY7kXn7rA0II0mHYDhc6WrBH8fDAc', 'A6zz7M08-HQSFq92sJ8KJOT2cZ47x7pXFQLPB0pckB3Q', 'AcwFTk-wgk3ZT2buPRIbK-zxgPx-TKbaegQvPEivN90Y', 'Alntkt3u6dDgiQxTATr01dy8M72uuaZEf9eTdM-70Gk8', 'A1-QxDkso9-MR1A8rZz_Naw6fgaAtayda8hrbkRVVu1E', 'AKuYMe09COczwf2nIoD5AE119n7GLFOVFlNLxZcKuswc', 'AxFfJTcSuEE11FINfXMqWttkZGnUZ8KaREhrnyAXTsjw', 'ALq-w1UKkdrppwZzGTtz4PWYEeWm0-sDHzOv5sq96xJY' ] bobSecrecies = [] for secret in bobSecrets: # convert secrets to secrecies bobSecrecies.append([secret]) # create bob signers bobSigners = [coring.Signer(qb64=secret) for secret in bobSecrets] assert [signer.qb64 for signer in bobSigners] == bobSecrets # bob inception transferable (nxt digest not empty) bobSerder = eventing.incept( keys=[bobSigners[0].verfer.qb64], nxt=coring.Nexter(keys=[bobSigners[1].verfer.qb64]).qb64, code=coring.MtrDex.Blake3_256) bob = bobSerder.ked["i"] assert bob == 'EQf1hzB6s5saaQPdDAsEzSMEFoQx_WLsq93bjPu5wuqA' # set of secrets (seeds for private keys) eveSecrets = [ 'AgjD4nRlycmM5cPcAkfOATAp8wVldRsnc9f1tiwctXlw', 'AKUotEE0eAheKdDJh9QvNmSEmO_bjIav8V_GmctGpuCQ', 'AK-nVhMMJciMPvmF5VZE_9H-nhrgng9aJWf7_UHPtRNM', 'AT2cx-P5YUjIw_SLCHQ0pqoBWGk9s4N1brD-4pD_ANbs', 'Ap5waegfnuP6ezC18w7jQiPyQwYYsp9Yv9rYMlKAYL8k', 'Aqlc_FWWrxpxCo7R12uIz_Y2pHUH2prHx1kjghPa8jT8', 'AagumsL8FeGES7tYcnr_5oN6qcwJzZfLKxoniKUpG4qc', 'ADW3o9m3udwEf0aoOdZLLJdf1aylokP0lwwI_M2J9h0s' ] eveSecrecies = [] for secret in eveSecrets: # convert secrets to secrecies eveSecrecies.append([secret]) # create eve signers eveSigners = [coring.Signer(qb64=secret) for secret in eveSecrets] assert [signer.qb64 for signer in eveSigners] == eveSecrets # eve inception transferable (nxt digest not empty) eveSerder = eventing.incept( keys=[eveSigners[0].verfer.qb64], nxt=coring.Nexter(keys=[eveSigners[1].verfer.qb64]).qb64, code=coring.MtrDex.Blake3_256) eve = eveSerder.ked["i"] assert eve == 'ED9EB3sA5u2vCPOEmX3d7bEyHiSh7Xi8fjew2KMl3FQM' with dbing.openDB(name="eve") as eveDB, keeping.openKS(name="eve") as eveKS, \ dbing.openDB(name="bob") as bobDB, keeping.openKS(name="bob") as bobKS: limit = 0.125 tock = 0.03125 doist = doing.Doist(limit=limit, tock=tock) bobPort = 5620 # bob's TCP listening port for server evePort = 5621 # eve's TCP listneing port for server bobKevers = dict() eveKevers = dict() # setup bob bobHab = directing.Habitat(ks=bobKS, db=bobDB, kevers=bobKevers, secrecies=bobSecrecies, temp=True) assert bobHab.ks == bobKS assert bobHab.db == bobDB assert bobHab.iserder.dig == bobSerder.dig assert bobHab.pre == bob bobClient = clienting.Client(tymth=doist.tymen(), host='127.0.0.1', port=evePort) bobClientDoer = doing.ClientDoer(tymth=doist.tymen(), client=bobClient) bobDirector = directing.Director(hab=bobHab, client=bobClient) assert bobDirector.hab == bobHab assert bobDirector.client == bobClient assert id(bobDirector.hab.kvy.kevers) == id(bobKevers) assert bobDirector.hab.kvy.db == bobDB bobReactor = directing.Reactor(hab=bobHab, client=bobClient) assert bobReactor.hab == bobHab assert bobReactor.client == bobClient assert id(bobReactor.hab.kvy.kevers) == id(bobKevers) assert bobReactor.hab.kvy.db == bobDB assert id(bobReactor.kevery.ims) == id(bobReactor.client.rxbs) assert id(bobReactor.client.rxbs) == id(bobDirector.client.rxbs) bobServer = serving.Server(host="", port=bobPort) bobServerDoer = doing.ServerDoer(server=bobServer) bobDirectant = directing.Directant(hab=bobHab, server=bobServer) assert bobDirectant.hab == bobHab assert bobDirectant.server == bobServer # Bob's Reactants created on demand # setup eve eveHab = directing.Habitat(ks=eveKS, db=eveDB, kevers=eveKevers, secrecies=eveSecrecies, temp=True) assert eveHab.ks == eveKS assert eveHab.db == eveDB assert eveHab.iserder.dig == eveSerder.dig assert eveHab.pre == eve eveClient = clienting.Client(tymth=doist.tymen(), host='127.0.0.1', port=bobPort) eveClientDoer = doing.ClientDoer(tymth=doist.tymen(), client=eveClient) eveDirector = directing.Director(hab=eveHab, client=eveClient) assert eveDirector.hab == eveHab assert eveDirector.client == eveClient assert id(eveDirector.hab.kvy.kevers) == id(eveKevers) assert eveDirector.hab.kvy.db == eveDB eveReactor = directing.Reactor(hab=eveHab, client=eveClient) assert eveReactor.hab == eveHab assert eveReactor.client == eveClient assert id(eveReactor.hab.kvy.kevers) == id(eveKevers) assert eveReactor.hab.kvy.db == eveDB assert id(eveReactor.kevery.ims) == id(eveReactor.client.rxbs) assert id(eveReactor.client.rxbs) == id(eveDirector.client.rxbs) eveServer = serving.Server(host="", port=evePort) eveServerDoer = doing.ServerDoer(server=eveServer) eveDirectant = directing.Directant(hab=eveHab, server=eveServer) assert eveDirectant.hab == eveHab assert eveDirectant.server == eveServer # Eve's Reactants created on demand bobMsgTx = b"Hi Eve I am Bob" bobDirector.client.tx(bobMsgTx) eveMsgTx = b"Hi Bob its me Eve" eveDirector.client.tx(eveMsgTx) doers = [ bobClientDoer, bobDirector, bobReactor, bobServerDoer, bobDirectant, eveClientDoer, eveDirector, eveReactor, eveServerDoer, eveDirectant ] doist.do(doers=doers) assert doist.tyme == limit assert bobClient.opened == False assert bobServer.opened == False assert eveClient.opened == False assert eveServer.opened == False assert not bobClient.txbs ca, ix = list(eveServer.ixes.items())[0] eveMsgRx = bytes(ix.rxbs) # ColdStart Error fluhes buffer assert eveMsgRx == b'' # assert eveMsgRx == bobMsgTx assert not eveClient.txbs ca, ix = list(bobServer.ixes.items())[0] bobMsgRx = bytes(ix.rxbs) # ColdStart Error fluhes buffer assert bobMsgRx == b'' # assert bobMsgRx == eveMsgTx assert not os.path.exists(eveDB.path) assert not os.path.exists(bobDB.path) help.ogler.resetLevel(level=help.ogler.level) """End Test"""