From 0781222bdc1530ea32356a85184967ea7e93091f Mon Sep 17 00:00:00 2001 From: Benedek Racz Date: Sun, 29 Sep 2019 17:13:48 +0200 Subject: [PATCH] [FIX] #11 a very similar issue can be reproduced --- issues/i11_greek_parent.py | 44 ++++++++++++++++++++++++++++++++ issues/i11_greek_printer.py | 45 ++++++++++++++++++++++++++++++++ issues/i11_unicode_parent.py | 48 +++++++++++++++++++++++++++++++++++ issues/i11_unicode_printer.py | 21 +++++++++++++++ 4 files changed, 158 insertions(+) create mode 100644 issues/i11_greek_parent.py create mode 100644 issues/i11_greek_printer.py create mode 100644 issues/i11_unicode_parent.py create mode 100644 issues/i11_unicode_printer.py diff --git a/issues/i11_greek_parent.py b/issues/i11_greek_parent.py new file mode 100644 index 0000000..5d51f7c --- /dev/null +++ b/issues/i11_greek_parent.py @@ -0,0 +1,44 @@ + +import wexpect +import time +import sys +import os + +here = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, here) + +import i11_greek_printer + +print(wexpect.__version__) + +# With quotes (C:\Program Files\Python37\python.exe needs quotes) +python_executable = '"' + sys.executable + '" ' +child_script = here + '\\i11_greek_printer.py' + + +def main(): + unicodePrinter = python_executable + ' ' + child_script + prompt = 'give the name of a greek letter> ' + + # Start the child process + print('starting child: ' + unicodePrinter) + p = wexpect.spawn(unicodePrinter) + print('waiting for prompt') + + # Wait for prompt + p.expect(prompt) + print('Child prompt arrived, lets start commands!') + + # Send commands + for letterName in i11_greek_printer.greekLetters.keys(): + p.sendline(letterName) + p.expect(prompt) + print(p.before.splitlines()[1]) + if i11_greek_printer.greekLetters[letterName] != p.before.splitlines()[1]: + p.interact() + time.sleep(5) + raise Exception() + + +main() + diff --git a/issues/i11_greek_printer.py b/issues/i11_greek_printer.py new file mode 100644 index 0000000..2469914 --- /dev/null +++ b/issues/i11_greek_printer.py @@ -0,0 +1,45 @@ +greekLetters = { + 'ALPHA': '\u03B1', + 'BETA': '\u03B2', + 'GAMMA': '\u03B3', + 'DELTA': '\u03B4', + 'EPSILON': '\u03B5', + 'ZETA': '\u03B6', + 'ETA': '\u03B7', + 'THETA': '\u03B8', + 'IOTA': '\u03B9', + 'KAPPA': '\u03BA', + 'LAMDA': '\u03BB', + 'MU': '\u03BC', + 'NU': '\u03BD', + 'XI': '\u03BE', + 'OMICRON': '\u03BF', + 'PI': '\u03C0', + 'RHO': '\u03C1', + 'FINAL SIGMA': '\u03C2', + 'SIGMA': '\u03C3', + 'TAU': '\u03C4', + 'UPSILON': '\u03C5', + 'PHI': '\u03C6', + 'CHI': '\u03C7', + 'PSI': '\u03C8', + 'OMEGA': '\u03C9' + } + +def main(): + while True: + letter = input('give the name of a greek letter> ') + if letter.lower() == 'exit': + print('Bye') + break + if letter.lower() == 'all': + print(greekLetters) + continue + try: + print(greekLetters[letter.upper()]) + except: + print('ERROR!!! Uunknkown letter') + +if __name__ == '__main__': + main() + \ No newline at end of file diff --git a/issues/i11_unicode_parent.py b/issues/i11_unicode_parent.py new file mode 100644 index 0000000..36487fa --- /dev/null +++ b/issues/i11_unicode_parent.py @@ -0,0 +1,48 @@ + +import wexpect +import time +import sys +import os + +here = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, here) + +import i11_unicode_printer + +print(wexpect.__version__) + +encodings = ['cp1250', 'utf-8'] + + +# With quotes (C:\Program Files\Python37\python.exe needs quotes) +python_executable = '"' + sys.executable + '" ' +child_script = here + '\\i11_unicode_printer.py' + + +def main(): + unicodePrinter = python_executable + ' ' + child_script + prompt = '> ' + + for ec in encodings: + # Start the child process + p = wexpect.spawn(unicodePrinter) + + # Wait for prompt + p.expect(prompt) + print('Child prompt arrived, lets set encoding!') + p.sendline(ec) + p.expect(prompt) + + # Send commands + for cc in range(34, 500): + p.sendline(str(cc)) + p.expect(prompt) + print(p.before.splitlines()[1]) + if chr(int(cc)).encode("utf-8").decode(ec) != p.before.splitlines()[1]: + p.interact() + time.sleep(5) + raise Exception() + + +main() + diff --git a/issues/i11_unicode_printer.py b/issues/i11_unicode_printer.py new file mode 100644 index 0000000..f2fafe3 --- /dev/null +++ b/issues/i11_unicode_printer.py @@ -0,0 +1,21 @@ + + +def main(): + encoding = "utf-8" + encoding = input('give the encoding> ') + while True: + code = input('give a number> ') + if code.lower() == 'exit': + print('Bye') + break + try: + print(chr(int(code)).encode("utf-8").decode(encoding) ) + # code_int = int(code) + # print(greekLetters[letter.upper()]) + except: + print('ERROR!!!') + raise + +if __name__ == '__main__': + main() + \ No newline at end of file