From b6e437cc68b9afaf461f002c1cd45880118056e8 Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Sun, 24 Feb 2019 06:04:05 +0100 Subject: [PATCH] command line option --- test/sync_handshake.py | 18 +++++++++++++++--- test/sync_test.py | 43 ++++++++++++++++++++++-------------------- 2 files changed, 38 insertions(+), 23 deletions(-) diff --git a/test/sync_handshake.py b/test/sync_handshake.py index 0d443ff..b696aad 100644 --- a/test/sync_handshake.py +++ b/test/sync_handshake.py @@ -18,12 +18,24 @@ def messageToSend(msg): class UserInterface(pEp.UserInterface): def notifyHandshake(self, me, partner, signal): - print("signal " + str(signal) + " for identities " + str(me) + " " + str(partner)) + print("signal " + str(signal) + " for identities " + str(me) + " " + + str(partner)) -def run(path): - me = pEp.Identity("alice@peptest.ch", path + " Neuman") +def run(name): + me = pEp.Identity("alice@peptest.ch", name + " Neuman") pEp.myself(me) pEp.messageToSend = messageToSend ui = UserInterface() + +if __name__=="__main__": + from optparse import OptionParser + + optParser = OptionParser() + optParser.add_option("-e", "--exec-for", action="store", type="string", + dest="exec_for", help="execute for name") + options, args = optParser.parse_args() + + run(options.exec_for) + diff --git a/test/sync_test.py b/test/sync_test.py index af1fabe..30a5ccb 100644 --- a/test/sync_test.py +++ b/test/sync_test.py @@ -9,7 +9,6 @@ import os, pathlib, sys -from optparse import OptionParser def test_for(path): @@ -71,28 +70,32 @@ def waitpid(pid): return -optParser = OptionParser() -optParser.add_option("-c", "--clean", action="store_true", dest="clean") -(options, args) = optParser.parse_args() +if __name__ == "__main__": + from optparse import OptionParser -if options.clean: - rmrf("TestInbox") - rmrf("Alice") - rmrf("Barbara") + optParser = OptionParser() + optParser.add_option("-c", "--clean", action="store_true", dest="clean", + help="remove all generated files") + options, args = optParser.parse_args() -else: - os.makedirs("TestInbox", exist_ok=True) - setup("Alice") - setup("Barbara") + if options.clean: + rmrf("TestInbox") + rmrf("Alice") + rmrf("Barbara") - Alice = os.fork() - if Alice == 0: - test_for("Alice") else: - Barbara = os.fork() - if Barbara == 0: - test_for("Barbara") + os.makedirs("TestInbox", exist_ok=True) + setup("Alice") + setup("Barbara") + + Alice = os.fork() + if Alice == 0: + test_for("Alice") else: - waitpid(Alice) - waitpid(Barbara) + Barbara = os.fork() + if Barbara == 0: + test_for("Barbara") + else: + waitpid(Alice) + waitpid(Barbara)