http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/a1a2f2c5/tools/bin/pythonSrc/pexpect-4.2/tests/test_run.py ---------------------------------------------------------------------- diff --git a/tools/bin/pythonSrc/pexpect-4.2/tests/test_run.py b/tools/bin/pythonSrc/pexpect-4.2/tests/test_run.py new file mode 100755 index 0000000..1b3c92f --- /dev/null +++ b/tools/bin/pythonSrc/pexpect-4.2/tests/test_run.py @@ -0,0 +1,191 @@ +#!/usr/bin/env python +# encoding: utf-8 +''' +PEXPECT LICENSE + + This license is approved by the OSI and FSF as GPL-compatible. + http://opensource.org/licenses/isc-license.txt + + Copyright (c) 2012, Noah Spurrier <[email protected]> + PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY + PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE + COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES. + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +''' +import pexpect +import unittest +import subprocess +import tempfile +import sys +import os +from . import PexpectTestCase + +unicode_type = str if pexpect.PY3 else unicode + + +def timeout_callback(values): + if values["event_count"] > 3: + return 1 + return 0 + + +def function_events_callback(values): + try: + previous_echoed = (values["child_result_list"][-1] + .decode().split("\n")[-2].strip()) + if previous_echoed.endswith("stage-1"): + return "echo stage-2\n" + elif previous_echoed.endswith("stage-2"): + return "echo stage-3\n" + elif previous_echoed.endswith("stage-3"): + return "exit\n" + else: + raise Exception("Unexpected output {0}".format(previous_echoed)) + except IndexError: + return "echo stage-1\n" + + +class RunFuncTestCase(PexpectTestCase.PexpectTestCase): + runfunc = staticmethod(pexpect.run) + cr = b'\r' + empty = b'' + prep_subprocess_out = staticmethod(lambda x: x) + + def setUp(self): + fd, self.rcfile = tempfile.mkstemp() + os.write(fd, b'PS1=GO: \n') + os.close(fd) + super(RunFuncTestCase, self).setUp() + + def tearDown(self): + os.unlink(self.rcfile) + super(RunFuncTestCase, self).tearDown() + + def test_run_exit(self): + (data, exitstatus) = self.runfunc('python exit1.py', withexitstatus=1) + assert exitstatus == 1, "Exit status of 'python exit1.py' should be 1." + + def test_run(self): + the_old_way = subprocess.Popen( + args=['uname', '-m', '-n'], + stdout=subprocess.PIPE + ).communicate()[0].rstrip() + + (the_new_way, exitstatus) = self.runfunc( + 'uname -m -n', withexitstatus=1) + the_new_way = the_new_way.replace(self.cr, self.empty).rstrip() + + self.assertEqual(self.prep_subprocess_out(the_old_way), the_new_way) + self.assertEqual(exitstatus, 0) + + def test_run_callback(self): + # TODO it seems like this test could block forever if run fails... + events = {pexpect.TIMEOUT: timeout_callback} + self.runfunc("cat", timeout=1, events=events) + + def test_run_bad_exitstatus(self): + (the_new_way, exitstatus) = self.runfunc( + 'ls -l /najoeufhdnzkxjd', withexitstatus=1) + assert exitstatus != 0 + + def test_run_event_as_string(self): + events = [ + # second match on 'abc', echo 'def' + ('abc\r\n.*GO:', 'echo "def"\n'), + # final match on 'def': exit + ('def\r\n.*GO:', 'exit\n'), + # first match on 'GO:' prompt, echo 'abc' + ('GO:', 'echo "abc"\n') + ] + + (data, exitstatus) = pexpect.run( + 'bash --rcfile {0}'.format(self.rcfile), + withexitstatus=True, + events=events, + timeout=10) + assert exitstatus == 0 + + def test_run_event_as_function(self): + events = [ + ('GO:', function_events_callback) + ] + + (data, exitstatus) = pexpect.run( + 'bash --rcfile {0}'.format(self.rcfile), + withexitstatus=True, + events=events, + timeout=10) + assert exitstatus == 0 + + def test_run_event_as_method(self): + events = [ + ('GO:', self._method_events_callback) + ] + + (data, exitstatus) = pexpect.run( + 'bash --rcfile {0}'.format(self.rcfile), + withexitstatus=True, + events=events, + timeout=10) + assert exitstatus == 0 + + def test_run_event_typeerror(self): + events = [('GO:', -1)] + with self.assertRaises(TypeError): + pexpect.run('bash --rcfile {0}'.format(self.rcfile), + withexitstatus=True, + events=events, + timeout=10) + + def _method_events_callback(self, values): + try: + previous_echoed = (values["child_result_list"][-1].decode() + .split("\n")[-2].strip()) + if previous_echoed.endswith("foo1"): + return "echo foo2\n" + elif previous_echoed.endswith("foo2"): + return "echo foo3\n" + elif previous_echoed.endswith("foo3"): + return "exit\n" + else: + raise Exception("Unexpected output {0!r}" + .format(previous_echoed)) + except IndexError: + return "echo foo1\n" + + +class RunUnicodeFuncTestCase(RunFuncTestCase): + runfunc = staticmethod(pexpect.runu) + cr = b'\r'.decode('ascii') + empty = b''.decode('ascii') + prep_subprocess_out = staticmethod(lambda x: x.decode('utf-8', 'replace')) + + def test_run_unicode(self): + if pexpect.PY3: + char = chr(254) # þ + pattern = '<in >' + else: + char = unichr(254) # analysis:ignore + pattern = '<in >'.decode('ascii') + + def callback(values): + if values['event_count'] == 0: + return char + '\n' + else: + return True # Stop the child process + + output = pexpect.runu(sys.executable + ' echo_w_prompt.py', + env={'PYTHONIOENCODING': 'utf-8'}, + events={pattern: callback}) + assert isinstance(output, unicode_type), type(output) + assert ('<out>' + char) in output, output + +if __name__ == '__main__': + unittest.main()
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/a1a2f2c5/tools/bin/pythonSrc/pexpect-4.2/tests/test_run_out_of_pty.py ---------------------------------------------------------------------- diff --git a/tools/bin/pythonSrc/pexpect-4.2/tests/test_run_out_of_pty.py b/tools/bin/pythonSrc/pexpect-4.2/tests/test_run_out_of_pty.py new file mode 100755 index 0000000..3090147 --- /dev/null +++ b/tools/bin/pythonSrc/pexpect-4.2/tests/test_run_out_of_pty.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python +''' +PEXPECT LICENSE + + This license is approved by the OSI and FSF as GPL-compatible. + http://opensource.org/licenses/isc-license.txt + + Copyright (c) 2012, Noah Spurrier <[email protected]> + PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY + PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE + COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES. + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +''' +import pexpect +import unittest +from . import PexpectTestCase + +class ExpectTestCase(PexpectTestCase.PexpectTestCase): + # This takes too long to run and isn't all that interesting of a test. + def OFF_test_run_out_of_pty (self): + '''This assumes that the tested platform has < 10000 pty devices. + This test currently does not work under Solaris. + Under Solaris it runs out of file descriptors first and + ld.so starts to barf: + ld.so.1: pt_chmod: fatal: /usr/lib/libc.so.1: Too many open files + ''' + plist=[] + for count in range (0,10000): + try: + plist.append (pexpect.spawn('ls -l')) + except pexpect.ExceptionPexpect: + for c in range (0, count): + plist[c].close() + return + except Exception: + err = sys.exc_info()[1] + self.fail ('Expected ExceptionPexpect. ' + str(err)) + self.fail ('Could not run out of pty devices. This may be OK.') + +if __name__ == '__main__': + unittest.main() + +suite = unittest.makeSuite(ExpectTestCase,'test') + http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/a1a2f2c5/tools/bin/pythonSrc/pexpect-4.2/tests/test_screen.py ---------------------------------------------------------------------- diff --git a/tools/bin/pythonSrc/pexpect-4.2/tests/test_screen.py b/tools/bin/pythonSrc/pexpect-4.2/tests/test_screen.py new file mode 100755 index 0000000..2429e57 --- /dev/null +++ b/tools/bin/pythonSrc/pexpect-4.2/tests/test_screen.py @@ -0,0 +1,287 @@ +#!/usr/bin/env python +''' +PEXPECT LICENSE + + This license is approved by the OSI and FSF as GPL-compatible. + http://opensource.org/licenses/isc-license.txt + + Copyright (c) 2012, Noah Spurrier <[email protected]> + PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY + PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE + COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES. + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +''' + +import sys + +from pexpect import screen +import unittest +from . import PexpectTestCase + +PY3 = (sys.version_info[0] >= 3) + +fill1_target='XXXXXXXXXX\n' + \ +'XOOOOOOOOX\n' + \ +'XO::::::OX\n' + \ +'XO:oooo:OX\n' + \ +'XO:o..o:OX\n' + \ +'XO:o..o:OX\n' + \ +'XO:oooo:OX\n' + \ +'XO::::::OX\n' + \ +'XOOOOOOOOX\n' + \ +'XXXXXXXXXX' +fill2_target = 'XXXXXXXXXXX\n' + \ +'XOOOOOOOOOX\n' + \ +'XO:::::::OX\n' + \ +'XO:ooooo:OX\n' + \ +'XO:o...o:OX\n' + \ +'XO:o.+.o:OX\n' + \ +'XO:o...o:OX\n' + \ +'XO:ooooo:OX\n' + \ +'XO:::::::OX\n' + \ +'XOOOOOOOOOX\n' + \ +'XXXXXXXXXXX' +put_target = '\\.3.5.7.9/\n' + \ +'.........2\n' + \ +'3.........\n' + \ +'.........4\n' + \ +'5...\\/....\n' + \ +'..../\\...6\n' + \ +'7.........\n' + \ +'.........8\n' + \ +'9.........\n' + \ +'/2.4.6.8.\\' +scroll_target = '\\.3.5.7.9/\n' + \ +'\\.3.5.7.9/\n' + \ +'\\.3.5.7.9/\n' + \ +'\\.3.5.7.9/\n' + \ +'5...\\/....\n' + \ +'..../\\...6\n' + \ +'/2.4.6.8.\\\n' + \ +'/2.4.6.8.\\\n' + \ +'/2.4.6.8.\\\n' + \ +'/2.4.6.8.\\' +insert_target = 'ZXZZZZZZXZ\n' +\ +'.........2\n' +\ +'3.........\n' +\ +'.........4\n' +\ +'Z5...\\/...\n' +\ +'..../Z\\...\n' +\ +'7.........\n' +\ +'.........8\n' +\ +'9.........\n' +\ +'ZZ/2.4.6ZZ' +get_region_target = ['......', '.\\/...', './\\...', '......'] + +unicode_box_unicode_result = u'\u2554\u2557\n\u255A\u255D' +unicode_box_pretty_result = u'''\ ++--+ +|\u2554\u2557| +|\u255A\u255D| ++--+ +''' +unicode_box_ascii_bytes_result = b'??\n??' +unicode_box_cp437_bytes_result = b'\xc9\xbb\n\xc8\xbc' +unicode_box_utf8_bytes_result = b'\xe2\x95\x94\xe2\x95\x97\n\xe2\x95\x9a\xe2\x95\x9d' + +class screenTestCase (PexpectTestCase.PexpectTestCase): + def make_screen_with_put (self): + s = screen.screen(10,10) + s.fill ('.') + for r in range (1,s.rows + 1): + if r % 2: + s.put_abs (r, 1, str(r)) + else: + s.put_abs (r, s.cols, str(r)) + for c in range (1,s.cols + 1): + if c % 2: + s.put_abs (1, c, str(c)) + else: + s.put_abs (s.rows, c, str(c)) + s.put_abs(1,1, '\\') + s.put_abs(1,s.cols, '/') + s.put_abs(s.rows,1,'/') + s.put_abs(s.rows, s.cols, '\\') + s.put_abs(5,5,'\\') + s.put_abs(5,6,'/') + s.put_abs(6,5,'/') + s.put_abs(6,6,'\\') + return s + + def test_fill (self): + s = screen.screen (10,10) + s.fill_region (10,1,1,10,'X') + s.fill_region (2,2,9,9,'O') + s.fill_region (8,8,3,3,':') + s.fill_region (4,7,7,4,'o') + s.fill_region (6,5,5,6,'.') + assert str(s) == fill1_target + + s = screen.screen (11,11) + s.fill_region (1,1,11,11,'X') + s.fill_region (2,2,10,10,'O') + s.fill_region (9,9,3,3,':') + s.fill_region (4,8,8,4,'o') + s.fill_region (7,5,5,7,'.') + s.fill_region (6,6,6,6,'+') + assert str(s) == fill2_target + def test_put (self): + s = self.make_screen_with_put() + assert str(s) == put_target + def test_get_region (self): + s = self.make_screen_with_put() + r = s.get_region (4,4,7,9) + assert r == get_region_target + + def test_cursor_save (self): + s = self.make_screen_with_put() + s.cursor_home (5,5) + c = s.get() + s.cursor_save() + s.cursor_home() + s.cursor_forward() + s.cursor_down() + s.cursor_unsave() + assert s.cur_r == 5 and s.cur_c == 5 + assert c == s.get() + def test_scroll (self): + s = self.make_screen_with_put() + s.scroll_screen_rows (1,4) + s.scroll_down(); s.scroll_down(); s.scroll_down() + s.scroll_down(); s.scroll_down(); s.scroll_down() + s.scroll_screen_rows (7,10) + s.scroll_up(); s.scroll_up(); s.scroll_up() + s.scroll_up(); s.scroll_up(); s.scroll_up() + assert str(s) == scroll_target + def test_insert (self): + s = self.make_screen_with_put() + s.insert_abs (10,1,'Z') + s.insert_abs (1,1,'Z') + s.insert_abs (1,1,'Z') + s.insert_abs (1,1,'Z') + s.insert_abs (1,1,'Z') + s.insert_abs (1,1,'Z') + s.insert_abs (10,1,'Z') + s.insert_abs (1,1,'Z') + s.insert_abs (1,1,'Z') + s.insert_abs (5,1,'Z') + s.insert_abs (6,6,'Z') + s.cursor_home (1,1) # Also test relative insert. + s.insert ('Z') + s.insert ('Z') + s.insert ('Z') + s.insert ('Z') + s.insert_abs (1,8,'X') + s.insert_abs (1,2,'X') + s.insert_abs (10,9,'Z') + s.insert_abs (10,9,'Z') + assert str(s) == insert_target + + def make_screen_with_box_unicode(self, *args, **kwargs): + '''Creates a screen containing a box drawn using double-line + line drawing characters. The characters are fed in as + unicode. ''' + s = screen.screen (2,2,*args,**kwargs) + s.put_abs (1,1,u'\u2554') + s.put_abs (1,2,u'\u2557') + s.put_abs (2,1,u'\u255A') + s.put_abs (2,2,u'\u255D') + return s + + def make_screen_with_box_cp437(self, *args, **kwargs): + '''Creates a screen containing a box drawn using double-line + line drawing characters. The characters are fed in as + CP437. ''' + s = screen.screen (2,2,*args,**kwargs) + s.put_abs (1,1,b'\xc9') + s.put_abs (1,2,b'\xbb') + s.put_abs (2,1,b'\xc8') + s.put_abs (2,2,b'\xbc') + return s + + def make_screen_with_box_utf8(self, *args, **kwargs): + '''Creates a screen containing a box drawn using double-line + line drawing characters. The characters are fed in as + UTF-8. ''' + s = screen.screen (2,2,*args,**kwargs) + s.put_abs (1,1,b'\xe2\x95\x94') + s.put_abs (1,2,b'\xe2\x95\x97') + s.put_abs (2,1,b'\xe2\x95\x9a') + s.put_abs (2,2,b'\xe2\x95\x9d') + return s + + def test_unicode_ascii (self): + # With the default encoding set to ASCII, we should still be + # able to feed in unicode strings and get them back out: + s = self.make_screen_with_box_unicode('ascii') + if PY3: + assert str(s) == unicode_box_unicode_result + else: + assert unicode(s) == unicode_box_unicode_result + # And we should still get something for Python 2 str(), though + # it might not be very useful + str(s) + + assert s.pretty() == unicode_box_pretty_result + + def test_decoding_errors(self): + # With strict error handling, it should reject bytes it can't decode + with self.assertRaises(UnicodeDecodeError): + self.make_screen_with_box_cp437('ascii', 'strict') + + # replace should turn them into unicode replacement characters, U+FFFD + s = self.make_screen_with_box_cp437('ascii', 'replace') + expected = u'\ufffd\ufffd\n\ufffd\ufffd' + if PY3: + assert str(s) == expected + else: + assert unicode(s) == expected + + def test_unicode_cp437 (self): + # Verify decoding from and re-encoding to CP437. + s = self.make_screen_with_box_cp437('cp437','strict') + if PY3: + assert str(s) == unicode_box_unicode_result + else: + assert unicode(s) == unicode_box_unicode_result + assert str(s) == unicode_box_cp437_bytes_result + assert s.pretty() == unicode_box_pretty_result + + def test_unicode_utf8 (self): + # Verify decoding from and re-encoding to UTF-8. + s = self.make_screen_with_box_utf8('utf-8','strict') + if PY3: + assert str(s) == unicode_box_unicode_result + else: + assert unicode(s) == unicode_box_unicode_result + assert str(s) == unicode_box_utf8_bytes_result + assert s.pretty() == unicode_box_pretty_result + + def test_no_bytes(self): + s = screen.screen(2, 2, encoding=None) + s.put_abs(1, 1, u'A') + s.put_abs(2, 2, u'D') + + with self.assertRaises(TypeError): + s.put_abs(1, 2, b'B') + + if PY3: + assert str(s) == u'A \n D' + else: + assert unicode(s) == u'A \n D' + # This will still work if it's limited to ascii + assert str(s) == b'A \n D' + +if __name__ == '__main__': + unittest.main() + +suite = unittest.makeSuite(screenTestCase,'test') + + http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/a1a2f2c5/tools/bin/pythonSrc/pexpect-4.2/tests/test_socket.py ---------------------------------------------------------------------- diff --git a/tools/bin/pythonSrc/pexpect-4.2/tests/test_socket.py b/tools/bin/pythonSrc/pexpect-4.2/tests/test_socket.py new file mode 100644 index 0000000..56d69c7 --- /dev/null +++ b/tools/bin/pythonSrc/pexpect-4.2/tests/test_socket.py @@ -0,0 +1,255 @@ +#!/usr/bin/env python +''' +PEXPECT LICENSE + + This license is approved by the OSI and FSF as GPL-compatible. + http://opensource.org/licenses/isc-license.txt + + Copyright (c) 2012, Noah Spurrier <[email protected]> + PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY + PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE + COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES. + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +''' +import pexpect +from pexpect import fdpexpect +import unittest +from . import PexpectTestCase +import multiprocessing +import os +import signal +import socket +import time +import errno + + +class SocketServerError(Exception): + pass + + +class ExpectTestCase(PexpectTestCase.PexpectTestCase): + + def setUp(self): + print(self.id()) + PexpectTestCase.PexpectTestCase.setUp(self) + self.host = '127.0.0.1' + self.port = 49152 + 10000 + self.motd = b"""\ +------------------------------------------------------------------------------ +* Welcome to the SOCKET UNIT TEST code! * +------------------------------------------------------------------------------ +* * +* This unit test code is our best effort at testing the ability of the * +* pexpect library to handle sockets. We need some text to test buffer size * +* handling. * +* * +* A page is 1024 bytes or 1K. 80 x 24 = 1920. So a standard terminal window * +* contains more than one page. We actually want more than a page for our * +* tests. * +* * +* This is the twelfth line, and we need 24. So we need a few more paragraphs.* +* We can keep them short and just put lines between them. * +* * +* The 80 x 24 terminal size comes from the ancient past when computers were * +* only able to display text in cuneiform writing. * +* * +* The cunieform writing system used the edge of a reed to make marks on clay * +* tablets. * +* * +* It was the forerunner of the style of handwriting used by doctors to write * +* prescriptions. Thus the name: pre (before) script (writing) ion (charged * +* particle). * +------------------------------------------------------------------------------ +""".replace(b'\n', b'\n\r') + b"\r\n" + self.prompt1 = b'Press Return to continue:' + self.prompt2 = b'Rate this unit test>' + self.prompt3 = b'Press X to exit:' + self.enter = b'\r\n' + self.exit = b'X\r\n' + self.server_up = multiprocessing.Event() + self.server_process = multiprocessing.Process(target=self.socket_server, args=(self.server_up,)) + self.server_process.daemon = True + self.server_process.start() + counter = 0 + while not self.server_up.is_set(): + time.sleep(0.250) + counter += 1 + if counter > (10 / 0.250): + raise SocketServerError("Could not start socket server") + + def tearDown(self): + os.kill(self.server_process.pid, signal.SIGINT) + self.server_process.join(timeout=5.0) + PexpectTestCase.PexpectTestCase.tearDown(self) + + def socket_server(self, server_up): + sock = None + try: + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + sock.bind((self.host, self.port)) + sock.listen(5) + server_up.set() + while True: + (conn, addr) = sock.accept() + conn.send(self.motd) + conn.send(self.prompt1) + result = conn.recv(1024) + if result != self.enter: + break + conn.send(self.prompt2) + result = conn.recv(1024) + if result != self.enter: + break + conn.send(self.prompt3) + result = conn.recv(1024) + if result.startswith(self.exit[0]): + conn.shutdown(socket.SHUT_RDWR) + conn.close() + except KeyboardInterrupt: + pass + if sock is not None: + try: + sock.shutdown(socket.SHUT_RDWR) + sock.close() + except socket.error: + pass + exit(0) + + def socket_fn(self, timed_out, all_read): + result = 0 + try: + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.connect((self.host, self.port)) + session = fdpexpect.fdspawn(sock, timeout=10) + # Get all data from server + session.read_nonblocking(size=4096) + all_read.set() + # This read should timeout + session.read_nonblocking(size=4096) + except pexpect.TIMEOUT: + timed_out.set() + result = errno.ETIMEDOUT + exit(result) + + def test_socket(self): + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.connect((self.host, self.port)) + session = fdpexpect.fdspawn(sock.fileno(), timeout=10) + session.expect(self.prompt1) + self.assertEqual(session.before, self.motd) + session.send(self.enter) + session.expect(self.prompt2) + session.send(self.enter) + session.expect(self.prompt3) + session.send(self.exit) + session.expect(pexpect.EOF) + self.assertEqual(session.before, b'') + + def test_socket_with_write(self): + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.connect((self.host, self.port)) + session = fdpexpect.fdspawn(sock.fileno(), timeout=10) + session.expect(self.prompt1) + self.assertEqual(session.before, self.motd) + session.write(self.enter) + session.expect(self.prompt2) + session.write(self.enter) + session.expect(self.prompt3) + session.write(self.exit) + session.expect(pexpect.EOF) + self.assertEqual(session.before, b'') + + def test_not_int(self): + with self.assertRaises(pexpect.ExceptionPexpect): + session = fdpexpect.fdspawn('bogus', timeout=10) + + def test_not_file_descriptor(self): + with self.assertRaises(pexpect.ExceptionPexpect): + session = fdpexpect.fdspawn(-1, timeout=10) + + def test_timeout(self): + with self.assertRaises(pexpect.TIMEOUT): + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.connect((self.host, self.port)) + session = fdpexpect.fdspawn(sock, timeout=10) + session.expect(b'Bogus response') + + def test_interrupt(self): + timed_out = multiprocessing.Event() + all_read = multiprocessing.Event() + test_proc = multiprocessing.Process(target=self.socket_fn, args=(timed_out, all_read)) + test_proc.daemon = True + test_proc.start() + while not all_read.is_set(): + time.sleep(1.0) + os.kill(test_proc.pid, signal.SIGWINCH) + while not timed_out.is_set(): + time.sleep(1.0) + test_proc.join(timeout=5.0) + self.assertEqual(test_proc.exitcode, errno.ETIMEDOUT) + + def test_multiple_interrupts(self): + timed_out = multiprocessing.Event() + all_read = multiprocessing.Event() + test_proc = multiprocessing.Process(target=self.socket_fn, args=(timed_out, all_read)) + test_proc.daemon = True + test_proc.start() + while not all_read.is_set(): + time.sleep(1.0) + while not timed_out.is_set(): + os.kill(test_proc.pid, signal.SIGWINCH) + time.sleep(1.0) + test_proc.join(timeout=5.0) + self.assertEqual(test_proc.exitcode, errno.ETIMEDOUT) + + def test_maxread(self): + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.connect((self.host, self.port)) + session = fdpexpect.fdspawn(sock.fileno(), timeout=10) + session.maxread = 1100 + session.expect(self.prompt1) + self.assertEqual(session.before, self.motd) + session.send(self.enter) + session.expect(self.prompt2) + session.send(self.enter) + session.expect(self.prompt3) + session.send(self.exit) + session.expect(pexpect.EOF) + self.assertEqual(session.before, b'') + + def test_fd_isalive (self): + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.connect((self.host, self.port)) + session = fdpexpect.fdspawn(sock.fileno(), timeout=10) + assert session.isalive() + sock.close() + assert not session.isalive(), "Should not be alive after close()" + + def test_fd_isatty (self): + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.connect((self.host, self.port)) + session = fdpexpect.fdspawn(sock.fileno(), timeout=10) + assert not session.isatty() + session.close() + + def test_fileobj(self): + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.connect((self.host, self.port)) + session = fdpexpect.fdspawn(sock, timeout=10) # Should get the fileno from the socket + session.expect(self.prompt1) + session.close() + assert not session.isalive() + session.close() # Smoketest - should be able to call this again + +if __name__ == '__main__': + unittest.main() + +suite = unittest.makeSuite(ExpectTestCase, 'test') http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/a1a2f2c5/tools/bin/pythonSrc/pexpect-4.2/tests/test_timeout_pattern.py ---------------------------------------------------------------------- diff --git a/tools/bin/pythonSrc/pexpect-4.2/tests/test_timeout_pattern.py b/tools/bin/pythonSrc/pexpect-4.2/tests/test_timeout_pattern.py new file mode 100755 index 0000000..5f610ef --- /dev/null +++ b/tools/bin/pythonSrc/pexpect-4.2/tests/test_timeout_pattern.py @@ -0,0 +1,92 @@ +#!/usr/bin/env python +''' +PEXPECT LICENSE + + This license is approved by the OSI and FSF as GPL-compatible. + http://opensource.org/licenses/isc-license.txt + + Copyright (c) 2012, Noah Spurrier <[email protected]> + PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY + PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE + COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES. + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +''' +from __future__ import with_statement # bring 'with' stmt to py25 +import pexpect +import unittest +from . import PexpectTestCase +import sys + +class Exp_TimeoutTestCase(PexpectTestCase.PexpectTestCase): + def test_matches_exp_timeout (self): + '''This tests that we can raise and catch TIMEOUT. + ''' + try: + raise pexpect.TIMEOUT("TIMEOUT match test") + except pexpect.TIMEOUT: + pass + #print "Correctly caught TIMEOUT when raising TIMEOUT." + else: + self.fail('TIMEOUT not caught by an except TIMEOUT clause.') + + def test_pattern_printout (self): + '''Verify that a TIMEOUT returns the proper patterns it is trying to match against. + Make sure it is returning the pattern from the correct call.''' + try: + p = pexpect.spawn('cat') + p.sendline('Hello') + p.expect('Hello') + p.expect('Goodbye',timeout=5) + except pexpect.TIMEOUT: + assert p.match_index == None + else: + self.fail("Did not generate a TIMEOUT exception.") + + def test_exp_timeout_notThrown (self): + '''Verify that a TIMEOUT is not thrown when we match what we expect.''' + try: + p = pexpect.spawn('cat') + p.sendline('Hello') + p.expect('Hello') + except pexpect.TIMEOUT: + self.fail("TIMEOUT caught when it shouldn't be raised because we match the proper pattern.") + + def test_stacktraceMunging (self): + '''Verify that the stack trace returned with a TIMEOUT instance does not contain references to pexpect.''' + try: + p = pexpect.spawn('cat') + p.sendline('Hello') + p.expect('Goodbye',timeout=5) + except pexpect.TIMEOUT: + err = sys.exc_info()[1] + if err.get_trace().count("pexpect/__init__.py") != 0: + self.fail("The TIMEOUT get_trace() referenced pexpect.py. " + "It should only reference the caller.\n" + err.get_trace()) + + def test_correctStackTrace (self): + '''Verify that the stack trace returned with a TIMEOUT instance correctly handles function calls.''' + def nestedFunction (spawnInstance): + spawnInstance.expect("junk", timeout=3) + + try: + p = pexpect.spawn('cat') + p.sendline('Hello') + nestedFunction(p) + except pexpect.TIMEOUT: + err = sys.exc_info()[1] + if err.get_trace().count("nestedFunction") == 0: + self.fail("The TIMEOUT get_trace() did not show the call " + "to the nestedFunction function.\n" + str(err) + "\n" + + err.get_trace()) + +if __name__ == '__main__': + unittest.main() + +suite = unittest.makeSuite(Exp_TimeoutTestCase,'test') http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/a1a2f2c5/tools/bin/pythonSrc/pexpect-4.2/tests/test_unicode.py ---------------------------------------------------------------------- diff --git a/tools/bin/pythonSrc/pexpect-4.2/tests/test_unicode.py b/tools/bin/pythonSrc/pexpect-4.2/tests/test_unicode.py new file mode 100644 index 0000000..1d2f933 --- /dev/null +++ b/tools/bin/pythonSrc/pexpect-4.2/tests/test_unicode.py @@ -0,0 +1,187 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +import platform +import tempfile +import sys +import time + +import pexpect +import unittest +from . import PexpectTestCase + +# the program cat(1) may display ^D\x08\x08 when \x04 (EOF, Ctrl-D) is sent +_CAT_EOF = '^D\x08\x08' + +class UnicodeTests(PexpectTestCase.PexpectTestCase): + def test_expect_basic (self): + p = pexpect.spawnu('cat') + p.sendline('Hello') + p.sendline('there') + p.sendline('Mr. þython') # þ is more like th than p, but never mind + p.expect('Hello') + p.expect('there') + p.expect('Mr. þython') + p.sendeof () + p.expect (pexpect.EOF) + + def test_expect_exact_basic (self): + p = pexpect.spawnu('cat') + p.sendline('Hello') + p.sendline('there') + p.sendline('Mr. þython') + p.expect_exact('Hello') + p.expect_exact('there') + p.expect_exact('Mr. þython') + p.sendeof() + p.expect_exact (pexpect.EOF) + + def test_expect_setecho_toggle(self): + '''This tests that echo may be toggled off. + ''' + p = pexpect.spawnu('cat', timeout=5) + try: + self._expect_echo_toggle_off(p) + except IOError: + if sys.platform.lower().startswith('sunos'): + if hasattr(unittest, 'SkipTest'): + raise unittest.SkipTest("Not supported on this platform.") + return 'skip' + raise + self._expect_echo_toggle_on(p) + + def test_expect_echo_exact (self): + '''Like test_expect_echo(), but using expect_exact(). + ''' + p = pexpect.spawnu('cat', timeout=5) + p.expect = p.expect_exact + self._expect_echo(p) + + def test_expect_setecho_toggle_exact(self): + p = pexpect.spawnu('cat', timeout=5) + p.expect = p.expect_exact + try: + self._expect_echo_toggle_off(p) + except IOError: + if sys.platform.lower().startswith('sunos'): + if hasattr(unittest, 'SkipTest'): + raise unittest.SkipTest("Not supported on this platform.") + return 'skip' + raise + self._expect_echo_toggle_on(p) + + def _expect_echo (self, p): + p.sendline('1234') # Should see this twice (once from tty echo and again from cat). + index = p.expect (['1234', 'abcdé', 'wxyz', pexpect.EOF, pexpect.TIMEOUT]) + assert index == 0, (index, p.before) + index = p.expect (['1234', 'abcdé', 'wxyz', pexpect.EOF]) + assert index == 0, index + + def _expect_echo_toggle_off(self, p): + p.setecho(0) # Turn off tty echo + p.waitnoecho() + p.sendline('abcdé') # Now, should only see this once. + p.sendline('wxyz') # Should also be only once. + index = p.expect ([pexpect.EOF,pexpect.TIMEOUT, 'abcdé', 'wxyz', '1234']) + assert index == 2, index + index = p.expect ([pexpect.EOF, 'abcdé', 'wxyz', '7890']) + assert index == 2, index + + def _expect_echo_toggle_on(self, p): + p.setecho(1) # Turn on tty echo + time.sleep(0.2) # there is no waitecho() ! + p.sendline('7890') # Should see this twice. + index = p.expect ([pexpect.EOF, 'abcdé', 'wxyz', '7890']) + assert index == 3, index + index = p.expect ([pexpect.EOF, 'abcdé', 'wxyz', '7890']) + assert index == 3, index + p.sendeof() + + def test_log_unicode(self): + msg = "abcΩ÷" + filename_send = tempfile.mktemp() + filename_read = tempfile.mktemp() + p = pexpect.spawnu('cat') + if platform.python_version_tuple() < ('3', '0', '0'): + import codecs + def open(fname, mode, **kwargs): + if 'newline' in kwargs: + del kwargs['newline'] + return codecs.open(fname, mode, **kwargs) + else: + import io + open = io.open + + p.logfile_send = open(filename_send, 'w', encoding='utf-8') + p.logfile_read = open(filename_read, 'w', encoding='utf-8') + p.sendline(msg) + p.sendeof() + p.expect(pexpect.EOF) + p.close() + p.logfile_send.close() + p.logfile_read.close() + + # ensure the 'send' log is correct, + with open(filename_send, 'r', encoding='utf-8') as f: + self.assertEqual(f.read(), msg + '\n\x04') + + # ensure the 'read' log is correct, + with open(filename_read, 'r', encoding='utf-8', newline='') as f: + output = f.read().replace(_CAT_EOF, '') + self.assertEqual(output, (msg + '\r\n')*2 ) + + + def test_spawn_expect_ascii_unicode(self): + # A bytes-based spawn should be able to handle ASCII-only unicode, for + # backwards compatibility. + p = pexpect.spawn('cat') + p.sendline('Camelot') + p.expect('Camelot') + + p.sendline('Aargh') + p.sendline('AÃ¥rgh') + p.expect_exact('Aargh') + + p.sendeof() + p.expect(pexpect.EOF) + + def test_spawn_send_unicode(self): + # A bytes-based spawn should be able to send arbitrary unicode + p = pexpect.spawn('cat') + p.sendline('3½') + p.sendeof() + p.expect(pexpect.EOF) + + def test_spawn_utf8_incomplete(self): + # This test case ensures correct incremental decoding, which + # otherwise fails when the stream inspected by os.read() + # does not align exactly at a utf-8 multibyte boundry: + # UnicodeDecodeError: 'utf8' codec can't decode byte 0xe2 in + # position 0: unexpected end of data + p = pexpect.spawnu('cat', maxread=1) + p.sendline('âââââ âââ') + p.sendeof() + p.expect('âââââ âââ') + + def test_readline_bin_echo(self): + # Test using readline() with spawnu objects. pexpect 3.2 had threw + # a TypeError when concatenating a bytestring to a unicode type. + + # given, + child = pexpect.spawnu('echo', ['input', ]) + + # exercise, + assert child.readline() == 'input' + child.crlf + + def test_unicode_argv(self): + """ Ensure a program can be executed with unicode arguments. """ + p = pexpect.spawn(u'echo ÇpoÉıun', timeout=5, encoding='utf8') + p.expect(u'ÇpoÉıun') + p.expect(pexpect.EOF) + assert not p.isalive() + assert p.exitstatus == 0 + +if __name__ == '__main__': + unittest.main() + +suite = unittest.makeSuite(UnicodeTests, 'test') http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/a1a2f2c5/tools/bin/pythonSrc/pexpect-4.2/tests/test_which.py ---------------------------------------------------------------------- diff --git a/tools/bin/pythonSrc/pexpect-4.2/tests/test_which.py b/tools/bin/pythonSrc/pexpect-4.2/tests/test_which.py new file mode 100644 index 0000000..15a8944 --- /dev/null +++ b/tools/bin/pythonSrc/pexpect-4.2/tests/test_which.py @@ -0,0 +1,291 @@ +# -*- coding: utf-8 -*- +import subprocess +import tempfile +import shutil +import errno +import os + +import pexpect +from . import PexpectTestCase + +import pytest + + +class TestCaseWhich(PexpectTestCase.PexpectTestCase): + " Tests for pexpect.which(). " + + def test_which_finds_ls(self): + " which() can find ls(1). " + exercise = pexpect.which("ls") + assert exercise is not None + assert exercise.startswith('/') + + def test_path_from_env(self): + " executable found from optional env argument " + bin_name = 'pexpect-test-path-from-env' + tempdir = tempfile.mkdtemp() + try: + bin_path = os.path.join(tempdir, bin_name) + with open(bin_path, 'w') as f: + f.write('# test file not to be run') + try: + os.chmod(bin_path, 0o700) + found_path = pexpect.which(bin_name, env={'PATH': tempdir}) + finally: + os.remove(bin_path) + self.assertEqual(bin_path, found_path) + finally: + os.rmdir(tempdir) + + def test_os_defpath_which(self): + " which() finds an executable in $PATH and returns its abspath. " + + bin_dir = tempfile.mkdtemp() + temp_obj = tempfile.NamedTemporaryFile( + suffix=u'.sh', prefix=u'ÇpoÉıun-', + dir=bin_dir, delete=False) + bin_path = temp_obj.name + fname = os.path.basename(temp_obj.name) + save_path = os.environ['PATH'] + save_defpath = os.defpath + + try: + # setup + os.environ['PATH'] = '' + os.defpath = bin_dir + with open(bin_path, 'w') as fp: + pass + + # given non-executable, + os.chmod(bin_path, 0o400) + + # exercise absolute and relative, + assert pexpect.which(bin_path) is None + assert pexpect.which(fname) is None + + # given executable, + os.chmod(bin_path, 0o700) + + # exercise absolute and relative, + assert pexpect.which(bin_path) == bin_path + assert pexpect.which(fname) == bin_path + + finally: + # restore, + os.environ['PATH'] = save_path + os.defpath = save_defpath + + # destroy scratch files and folders, + if os.path.exists(bin_path): + os.unlink(bin_path) + if os.path.exists(bin_dir): + os.rmdir(bin_dir) + + def test_path_search_which(self): + " which() finds an executable in $PATH and returns its abspath. " + fname = 'gcc' + bin_dir = tempfile.mkdtemp() + bin_path = os.path.join(bin_dir, fname) + save_path = os.environ['PATH'] + try: + # setup + os.environ['PATH'] = bin_dir + with open(bin_path, 'w') as fp: + pass + + # given non-executable, + os.chmod(bin_path, 0o400) + + # exercise absolute and relative, + assert pexpect.which(bin_path) is None + assert pexpect.which(fname) is None + + # given executable, + os.chmod(bin_path, 0o700) + + # exercise absolute and relative, + assert pexpect.which(bin_path) == bin_path + assert pexpect.which(fname) == bin_path + + finally: + # restore, + os.environ['PATH'] = save_path + + # destroy scratch files and folders, + if os.path.exists(bin_path): + os.unlink(bin_path) + if os.path.exists(bin_dir): + os.rmdir(bin_dir) + + def test_which_follows_symlink(self): + " which() follows symlinks and returns its path. " + fname = 'original' + symname = 'extra-crispy' + bin_dir = tempfile.mkdtemp() + bin_path = os.path.join(bin_dir, fname) + sym_path = os.path.join(bin_dir, symname) + save_path = os.environ['PATH'] + try: + # setup + os.environ['PATH'] = bin_dir + with open(bin_path, 'w') as fp: + pass + os.chmod(bin_path, 0o400) + os.symlink(bin_path, sym_path) + + # should not be found because symlink points to non-executable + assert pexpect.which(symname) is None + + # but now it should -- because it is executable + os.chmod(bin_path, 0o700) + assert pexpect.which(symname) == sym_path + + finally: + # restore, + os.environ['PATH'] = save_path + + # destroy scratch files, symlinks, and folders, + if os.path.exists(sym_path): + os.unlink(sym_path) + if os.path.exists(bin_path): + os.unlink(bin_path) + if os.path.exists(bin_dir): + os.rmdir(bin_dir) + + def test_which_should_not_match_folders(self): + " Which does not match folders, even though they are executable. " + # make up a path and insert a folder that is 'executable', a naive + # implementation might match (previously pexpect versions 3.2 and + # sh versions 1.0.8, reported by @lcm337.) + fname = 'g++' + bin_dir = tempfile.mkdtemp() + bin_dir2 = os.path.join(bin_dir, fname) + save_path = os.environ['PATH'] + try: + os.environ['PATH'] = bin_dir + os.mkdir(bin_dir2, 0o755) + # should not be found because it is not executable *file*, + # but rather, has the executable bit set, as a good folder + # should -- it should not be returned because it fails isdir() + exercise = pexpect.which(fname) + assert exercise is None + + finally: + # restore, + os.environ['PATH'] = save_path + # destroy scratch folders, + for _dir in (bin_dir2, bin_dir,): + if os.path.exists(_dir): + os.rmdir(_dir) + + def test_which_should_match_other_group_user(self): + " which() returns executables by other, group, and user ownership. " + # create an executable and test that it is found using which() for + # each of the 'other', 'group', and 'user' permission bits. + fname = 'g77' + bin_dir = tempfile.mkdtemp() + bin_path = os.path.join(bin_dir, fname) + save_path = os.environ['PATH'] + try: + # setup + os.environ['PATH'] = bin_dir + + # an interpreted script requires the ability to read, + # whereas a binary program requires only to be executable. + # + # to gain access to a binary program, we make a copy of + # the existing system program echo(1). + bin_echo = None + for pth in ('/bin/echo', '/usr/bin/echo'): + if os.path.exists(pth): + bin_echo = pth + break + bin_which = None + for pth in ('/bin/which', '/usr/bin/which'): + if os.path.exists(pth): + bin_which = pth + break + if not bin_echo or not bin_which: + pytest.skip('needs `echo` and `which` binaries') + shutil.copy(bin_echo, bin_path) + isroot = os.getuid() == 0 + for should_match, mode in ( + # note that although the file may have matching 'group' or + # 'other' executable permissions, it is *not* executable + # because the current uid is the owner of the file -- which + # takes precedence + (False, 0o000), # ----------, no + (isroot, 0o001), # ---------x, no + (isroot, 0o010), # ------x---, no + (True, 0o100), # ---x------, yes + (False, 0o002), # --------w-, no + (False, 0o020), # -----w----, no + (False, 0o200), # --w-------, no + (isroot, 0o003), # --------wx, no + (isroot, 0o030), # -----wx---, no + (True, 0o300), # --wx------, yes + (False, 0o004), # -------r--, no + (False, 0o040), # ----r-----, no + (False, 0o400), # -r--------, no + (isroot, 0o005), # -------r-x, no + (isroot, 0o050), # ----r-x---, no + (True, 0o500), # -r-x------, yes + (False, 0o006), # -------rw-, no + (False, 0o060), # ----rw----, no + (False, 0o600), # -rw-------, no + (isroot, 0o007), # -------rwx, no + (isroot, 0o070), # ----rwx---, no + (True, 0o700), # -rwx------, yes + (isroot, 0o4001), # ---S-----x, no + (isroot, 0o4010), # ---S--x---, no + (True, 0o4100), # ---s------, yes + (isroot, 0o4003), # ---S----wx, no + (isroot, 0o4030), # ---S-wx---, no + (True, 0o4300), # --ws------, yes + (isroot, 0o2001), # ------S--x, no + (isroot, 0o2010), # ------s---, no + (True, 0o2100), # ---x--S---, yes + + ): + mode_str = '{0:0>4o}'.format(mode) + + # given file mode, + os.chmod(bin_path, mode) + + # exercise whether we may execute + can_execute = True + try: + subprocess.Popen(fname).wait() == 0 + except OSError as err: + if err.errno != errno.EACCES: + raise + # permission denied + can_execute = False + + assert should_match == can_execute, ( + should_match, can_execute, mode_str) + + # exercise whether which(1) would match + proc = subprocess.Popen((bin_which, fname), + env={'PATH': bin_dir}, + stdout=subprocess.PIPE) + bin_which_match = bool(not proc.wait()) + assert should_match == bin_which_match, ( + should_match, bin_which_match, mode_str) + + # finally, exercise pexpect's which(1) matches + # the same. + pexpect_match = bool(pexpect.which(fname)) + + assert should_match == pexpect_match == bin_which_match, ( + should_match, pexpect_match, bin_which_match, mode_str) + + finally: + # restore, + os.environ['PATH'] = save_path + + # destroy scratch files and folders, + if os.path.exists(bin_path): + os.unlink(bin_path) + if os.path.exists(bin_dir): + os.rmdir(bin_dir) http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/a1a2f2c5/tools/bin/pythonSrc/pexpect-4.2/tests/test_winsize.py ---------------------------------------------------------------------- diff --git a/tools/bin/pythonSrc/pexpect-4.2/tests/test_winsize.py b/tools/bin/pythonSrc/pexpect-4.2/tests/test_winsize.py new file mode 100755 index 0000000..be16773 --- /dev/null +++ b/tools/bin/pythonSrc/pexpect-4.2/tests/test_winsize.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python +''' +PEXPECT LICENSE + + This license is approved by the OSI and FSF as GPL-compatible. + http://opensource.org/licenses/isc-license.txt + + Copyright (c) 2012, Noah Spurrier <[email protected]> + PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY + PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE + COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES. + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +''' +import pexpect +import unittest +from . import PexpectTestCase +import time + +class TestCaseWinsize(PexpectTestCase.PexpectTestCase): + + def test_initial_winsize(self): + """ Assert initial window dimension size (24, 80). """ + p = pexpect.spawn('{self.PYTHONBIN} sigwinch_report.py' + .format(self=self), timeout=3) + # default size by PtyProcess class is 24 rows by 80 columns. + p.expect_exact('Initial Size: (24, 80)') + p.close() + + def test_initial_winsize_by_dimension(self): + """ Assert user-parameter window dimension size is initial. """ + p = pexpect.spawn('{self.PYTHONBIN} sigwinch_report.py' + .format(self=self), timeout=3, + dimensions=(40, 100)) + p.expect_exact('Initial Size: (40, 100)') + p.close() + + def test_setwinsize(self): + """ Ensure method .setwinsize() sends signal caught by child. """ + p = pexpect.spawn('{self.PYTHONBIN} sigwinch_report.py' + .format(self=self), timeout=3) + # Note that we must await the installation of the child process' + # signal handler, + p.expect_exact('READY') + p.setwinsize(19, 84) + p.expect_exact('SIGWINCH: (19, 84)') + p.close() + +if __name__ == '__main__': + unittest.main() + +suite = unittest.makeSuite(TestCaseWinsize,'test') + + http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/a1a2f2c5/tools/bin/pythonSrc/pexpect-4.2/tests/tetris.data ---------------------------------------------------------------------- diff --git a/tools/bin/pythonSrc/pexpect-4.2/tests/tetris.data b/tools/bin/pythonSrc/pexpect-4.2/tests/tetris.data new file mode 100644 index 0000000..06b6ce6 --- /dev/null +++ b/tools/bin/pythonSrc/pexpect-4.2/tests/tetris.data @@ -0,0 +1,3 @@ +[2J +[24;1H J->LEFT K->ROTATE L->RIGHT SPACE->DROP P->PAUSE Q->QUIT +[1;28HXX[1;36HXXXXXXXX[1;50HXX[2;28HXX[2;50HXX[3;28HXX[3;50HXX[4;28HXX[4;50HXX[5;28HXX[5;50HXX[6;28HXX[6;50HXX[7;28HXX[7;50HXX[8;28HXX[8;50HXX[9;28HXX[9;50HXX[10;28HXX[10;50HXX[11;28HXX[11;50HXX[12;28HXX[12;50HXX[13;28HXX[13;50HXX[14;28HXX[14;50HXX[15;28HXX[15;50HXX[16;28HXX[16;50HXX[17;28HXX[17;50HXX[18;28HXX[18;50HXX[19;28HXX[19;50HXX[20;28HXX[20;50HXX[21;28HXXXXXXXXXXXXXXXXXXXXXXXX[1;36H [2;36HXXXXXXXX[21;50HXX[2;36H [3;36HXXXXXXXX[21;50HXX[3;36H [4;36HXXXXXXXX[21;50HXX[4;36H [5;36HXXXXXXXX[21;50HXX[5;34HXX[5;42H [21;50HXX[5;34H [6;34HXXXXXXXX[21;50HXX[6;32HXX[6;40H [21;50HXX[6;30HXX[6;38H [21;50HXX[6;30H [7;30HXXXXXXXX[21;50HXX[21;50HXX[21;50HXX[21;50HXX[7;30H [8;30HXXXXXXXX[21;50HXX[8;30H [20;30HXXXXXXXX[21;50HXX[1;36HXXXXXX[2;36HXX[21;50HXX[1;36H [2;38HXXXX[3;36HXX[21;50HXX[2;36H [2;42HXX[3;36H XX[21;50HXX[2;38H [3;40 HXXXX[4;38HXX[21;50HXX[3;38H [3;44HXX[4;38H XX[21;50HXX[3;40H [3;46HXX[4;40H XX[21;50HXX[3;42H [3;48HXX[4;42H XX[21;50HXX[21;50HXX[21;50HXX[21;50HXX[21;50HXX[21;50HXX[21;50HXX[3;44H [4;46HXXXX[5;44HXX[21;50HXX[4;44H [5;46HXXXX[6;44HXX[21;50HXX[5;44H [6;44H [19;44HXXXXXX[20;44HXX[21;50HXX[1;36HXXXXXX[2;36HXX[21;50HXX[1;36H [2;38HXXXX[3;36HXX[21;50HXX[2;36H [2;42HXX[3;36H XX[21;50HXX[2;38H [2;44HXX[3;38H XX[21;50HXX[2;40H [3;42HXXXX[4;40HXX[21;50HXX[2;42HXX[3;40H [3;44H [4;40H XXXX[21;50HXX[2;42H XX[3;40HXX[3;44HXX[4;42H [21;50HXX[2;44H [3;40H [4;40HXXXXXX[21;50HXX[3;44H [4;40H [17;44HXX[18;40HXXXXXX[21;50HXX[1;36HXXXX[21;50HXX[1;36H [1;40HXX[2;36HXXXX[21;50HXX[1;36HXX[1;40H [2;34HXX[2;38H [21;50HXX[1;36H [2;34H [2;38HXX[3;34HXXXX[21;50HXX[2;34HXX[2;38H [3;32HXX[3;36H [21;50HXX[2;32HXX[2;36H [3;30HXX[3;34H [21;50HXX[21;50HXX [2;32H [3;30H [3;34HXX[4;30HXXXX[21;50HXX[21;50HXX[3;32H [4;30H [18;32HXXXX[19;30HXXXX[21;50HXX[1;36HXXXXXX[2;36HXX[21;50HXX[1;36H [1;42HXX[2;36H XX[21;50HXX[1;38H [2;40HXXXX[3;38HXX[21;50HXX[2;38H [2;44HXX[3;38H XX[21;50HXX[2;40H [2;46HXX[3;40H XX[21;50HXX[2;42H [2;48HXX[3;42H XX[21;50HXX[2;44H [3;46HXXXX[4;44HXX[21;50HXX[21;50HXX[21;50HXX[3;44H [4;44H [15;44HXXXXXX[16;44HXX[21;50HXX[1;36HXXXXXXXX[21;50HXX[1;34HXX[1;42H [21;50HXX[1;34H [2;34HXXXXXXXX[21;50HXX[2;32HXX[2;40H [21;50HXX[2;30HXX[2;38H [21;50HXX[21;50HXX[21;50HXX[21;50HXX[21;50HXX[2;30H [3;30HXXXXXXXX[21;50HXX[3;30H [17;30HXXXXXXXX[21;50HXX[1;38HXXXX[21;50HXX[1;38H [16;36HXXXX[17;38HXXXX[21;50HXX[21;50HXX[1;36HXXXX[21;50HXX[1;36H [1;40HXX[21;50HXX[2;38HXXXX[21;50HXX[1;38H [1;42HXX[2;38H [2;42HXX[21;50HXX[1;40H [1;44HXX[2;40H [2;44HXX[21;50HXX[1;42H [1;46HXX[2;42 H [2;46HXX[21;50HXX[1;44H [3;44HXXXX[21;50HXX[2;44H [3;44H [13;44HXXXX[14;44HXXXX[21;50HXX[1;36HXXXXXX[2;40HXX[21;50HXX[1;34HXX[1;40H [2;38HXX [21;50HXX[1;34H [2;34HXXXX[3;38HXX[21;50HXX[2;32HXX[2;38H [3;36HXX [21;50HXX[2;30HXX[2;36H [3;34HXX [21;50HXX[21;50HXX[21;50HXX[21;50HXX[2;30H [3;34H [15;30HXXXXXX[16;34HXX[21;50HXX[1;36HXXXXXXXX[21;50HXX[1;36H [1;44HXX[21;50HXX[1;38H [2;38HXXXXXXXX[21;50HXX[1;40HXX[2;38H [2;42H [3;40HXX[4;40HXX[21;50HXX[1;40H [5;40HXX[21;50HXX[2;40H [3;38HXX[3;42HXXXX[4;40H [5;40H [21;50HXX[2;40HXX[3;38H [3;42H [4;40HXX[5;40HXX[21;50HXX[2;40H [6;40HXX[21;50HXX[3;40H [4;40H [5;40H [6;40H [13;40HXX[14;40HXX[15;40HXX[16;40HXX[21;50HXX[1;36HXXXXXX[2;38HXX[21;50HXX[1;34HXX[1;40H [2;36HXX [21;50HXX[1;32HXX[1;38H [2;34HXX [21;50HXX[1;32H [21;50HXX[1;36H [2;36HXX[3;34HXX[21;50HXX[1;32HXX [2;32HXX[2;36H [3;32HX X [21;50HXX[2;30HXX[3;32H [21;50HXX[1;32H [2;30H [2;34H [3;30HXXXXXX[21;50HXX[2;32H [3;30H [13;32HXX[14;30HXXXXXX[21;50HXX[1;36HXXXXXXXX[21;50HXX[1;36H [1;44HXX[21;50HXX[1;38H [1;42H [2;40HXX[3;40HXX[21;50HXX[1;40H XX[2;40H XX[3;40H XX[21;50HXX[4;42HXX[21;50HXX[1;42H [2;40HXX[2;44HXXXX[3;42H [4;42H [21;50HXX[2;40H [2;48HXX[21;50HXX[1;44HXX[2;42H [2;46H [3;44HXX[4;44HXX[21;50HXX[1;44H [5;44HXX[21;50HXX[2;44H [3;44H [4;44H [5;44H [9;44HXX[10;44HXX[11;44HXX[12;44HXX[21;50HXX[1;36HXXXXXX[2;36HXX[21;50HXX[1;36H [1;40H [2;36H XXXX[21;50HXX[1;36HXX [2;36HXX[2;40H [21;50HXX[1;34HXX[1;38HXX[2;36H [21;50HXX[1;34H [2;34HXXXXXX[21;50HXX[1;36HXX [2;32HXX[2;38H [21;50HXX[1;32HXXXX [2;32H [2;36H [3;34HXX[21;50HXX[1;30HXX[1;34H [2;32HXX [3;32HXX [21;50HXX[1;30H [2;30HXX[4;32HXX[21;50HXX[2;30H [3;32H [4;32H [10;30HXXXX[11;32HXX[12;32HXX[21;50H XX[1;36HXXXXXX[2;40HXX[21;50HXX[1;36H [1;40H [2;38HXX [21;50HXX[1;36HXX[1;40HXX[2;38H [21;50HXX[1;38H [2;36HXXXXXX[21;50HXX[1;36H XX[2;36H [2;40H [3;36HXXXX[21;50HXX[1;38H [2;38H [3;36H [13;38HXX[14;38HXX[15;36HXXXX[21;50HXX[1;36HXXXXXX[2;36HXX[21;50HXX[1;36H [1;42HXX[2;36H XX[21;50HXX[1;38H [2;40HXXXX[3;38HXX[21;50HXX[1;40HXX[2;38H [2;42H [3;38H XXXX[21;50HXX[1;40H XX[2;40H XX[3;40H [3;44HXX[21;50HXX[1;42H XX[2;40HXX[2;44HXX[3;42H [21;50HXX[1;44H XX[2;40H [2;46HXX[21;50HXX[1;46H [2;42H [3;42HXXXXXX[21;50HXX[2;42HXXXX [3;42H [3;46H [4;44HXX[21;50HXX[2;42H [3;44H [4;44H [6;42HXXXX[7;44HXX[8;44HXX[21;50HXX[1;38HXXXX[21;50HXX[1;36HXX[1;40H [2;36HXX[21;50HXX[1;34HXX[1;38H [2;34HXX [21;50HXX[1;34H [2;36HXX[3;34HXX[21;50HXX[1;34HXX[2;34H [2;38HXX[3;34H [21;50HXX[1;32HXX[1;36H [2;34HXX[2;38H [21;50HXX[1;32H [2;32HXX[2;36H [3;32HXX[21;5 0HXX[1;32HXX [2;30HXX[2;34H [3;30HXX [21;50HXX[1;32H [2;30H [3;32HXX[4;30HXX[21;50HXX[2;32H [3;30H [4;30H [7;32HXX[8;30HXXXX[9;30HXX[21;50HXX[1;36HXXXX[21;50HXX[21;50HXX[1;36H [1;40HXX[21;50HXX[21;50HXX[2;38HXXXX[21;50HXX[1;38H [1;42HXX[2;38H [2;42HXX[21;50HXX[21;50HXX[1;40H [1;44HXX[2;40H [2;44HXX[21;50HXX[21;50HXX[1;42H [3;42HXXXX[21;50HXX[2;42H [3;42H [4;42HXXXX[5;42HXXXX[21;50HXX[1;36HXXXX[21;50HXX[1;36H [1;40HXX[2;40HXX[21;50HXX[1;36HXX[1;40H [2;40H [21;50HXX[1;36H [1;40HXX[2;40HXX[21;50HXX[1;40H [2;38HXX[3;40HXX[21;50HXX[1;38H [2;38H [3;40H [10;38HXX[11;38HXXXX[12;40HXX[21;50HXX[1;36HXXXXXX[2;40HXX[21;50HXX[1;36H [2;40H [9;36HXXXXXX[10;40HXX[21;50HXX[21;50HXX[1;38HXXXX[21;50HXX[1;36HXX[1;40H [2;36HXX[21;50HXX[1;34HXX[1;38H [2;34HXX [21;50HXX[1;34H [2;36HXX[3;34HXX[21;50HXX[1;34HXX[2;34H [2;38HXX[3;34H [21;50HXX[1;32HXX[1;36H [2;34 HXX[2;38H [21;50HXX[1;32H [2;34H [6;32HXXXX[7;34HXXXX[21;50HXX[1;36HXXXXXX[2;40HXX[21;50HXX[1;36H [1;42HXX[2;40H XX[21;50HXX[1;38H [1;42H [2;40HXX [21;50HXX[1;40H XX[2;40H XX[21;50HXX[1;40HXX[1;44HXX[2;42H [21;50HXX[1;42H [2;40HXXXXXX[21;50HXX[1;40H XX[2;40H [2;46HXX[21;50HXX[1;42H XX[2;42H [2;46H [3;42HXXXX[21;50HXX[21;50HXX[1;38HXXXX[21;50HXX[1;36HXX[1;40H [2;36HXX[21;50HXX[1;36H [2;38HXX[3;36HXX[21;50HXX[1;36HXX [2;34HXX[2;38H [3;34HXX [21;50HXX[1;34HXX[2;34H [2;38HXX[3;34H [21;50HXX[1;32HXX[1;36H [2;34HXX[2;38H [21;50HXX[1;32H [2;32HXX[2;36H [3;32HXX[21;50HXX[1;34H [2;32H [3;34HXX[4;32HXX[21;50HXX[2;32HXX [3;30HXX[3;34H [4;30HXX [21;50HXX[2;32H [3;30H [4;30H XX[5;30HXXXX[6;30HXX[21;50HXX[1;36HXXXXXX[2;40HXX[21;50HXX[1;36H [1;42HXX[2;40H XX[21;50HXX[1;38H [1;42H [2;40HXX [21;50HXX[1;40H XX[2;40H XX[21;50HXX[21;50HXX[1;38HXXXX[21;5 0HXX[21;50HXX[1;36HXX[1;40H [2;36HXX[21;50HXX[1;36H [2;36H [4;38HXX[5;36HXXXX[6;36HXX[21;50HXX[1;36HXXXX[21;50HXX[21;50HXX[1;34HXX[1;38H [21;50HXX[2;34HXXXX[21;50HXX[21;50HXX[1;32HXX[1;36H [2;32HXX[2;36H [21;50HXX[21;50HXX[1;30HXX[1;34H [2;30HXX[2;34H [21;50HXX[1;30H [3;30HXXXX[21;50HXX[21;50HXX[1;36HXXXX[21;50HXX[1;36H [1;40HXX[21;50HXX[21;50HXX[21;50HXX[21;50HXX[2;38HXXXX[21;50HXX[21;50HXX[21;50HXX[21;50HXX[21;50HXX[1;38H [3;38HXXXX[21;50HXX[21;50HXX[21;50HXX[21;50HXX[21;50HXX http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/a1a2f2c5/tools/bin/pythonSrc/pexpect-4.2/tests/ticker.py ---------------------------------------------------------------------- diff --git a/tools/bin/pythonSrc/pexpect-4.2/tests/ticker.py b/tools/bin/pythonSrc/pexpect-4.2/tests/ticker.py new file mode 100755 index 0000000..5ecc1c2 --- /dev/null +++ b/tools/bin/pythonSrc/pexpect-4.2/tests/ticker.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +''' +PEXPECT LICENSE + + This license is approved by the OSI and FSF as GPL-compatible. + http://opensource.org/licenses/isc-license.txt + + Copyright (c) 2012, Noah Spurrier <[email protected]> + PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY + PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE + COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES. + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +''' + +import time, sys + +for i in range(5): + print "tick" + time.sleep(1) + +sys.exit(0) http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/a1a2f2c5/tools/bin/pythonSrc/pexpect-4.2/tests/torturet.vt ---------------------------------------------------------------------- diff --git a/tools/bin/pythonSrc/pexpect-4.2/tests/torturet.vt b/tools/bin/pythonSrc/pexpect-4.2/tests/torturet.vt new file mode 100644 index 0000000..65f965b --- /dev/null +++ b/tools/bin/pythonSrc/pexpect-4.2/tests/torturet.vt @@ -0,0 +1,61 @@ +\<>[H[1;2;3;4qPrEM1\[?4h[0m +[H[J[7m#6(0a`opqrs`(B This is the (0`srqpo`a(B[1m +#3VT100 series Torture Test Demonstration. +#4VT100 series Torture Test Demonstration. +#6[1;5m Watch the blinking lights [4;24r[0m +[0q[1q[0q[2q[0q[3q[0q[4q[0q +[0q[1q[0q[2q[0q[3q[0q[4q[0q +[0q[1q[0q[2q[0q[3q[0q[4q[0q +PrEM0\[4;1H[J[24;1H + +This file is a VT100-series Torture Test. It demonstrates all the visual +attributes of the VT100 terminal. + +The top line is double-width/single-height with inverse-video line-drawing +characters. The 2nd and 3rd lines are double-width/double-height in bold +inverse video. They also show the limited scrolling region. + +The remaining lines will show NORMAL, BOLD, BLINK, INVERSE, and all 16 +combinations of those 4 attributes. They show that there is a difference +between an underscore character and the underline attribute, and that +lower-case decenders go below the underline. + +A window pane is drawn in the lower right to show how the line-drawing set +can be used. At the lower left is the character set double-wide/double-high +to show the dot-matrix used. Upper-case characters are 8 by 7 in a 10 by 10 +character cell, with 1 blank row on top and 2 on the bottom. The underline +attribute uses the first bottom blank row, lower-case decenders use both. + + + +[0mThis is a normal line __________________________________________________y_ +[1mThis is a bold line (normal unless the Advanced Video Option is installed) +[0;4mThis line is underlined _ " " " " " " _y_ +[0;5mThis is a blinking line _ " " " " " " _y_ +[0;7mThis is inverse video _ (underlined if no AVO and cursor is underline) _y_ +[0mNormal gjpqy [4mUnderline[0;0m [5m Blink [4mUnderline+Blink gjpqy[0m +[1mBold gjpqy [4mUnderline[0;1m [5m Blink [4mUnderline+Blink gjpqy[0m +[7mInverse [4mUnderline[0;7m [5m Blink [4mUnderline+Blink[0;7m +[1mBold+Inverse [4mUnderline[0;1;7m [5m Blink [4mUnderline+Blink[0m +PrEM1\[A +#6This is double [1mwidth[0m +#3This is double [1mheight[0m +#4This is double [1mheight[0m +#6[7;4m_[0;7mABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ioy +#3[7;4m_[0;7mABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ioy +#4[7;4m_[0;7mABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ioy[3A +[0m[CA[CC[CE[CG[CI[CK[CM[CO[CQ[CS[CU[CW[CY[C0[C2[C4[C6[C8[Ci[Cy +[4m_[0m[CB[CD[CF[CH[CJ[CL[CN[CP[CR[CT[CV[CX[CZ[C1[C3[C5[C7[C9[Co +[4m_[0m[CB[CD[CF[CH[CJ[CL[CN[CP[CR[CT[CV[CX[CZ[C1[C3[C5[C7[C9[Co +(0#6[7m`abcdefghijklmnopqrstuvwxyz{|}~[0m lqwqk +#3[7m`abcdefghijklmnopqrstuvwxyz{|}~[0m tqnqu +#4[7m`abcdefghijklmnopqrstuvwxyz{|}~[0m tqnqu[3A[0m +[Ca[Cc[Ce[Cg[Ci[Ck[Cm[Co[Cq[Cs[Cu[Cw[Cy[C{[C} +`[Cb[Cd[Cf[Ch[Cj[Cl[Cn[Cp[Cr[Ct[Cv[Cx[Cz[C|[C~ +`[Cb[Cd[Cf[Ch[Cj[Cl[Cn[Cp[Cr[Ct[Cv[Cx[Cz[C|[C~(B +#6[7m`abcdefghijklmnopqrstuvwxyz{|}~(0[0m mqvqj[A(B +[0m[Ca[Cc[Ce[Cg[Ci[Ck[Cm[Co[Cq[Cs[Cu[Cw[Cy[C{[C} +PrEM0\ $PrEM0 works on GIGI [A[1;7m + This test created by Joe Smith, 8-May-85 [0m +[1;r[22;1H + http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/a1a2f2c5/tools/bin/pythonSrc/pexpect-4.2/tests/utils.py ---------------------------------------------------------------------- diff --git a/tools/bin/pythonSrc/pexpect-4.2/tests/utils.py b/tools/bin/pythonSrc/pexpect-4.2/tests/utils.py new file mode 100644 index 0000000..dcd3aa0 --- /dev/null +++ b/tools/bin/pythonSrc/pexpect-4.2/tests/utils.py @@ -0,0 +1,7 @@ +import os + +def no_coverage_env(): + "Return a copy of os.environ that won't trigger coverage measurement." + env = os.environ.copy() + env.pop('COV_CORE_SOURCE', None) + return env \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/a1a2f2c5/tools/bin/pythonSrc/pexpect-4.2/tools/display-fpathconf.py ---------------------------------------------------------------------- diff --git a/tools/bin/pythonSrc/pexpect-4.2/tools/display-fpathconf.py b/tools/bin/pythonSrc/pexpect-4.2/tools/display-fpathconf.py new file mode 100644 index 0000000..d40cbae --- /dev/null +++ b/tools/bin/pythonSrc/pexpect-4.2/tools/display-fpathconf.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +"""Displays os.fpathconf values related to terminals. """ +from __future__ import print_function +import sys +import os + + +def display_fpathconf(): + DISP_VALUES = ( + ('PC_MAX_CANON', ('Max no. of bytes in a ' + 'terminal canonical input line.')), + ('PC_MAX_INPUT', ('Max no. of bytes for which ' + 'space is available in a terminal input queue.')), + ('PC_PIPE_BUF', ('Max no. of bytes which will ' + 'be written atomically to a pipe.')), + ('PC_VDISABLE', 'Terminal character disabling value.') + ) + FMT = '{name:<13} {value:<5} {description}' + + # column header + print(FMT.format(name='name', value='value', description='description')) + print(FMT.format(name=('-' * 13), value=('-' * 5), description=('-' * 11))) + + fd = sys.stdin.fileno() + for name, description in DISP_VALUES: + key = os.pathconf_names.get(name, None) + if key is None: + value = 'UNDEF' + else: + try: + value = os.fpathconf(fd, name) + except OSError as err: + value = 'OSErrno {0.errno}'.format(err) + if name == 'PC_VDISABLE': + value = hex(value) + print(FMT.format(name=name, value=value, description=description)) + print() + + +if __name__ == '__main__': + display_fpathconf() http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/a1a2f2c5/tools/bin/pythonSrc/pexpect-4.2/tools/display-maxcanon.py ---------------------------------------------------------------------- diff --git a/tools/bin/pythonSrc/pexpect-4.2/tools/display-maxcanon.py b/tools/bin/pythonSrc/pexpect-4.2/tools/display-maxcanon.py new file mode 100644 index 0000000..cbd664f --- /dev/null +++ b/tools/bin/pythonSrc/pexpect-4.2/tools/display-maxcanon.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python +""" +This tool uses pexpect to test expected Canonical mode length. + +All systems use the value of MAX_CANON which can be found using +fpathconf(3) value PC_MAX_CANON -- with the exception of Linux +and FreeBSD. + +Linux, though defining a value of 255, actually honors the value +of 4096 from linux kernel include file tty.h definition +N_TTY_BUF_SIZE. + +Linux also does not honor IMAXBEL. termios(3) states, "Linux does not +implement this bit, and acts as if it is always set." Although these +tests ensure it is enabled, this is a non-op for Linux. + +FreeBSD supports neither, and instead uses a fraction (1/5) of the tty +speed which is always 9600. Therefor, the maximum limited input line +length is 9600 / 5 = 1920. + +These tests only ensure the correctness of the behavior described by +the sendline() docstring -- the values listed there, and above should +be equal to the output of the given OS described, but no promises! +""" +# std import +from __future__ import print_function +import sys +import os + + +def detect_maxcanon(): + import pexpect + bashrc = os.path.join( + # re-use pexpect/replwrap.py's bashrc file, + os.path.dirname(__file__), os.path.pardir, 'pexpect', 'bashrc.sh') + + child = pexpect.spawn('bash', ['--rcfile', bashrc], + echo=True, encoding='utf8', timeout=3) + + child.sendline(u'echo -n READY_; echo GO') + child.expect_exact(u'READY_GO') + + child.sendline(u'stty icanon imaxbel erase ^H; echo -n retval: $?') + child.expect_exact(u'retval: 0') + + child.sendline(u'echo -n GO_; echo AGAIN') + child.expect_exact(u'GO_AGAIN') + child.sendline(u'cat') + + child.delaybeforesend = 0 + + column, blocksize = 0, 64 + ch_marker = u'_' + + print('auto-detecting MAX_CANON: ', end='') + sys.stdout.flush() + + while True: + child.send(ch_marker * blocksize) + result = child.expect([ch_marker * blocksize, u'\a']) + if result == 0: + # entire block fit without emitting bel + column += blocksize + elif result == 1: + # an '\a' was emitted, count the number of ch_markers + # found since last blocksize, determining our MAX_CANON + column += child.before.count(ch_marker) + break + print(column) + +if __name__ == '__main__': + try: + detect_maxcanon() + except ImportError: + # we'd like to use this with CI -- but until we integrate + # with tox, we can't determine a period in testing when + # the pexpect module has been installed + print('warning: pexpect not in module path, MAX_CANON ' + 'could not be determined by systems test.', + file=sys.stderr) http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/a1a2f2c5/tools/bin/pythonSrc/pexpect-4.2/tools/display-sighandlers.py ---------------------------------------------------------------------- diff --git a/tools/bin/pythonSrc/pexpect-4.2/tools/display-sighandlers.py b/tools/bin/pythonSrc/pexpect-4.2/tools/display-sighandlers.py new file mode 100755 index 0000000..f3559f7 --- /dev/null +++ b/tools/bin/pythonSrc/pexpect-4.2/tools/display-sighandlers.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# Displays all signals, their values, and their handlers. +from __future__ import print_function +import signal +FMT = '{name:<10} {value:<5} {description}' + +# header +print(FMT.format(name='name', value='value', description='description')) +print('-' * (33)) + +for name, value in [(signal_name, getattr(signal, signal_name)) + for signal_name in dir(signal) + if signal_name.startswith('SIG') + and not signal_name.startswith('SIG_')]: + try: + handler = signal.getsignal(value) + except ValueError: + # FreeBSD: signal number out of range + handler = 'out of range' + description = { + signal.SIG_IGN: "ignored(SIG_IGN)", + signal.SIG_DFL: "default(SIG_DFL)" + }.get(handler, handler) + print(FMT.format(name=name, value=value, description=description)) http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/a1a2f2c5/tools/bin/pythonSrc/pexpect-4.2/tools/display-terminalinfo.py ---------------------------------------------------------------------- diff --git a/tools/bin/pythonSrc/pexpect-4.2/tools/display-terminalinfo.py b/tools/bin/pythonSrc/pexpect-4.2/tools/display-terminalinfo.py new file mode 100755 index 0000000..15911d4 --- /dev/null +++ b/tools/bin/pythonSrc/pexpect-4.2/tools/display-terminalinfo.py @@ -0,0 +1,209 @@ +#!/usr/bin/env python +""" Display known information about our terminal. """ +from __future__ import print_function +import termios +import locale +import sys +import os + +BITMAP_IFLAG = { + 'IGNBRK': 'ignore BREAK condition', + 'BRKINT': 'map BREAK to SIGINTR', + 'IGNPAR': 'ignore (discard) parity errors', + 'PARMRK': 'mark parity and framing errors', + 'INPCK': 'enable checking of parity errors', + 'ISTRIP': 'strip 8th bit off chars', + 'INLCR': 'map NL into CR', + 'IGNCR': 'ignore CR', + 'ICRNL': 'map CR to NL (ala CRMOD)', + 'IXON': 'enable output flow control', + 'IXOFF': 'enable input flow control', + 'IXANY': 'any char will restart after stop', + 'IMAXBEL': 'ring bell on input queue full', + 'IUCLC': 'translate upper case to lower case', +} + +BITMAP_OFLAG = { + 'OPOST': 'enable following output processing', + 'ONLCR': 'map NL to CR-NL (ala CRMOD)', + 'OXTABS': 'expand tabs to spaces', + 'ONOEOT': 'discard EOT\'s `^D\' on output)', + 'OCRNL': 'map CR to NL', + 'OLCUC': 'translate lower case to upper case', + 'ONOCR': 'No CR output at column 0', + 'ONLRET': 'NL performs CR function', +} + +BITMAP_CFLAG = { + 'CSIZE': 'character size mask', + 'CS5': '5 bits (pseudo)', + 'CS6': '6 bits', + 'CS7': '7 bits', + 'CS8': '8 bits', + 'CSTOPB': 'send 2 stop bits', + 'CREAD': 'enable receiver', + 'PARENB': 'parity enable', + 'PARODD': 'odd parity, else even', + 'HUPCL': 'hang up on last close', + 'CLOCAL': 'ignore modem status lines', + 'CCTS_OFLOW': 'CTS flow control of output', + 'CRTSCTS': 'same as CCTS_OFLOW', + 'CRTS_IFLOW': 'RTS flow control of input', + 'MDMBUF': 'flow control output via Carrier', +} + +BITMAP_LFLAG = { + 'ECHOKE': 'visual erase for line kill', + 'ECHOE': 'visually erase chars', + 'ECHO': 'enable echoing', + 'ECHONL': 'echo NL even if ECHO is off', + 'ECHOPRT': 'visual erase mode for hardcopy', + 'ECHOCTL': 'echo control chars as ^(Char)', + 'ISIG': 'enable signals INTR, QUIT, [D]SUSP', + 'ICANON': 'canonicalize input lines', + 'ALTWERASE': 'use alternate WERASE algorithm', + 'IEXTEN': 'enable DISCARD and LNEXT', + 'EXTPROC': 'external processing', + 'TOSTOP': 'stop background jobs from output', + 'FLUSHO': 'output being flushed (state)', + 'NOKERNINFO': 'no kernel output from VSTATUS', + 'PENDIN': 'XXX retype pending input (state)', + 'NOFLSH': 'don\'t flush after interrupt', +} + +CTLCHAR_INDEX = { + 'VEOF': 'EOF', + 'VEOL': 'EOL', + 'VEOL2': 'EOL2', + 'VERASE': 'ERASE', + 'VWERASE': 'WERASE', + 'VKILL': 'KILL', + 'VREPRINT': 'REPRINT', + 'VINTR': 'INTR', + 'VQUIT': 'QUIT', + 'VSUSP': 'SUSP', + 'VDSUSP': 'DSUSP', + 'VSTART': 'START', + 'VSTOP': 'STOP', + 'VLNEXT': 'LNEXT', + 'VDISCARD': 'DISCARD', + 'VMIN': '---', + 'VTIME': '---', + 'VSTATUS': 'STATUS', +} + + +def display_bitmask(kind, bitmap, value): + """ Display all matching bitmask values for ``value`` given ``bitmap``. """ + col1_width = max(map(len, list(bitmap.keys()) + [kind])) + col2_width = 7 + FMT = '{name:>{col1_width}} {value:>{col2_width}} {description}' + print(FMT.format(name=kind, + value='Value', + description='Description', + col1_width=col1_width, + col2_width=col2_width)) + print('{0} {1} {2}'.format('-' * col1_width, + '-' * col2_width, + '-' * max(map(len, bitmap.values())))) + for flag_name, description in bitmap.items(): + try: + bitmask = getattr(termios, flag_name) + bit_val = 'on' if bool(value & bitmask) else 'off' + except AttributeError: + bit_val = 'undef' + print(FMT.format(name=flag_name, + value=bit_val, + description=description, + col1_width=col1_width, + col2_width=col2_width)) + print() + + +def display_ctl_chars(index, cc): + """ Display all control character indicies, names, and values. """ + title = 'Special Character' + col1_width = len(title) + col2_width = max(map(len, index.values())) + FMT = '{idx:<{col1_width}} {name:<{col2_width}} {value}' + print('Special line Characters'.center(40).rstrip()) + print(FMT.format(idx='Index', + name='Name', + value='Value', + col1_width=col1_width, + col2_width=col2_width)) + print('{0} {1} {2}'.format('-' * col1_width, + '-' * col2_width, + '-' * 10)) + for index_name, name in index.items(): + try: + index = getattr(termios, index_name) + value = cc[index] + if value == b'\xff': + value = '_POSIX_VDISABLE' + else: + value = repr(value) + except AttributeError: + value = 'undef' + print(FMT.format(idx=index_name, + name=name, + value=value, + col1_width=col1_width, + col2_width=col2_width)) + print() + + +def display_conf(kind, names, getter): + col1_width = max(map(len, names)) + FMT = '{name:>{col1_width}} {value}' + print(FMT.format(name=kind, + value='value', + col1_width=col1_width)) + print('{0} {1}'.format('-' * col1_width, '-' * 27)) + for name in names: + try: + value = getter(name) + except OSError as err: + value = err + print(FMT.format(name=name, value=value, col1_width=col1_width)) + print() + + +def main(): + fd = sys.stdin.fileno() + locale.setlocale(locale.LC_ALL, '') + encoding = locale.getpreferredencoding() + + print('os.isatty({0}) => {1}'.format(fd, os.isatty(fd))) + print('locale.getpreferredencoding() => {0}'.format(encoding)) + + display_conf(kind='pathconf', + names=os.pathconf_names, + getter=lambda name: os.fpathconf(fd, name)) + + try: + (iflag, oflag, cflag, lflag, ispeed, ospeed, cc + ) = termios.tcgetattr(fd) + except termios.error as err: + print('stdin is not a typewriter: {0}'.format(err)) + else: + display_bitmask(kind='Input Mode', + bitmap=BITMAP_IFLAG, + value=iflag) + display_bitmask(kind='Output Mode', + bitmap=BITMAP_OFLAG, + value=oflag) + display_bitmask(kind='Control Mode', + bitmap=BITMAP_CFLAG, + value=cflag) + display_bitmask(kind='Local Mode', + bitmap=BITMAP_LFLAG, + value=lflag) + display_ctl_chars(index=CTLCHAR_INDEX, + cc=cc) + print('os.ttyname({0}) => {1}'.format(fd, os.ttyname(fd))) + print('os.ctermid() => {0}'.format(os.ttyname(fd))) + + +if __name__ == '__main__': + main() http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/a1a2f2c5/tools/bin/pythonSrc/pexpect-4.2/tools/teamcity-coverage-report.sh ---------------------------------------------------------------------- diff --git a/tools/bin/pythonSrc/pexpect-4.2/tools/teamcity-coverage-report.sh b/tools/bin/pythonSrc/pexpect-4.2/tools/teamcity-coverage-report.sh new file mode 100755 index 0000000..2e32241 --- /dev/null +++ b/tools/bin/pythonSrc/pexpect-4.2/tools/teamcity-coverage-report.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# This is to be executed by each individual OS test. It only +# combines coverage files and reports locally to the given +# TeamCity build configuration. +set -e +set -o pipefail +[ -z ${TEMP} ] && TEMP=/tmp + +# combine all .coverage* files, +coverage combine + +# create ascii report, +report_file=$(mktemp $TEMP/coverage.XXXXX) +coverage report --rcfile=`dirname $0`/../.coveragerc > "${report_file}" 2>/dev/null + +# Report Code Coverage for TeamCity, using 'Service Messages', +# https://confluence.jetbrains.com/display/TCD8/How+To...#HowTo...-ImportcoverageresultsinTeamCity +# https://confluence.jetbrains.com/display/TCD8/Custom+Chart#CustomChart-DefaultStatisticsValuesProvidedbyTeamCity +total_no_lines=$(awk '/TOTAL/{printf("%s",$2)}' < "${report_file}") +total_no_misses=$(awk '/TOTAL/{printf("%s",$3)}' < "${report_file}") +total_no_covered=$((${total_no_lines} - ${total_no_misses})) +echo "##teamcity[buildStatisticValue key='CodeCoverageAbsLTotal' value='""${total_no_lines}""']" +echo "##teamcity[buildStatisticValue key='CodeCoverageAbsLCovered' value='""${total_no_covered}""']" + +# Display for human consumption and remove ascii file. +cat "${report_file}" +rm "${report_file}" http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/a1a2f2c5/tools/bin/pythonSrc/pexpect-4.2/tools/teamcity-runtests.sh ---------------------------------------------------------------------- diff --git a/tools/bin/pythonSrc/pexpect-4.2/tools/teamcity-runtests.sh b/tools/bin/pythonSrc/pexpect-4.2/tools/teamcity-runtests.sh new file mode 100755 index 0000000..bcb28f7 --- /dev/null +++ b/tools/bin/pythonSrc/pexpect-4.2/tools/teamcity-runtests.sh @@ -0,0 +1,64 @@ +#!/bin/bash +# +# This script assumes that the project 'ptyprocess' is +# available in the parent of the project's folder. +set -e +set -o pipefail + +if [ -z $1 ]; then + echo "$0 (2.6|2.7|3.3|3.4)" + exit 1 +fi + +export PYTHONIOENCODING=UTF8 +export LANG=en_US.UTF-8 + +pyversion=$1 +shift +here=$(cd `dirname $0`; pwd) +osrel=$(uname -s) +venv=teamcity-pexpect +venv_wrapper=$(which virtualenvwrapper.sh) + +if [ -z $venv_wrapper ]; then + echo "virtualenvwrapper.sh not found in PATH." >&2 + exit 1 +fi + +. ${venv_wrapper} +rmvirtualenv ${venv} || true +mkvirtualenv -p `which python${pyversion}` ${venv} || true +workon ${venv} + +# install ptyprocess +cd $here/../../ptyprocess +pip uninstall --yes ptyprocess || true +python setup.py install + +# install all test requirements +pip install --upgrade pytest-cov coverage coveralls pytest-capturelog + +# run tests +cd $here/.. +ret=0 +py.test \ + --cov pexpect \ + --cov-config .coveragerc \ + --junit-xml=results.${osrel}.py${pyversion}.xml \ + --verbose \ + --verbose \ + "$@" || ret=$? + +if [ $ret -ne 0 ]; then + # we always exit 0, preferring instead the jUnit XML + # results to be the dominate cause of a failed build. + echo "py.test returned exit code ${ret}." >&2 + echo "the build should detect and report these failing tests." >&2 +fi + +# combine all coverage to single file, report for this build, +# then move into ./build-output/ as a unique artifact to allow +# the final "Full build" step to combine and report to coveralls.io +`dirname $0`/teamcity-coverage-report.sh +mkdir -p build-output +mv .coverage build-output/.coverage.${osrel}.py{$pyversion}.$RANDOM.$$
