Browse Source

add color support

PYADPT-55
Volker Birk 6 years ago
parent
commit
66d8b32379
  1. 4
      test/README.md
  2. 21
      test/sync_handshake.py
  3. 10
      test/sync_test.py

4
test/README.md

@ -21,3 +21,7 @@ $ HOME=$PWD lldb python3 -- ../sync_handshake.py -e Phone
Then this side is doing a replay in the debugger. Using touch to set a Then this side is doing a replay in the debugger. Using touch to set a
different timestamp on the marker will only partly replay. different timestamp on the marker will only partly replay.
= Hint =
installing termcolor can be helpful

21
test/sync_handshake.py

@ -22,9 +22,15 @@ import os
import pEp import pEp
import minimail import minimail
try:
from termcolor import colored
except:
colored = lambda x, y: x
inbox = pathlib.Path("..") / "TestInbox" inbox = pathlib.Path("..") / "TestInbox"
device_name = "" device_name = ""
output = print
def messageToSend(msg): def messageToSend(msg):
@ -32,19 +38,24 @@ def messageToSend(msg):
m, keys, rating, flags = msg.decrypt() m, keys, rating, flags = msg.decrypt()
else: else:
m = msg m = msg
print("<!-- " + str(m.from_) + " -->\n" + m.attachments[0].decode()) output("<!-- " + str(m.from_) + " -->\n" + m.attachments[0].decode())
minimail.send(inbox, msg, device_name) minimail.send(inbox, msg, device_name)
class UserInterface(pEp.UserInterface): class UserInterface(pEp.UserInterface):
def notifyHandshake(self, me, partner, signal): def notifyHandshake(self, me, partner, signal):
print("on " + device_name + " signal " + str(signal) + " for identities " + str(me.fpr) + " " + output("on " + device_name + " signal " + str(signal) + " for identities " + str(me.fpr) + " " +
str(partner.fpr)) str(partner.fpr))
def run(name): def run(name, color=None):
global device_name global device_name
device_name = name device_name = name
if color:
global output
output = lambda x: print(colored(x, color))
me = pEp.Identity("alice@peptest.ch", name + " of Alice Neuman") me = pEp.Identity("alice@peptest.ch", name + " of Alice Neuman")
pEp.myself(me) pEp.myself(me)
pEp.messageToSend = messageToSend pEp.messageToSend = messageToSend
@ -69,10 +80,12 @@ if __name__=="__main__":
optParser.add_option("-e", "--exec-for", action="store", type="string", optParser.add_option("-e", "--exec-for", action="store", type="string",
dest="exec_for", help="execute for name of simulated device " + dest="exec_for", help="execute for name of simulated device " +
"(default: name of actual directory)") "(default: name of actual directory)")
optParser.add_option("--color", action="store", type="string",
desct="color", help="print debug output in this color")
options, args = optParser.parse_args() options, args = optParser.parse_args()
if not options.exec_for: if not options.exec_for:
options.exec_for = os.path.basename(os.getcwd()) options.exec_for = os.path.basename(os.getcwd())
run(options.exec_for) run(options.exec_for, options.color)

10
test/sync_test.py

@ -19,14 +19,14 @@ import shutil
import pathlib import pathlib
def test_for(path): def test_for(path, color=None):
cwd = os.getcwd(); cwd = os.getcwd();
os.chdir(path) os.chdir(path)
os.environ["HOME"] = os.getcwd() os.environ["HOME"] = os.getcwd()
print("running tests for " + path); print("running tests for " + path)
from sync_handshake import run from sync_handshake import run
run(path) run(path, color)
os.chdir(cwd) os.chdir(cwd)
@ -121,8 +121,8 @@ if __name__ == "__main__":
setup("Phone") setup("Phone")
setup("Laptop") setup("Laptop")
Phone = Process(target=test_for, args=("Phone",)) Phone = Process(target=test_for, args=("Phone", "red"))
Laptop = Process(target=test_for, args=("Laptop",)) Laptop = Process(target=test_for, args=("Laptop", "green"))
Phone.start() Phone.start()
Laptop.start() Laptop.start()

Loading…
Cancel
Save