From ee2ef4b4ba32765d6a2e2b5fe3c8e5f52b6b1159 Mon Sep 17 00:00:00 2001 From: Volker Birk Date: Sun, 14 Apr 2019 22:30:55 +0200 Subject: [PATCH] end on notifications feature --- test/sync_handshake.py | 17 +++++++++++++---- test/sync_test.py | 20 +++++++++++++++----- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/test/sync_handshake.py b/test/sync_handshake.py index 91957bd..fb20c36 100644 --- a/test/sync_handshake.py +++ b/test/sync_handshake.py @@ -47,6 +47,10 @@ SYNC_HANDSHAKE_ACCEPTED = 0 SYNC_HANDSHAKE_REJECTED = 1 the_end = False +end_on = ( + pEp.sync_handshake_signal.SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED, + pEp.sync_handshake_signal.SYNC_NOTIFY_ACCEPTED_GROUP_CREATED + ) def print_msg(p): @@ -108,10 +112,7 @@ class UserInterface(pEp.UserInterface): except NameError: self.deliverHandshakeResult(SYNC_HANDSHAKE_ACCEPTED) - elif signal in ( - pEp.sync_handshake_signal.SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED, - pEp.sync_handshake_signal.SYNC_NOTIFY_ACCEPTED_GROUP_CREATED - ): + if signal in end_on: global the_end the_end = True @@ -157,10 +158,18 @@ if __name__=="__main__": help="reject device group") optParser.add_option("--accept", action="store_false", dest="reject", help="accept device group (default)") + optParser.add_option("-E", "--end-on", dest="notifications", + help="end on these notifications") options, args = optParser.parse_args() if not options.exec_for: options.exec_for = os.path.basename(os.getcwd()) + if options.notifications: + end_on = eval(options.notifications) + try: None in end_on + except TypeError: + end_on = (end_on,) + run(options.exec_for, options.color) diff --git a/test/sync_test.py b/test/sync_test.py index 4d6bca7..03cc160 100644 --- a/test/sync_test.py +++ b/test/sync_test.py @@ -20,14 +20,16 @@ import shutil import pathlib -def test_for(path, color=None): +def test_for(path, color=None, end_on=None): cwd = os.getcwd(); os.chdir(path) os.environ["HOME"] = os.getcwd() print("running tests for " + path) - from sync_handshake import run - run(path, color) + import sync_handshake + if end_on: + sync_handshake.end_on = end_on + sync_handshake.run(path, color) os.chdir(cwd) @@ -85,6 +87,8 @@ if __name__ == "__main__": help="setup environment, then stop") optParser.add_option("-p", "--print", action="store_true", dest="print", help="print sync message trace in inbox") + optParser.add_option("-E", "--end-on", dest="notifications", + help="end on these notifications") options, args = optParser.parse_args() if options.cleanall: @@ -139,8 +143,14 @@ if __name__ == "__main__": setup("Laptop") if not options.setup_only: - Phone = Process(target=test_for, args=("Phone", "red")) - Laptop = Process(target=test_for, args=("Laptop", "green")) + end_on = None + if options.notifications: + end_on = eval(options.notifications) + try: None in end_on + except TypeError: + end_on = (end_on,) + Phone = Process(target=test_for, args=("Phone", "red", end_on)) + Laptop = Process(target=test_for, args=("Laptop", "green", end_on)) Phone.start() Laptop.start()