end on notifications feature sync
authorVolker Birk <vb@pep-project.org>
Sun, 14 Apr 2019 22:30:55 +0200
branchsync
changeset 26955667d28329a
parent 268 81bfa5a09184
child 270 f8e25f0b6e50
end on notifications feature
test/sync_handshake.py
test/sync_test.py
     1.1 --- a/test/sync_handshake.py	Sun Apr 14 20:56:24 2019 +0200
     1.2 +++ b/test/sync_handshake.py	Sun Apr 14 22:30:55 2019 +0200
     1.3 @@ -47,6 +47,10 @@
     1.4  SYNC_HANDSHAKE_REJECTED = 1
     1.5  
     1.6  the_end = False
     1.7 +end_on = (
     1.8 +        pEp.sync_handshake_signal.SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED,
     1.9 +        pEp.sync_handshake_signal.SYNC_NOTIFY_ACCEPTED_GROUP_CREATED
    1.10 +    )
    1.11  
    1.12  
    1.13  def print_msg(p):
    1.14 @@ -108,10 +112,7 @@
    1.15  
    1.16              except NameError:
    1.17                  self.deliverHandshakeResult(SYNC_HANDSHAKE_ACCEPTED)
    1.18 -        elif signal in (
    1.19 -                pEp.sync_handshake_signal.SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED,
    1.20 -                pEp.sync_handshake_signal.SYNC_NOTIFY_ACCEPTED_GROUP_CREATED
    1.21 -            ):
    1.22 +        if signal in end_on:
    1.23              global the_end
    1.24              the_end = True
    1.25  
    1.26 @@ -157,10 +158,18 @@
    1.27              help="reject device group")
    1.28      optParser.add_option("--accept", action="store_false", dest="reject",
    1.29              help="accept device group (default)")
    1.30 +    optParser.add_option("-E", "--end-on", dest="notifications",
    1.31 +            help="end on these notifications")
    1.32      options, args = optParser.parse_args()
    1.33  
    1.34      if not options.exec_for:
    1.35          options.exec_for = os.path.basename(os.getcwd())
    1.36  
    1.37 +    if options.notifications:
    1.38 +        end_on = eval(options.notifications)
    1.39 +        try: None in end_on
    1.40 +        except TypeError:
    1.41 +            end_on = (end_on,)
    1.42 +
    1.43      run(options.exec_for, options.color)
    1.44  
     2.1 --- a/test/sync_test.py	Sun Apr 14 20:56:24 2019 +0200
     2.2 +++ b/test/sync_test.py	Sun Apr 14 22:30:55 2019 +0200
     2.3 @@ -20,14 +20,16 @@
     2.4  import pathlib
     2.5  
     2.6  
     2.7 -def test_for(path, color=None):
     2.8 +def test_for(path, color=None, end_on=None):
     2.9      cwd = os.getcwd();
    2.10      os.chdir(path)
    2.11      os.environ["HOME"] = os.getcwd()
    2.12  
    2.13      print("running tests for " + path)
    2.14 -    from sync_handshake import run
    2.15 -    run(path, color)
    2.16 +    import sync_handshake
    2.17 +    if end_on:
    2.18 +        sync_handshake.end_on = end_on
    2.19 +    sync_handshake.run(path, color)
    2.20  
    2.21      os.chdir(cwd)
    2.22  
    2.23 @@ -85,6 +87,8 @@
    2.24              help="setup environment, then stop")
    2.25      optParser.add_option("-p", "--print", action="store_true", dest="print",
    2.26              help="print sync message trace in inbox")
    2.27 +    optParser.add_option("-E", "--end-on", dest="notifications",
    2.28 +            help="end on these notifications")
    2.29      options, args = optParser.parse_args()
    2.30  
    2.31      if options.cleanall:
    2.32 @@ -139,8 +143,14 @@
    2.33          setup("Laptop")
    2.34  
    2.35          if not options.setup_only:
    2.36 -            Phone = Process(target=test_for, args=("Phone", "red"))
    2.37 -            Laptop = Process(target=test_for, args=("Laptop", "green"))
    2.38 +            end_on = None
    2.39 +            if options.notifications:
    2.40 +                end_on = eval(options.notifications)
    2.41 +                try: None in end_on
    2.42 +                except TypeError:
    2.43 +                    end_on = (end_on,)
    2.44 +            Phone = Process(target=test_for, args=("Phone", "red", end_on))
    2.45 +            Laptop = Process(target=test_for, args=("Laptop", "green", end_on))
    2.46  
    2.47              Phone.start()
    2.48              Laptop.start()