You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hawq.apache.org by rl...@apache.org on 2016/08/18 02:44:29 UTC
[04/11] incubator-hawq git commit: HAWQ-838. Replace python module
paramiko with pexpect
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/a1a2f2c5/tools/bin/pythonSrc/pexpect-4.2/tests/test_destructor.py
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/pexpect-4.2/tests/test_destructor.py b/tools/bin/pythonSrc/pexpect-4.2/tests/test_destructor.py
new file mode 100755
index 0000000..d27b6f6
--- /dev/null
+++ b/tools/bin/pythonSrc/pexpect-4.2/tests/test_destructor.py
@@ -0,0 +1,84 @@
+#!/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 <no...@noah.org>
+ 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 gc
+import platform
+import time
+
+class TestCaseDestructor(PexpectTestCase.PexpectTestCase):
+ def test_destructor (self):
+ if platform.python_implementation() != 'CPython':
+ # Details of garbage collection are different on other implementations
+ return 'SKIP'
+ gc.collect()
+ time.sleep(3)
+ p1 = pexpect.spawn('%s hello_world.py' % self.PYTHONBIN)
+ p2 = pexpect.spawn('%s hello_world.py' % self.PYTHONBIN)
+ p3 = pexpect.spawn('%s hello_world.py' % self.PYTHONBIN)
+ p4 = pexpect.spawn('%s hello_world.py' % self.PYTHONBIN)
+ fd_t1 = (p1.child_fd,p2.child_fd,p3.child_fd,p4.child_fd)
+ p1.expect(pexpect.EOF)
+ p2.expect(pexpect.EOF)
+ p3.expect(pexpect.EOF)
+ p4.expect(pexpect.EOF)
+ p1.kill(9)
+ p2.kill(9)
+ p3.kill(9)
+ p4.kill(9)
+ p1 = None
+ p2 = None
+ p3 = None
+ p4 = None
+ gc.collect()
+ time.sleep(3) # Some platforms are slow at gc... Solaris!
+
+ p1 = pexpect.spawn('%s hello_world.py' % self.PYTHONBIN)
+ p2 = pexpect.spawn('%s hello_world.py' % self.PYTHONBIN)
+ p3 = pexpect.spawn('%s hello_world.py' % self.PYTHONBIN)
+ p4 = pexpect.spawn('%s hello_world.py' % self.PYTHONBIN)
+ fd_t2 = (p1.child_fd,p2.child_fd,p3.child_fd,p4.child_fd)
+ p1.kill(9)
+ p2.kill(9)
+ p3.kill(9)
+ p4.kill(9)
+ del (p1)
+ del (p2)
+ del (p3)
+ del (p4)
+ gc.collect()
+ time.sleep(3)
+
+ p1 = pexpect.spawn('%s hello_world.py' % self.PYTHONBIN)
+ p2 = pexpect.spawn('%s hello_world.py' % self.PYTHONBIN)
+ p3 = pexpect.spawn('%s hello_world.py' % self.PYTHONBIN)
+ p4 = pexpect.spawn('%s hello_world.py' % self.PYTHONBIN)
+ fd_t3 = (p1.child_fd,p2.child_fd,p3.child_fd,p4.child_fd)
+
+ assert (fd_t1 == fd_t2 == fd_t3), "pty file descriptors not properly garbage collected (fd_t1,fd_t2,fd_t3)=(%s,%s,%s)" % (str(fd_t1),str(fd_t2),str(fd_t3))
+
+
+if __name__ == '__main__':
+ unittest.main()
+
+suite = unittest.makeSuite(TestCaseDestructor,'test')
+
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/a1a2f2c5/tools/bin/pythonSrc/pexpect-4.2/tests/test_dotall.py
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/pexpect-4.2/tests/test_dotall.py b/tools/bin/pythonSrc/pexpect-4.2/tests/test_dotall.py
new file mode 100755
index 0000000..68aef3f
--- /dev/null
+++ b/tools/bin/pythonSrc/pexpect-4.2/tests/test_dotall.py
@@ -0,0 +1,43 @@
+#!/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 <no...@noah.org>
+ 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 re
+from . import PexpectTestCase
+
+testdata = 'BEGIN\nHello world\nEND'
+class TestCaseDotall(PexpectTestCase.PexpectTestCase):
+ def test_dotall (self):
+ p = pexpect.spawn('echo "%s"' % testdata)
+ i = p.expect ([b'BEGIN(.*)END', pexpect.EOF])
+ assert i==0, 'DOTALL does not seem to be working.'
+
+ def test_precompiled (self):
+ p = pexpect.spawn('echo "%s"' % testdata)
+ pat = re.compile(b'BEGIN(.*)END') # This overrides the default DOTALL.
+ i = p.expect ([pat, pexpect.EOF])
+ assert i==1, 'Precompiled pattern to override DOTALL does not seem to be working.'
+
+if __name__ == '__main__':
+ unittest.main()
+
+suite = unittest.makeSuite(TestCaseDotall,'test')
+
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/a1a2f2c5/tools/bin/pythonSrc/pexpect-4.2/tests/test_env.py
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/pexpect-4.2/tests/test_env.py b/tools/bin/pythonSrc/pexpect-4.2/tests/test_env.py
new file mode 100755
index 0000000..ecaaa4b
--- /dev/null
+++ b/tools/bin/pythonSrc/pexpect-4.2/tests/test_env.py
@@ -0,0 +1,93 @@
+#!/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) 2016, Martin Packman <ma...@canonical.com>
+ 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 contextlib
+import os
+import tempfile
+import unittest
+
+import pexpect
+from . import PexpectTestCase
+
+
+@contextlib.contextmanager
+def example_script(name, output='success'):
+ " helper to create a temporary shell script that tests can run "
+ tempdir = tempfile.mkdtemp(prefix='tmp-pexpect-test')
+ try:
+ script_path = os.path.join(tempdir, name)
+ with open(script_path, 'w') as f:
+ f.write('#!/bin/sh\necho "%s"' % (output,))
+ try:
+ os.chmod(script_path, 0o755)
+ yield tempdir
+ finally:
+ os.remove(script_path)
+ finally:
+ os.rmdir(tempdir)
+
+
+class TestCaseEnv(PexpectTestCase.PexpectTestCase):
+ " tests for the env argument to pexpect.spawn and pexpect.run "
+
+ def test_run_uses_env(self):
+ " pexpect.run uses env argument when running child process "
+ script_name = 'run_uses_env.sh'
+ environ = {'PEXPECT_TEST_KEY': 'pexpect test value'}
+ with example_script(script_name, '$PEXPECT_TEST_KEY') as script_dir:
+ script = os.path.join(script_dir, script_name)
+ out = pexpect.run(script, env=environ)
+ self.assertEqual(out.rstrip(), b'pexpect test value')
+
+ def test_spawn_uses_env(self):
+ " pexpect.spawn uses env argument when running child process "
+ script_name = 'spawn_uses_env.sh'
+ environ = {'PEXPECT_TEST_KEY': 'pexpect test value'}
+ with example_script(script_name, '$PEXPECT_TEST_KEY') as script_dir:
+ script = os.path.join(script_dir, script_name)
+ child = pexpect.spawn(script, env=environ)
+ out = child.readline()
+ child.expect(pexpect.EOF)
+ self.assertEqual(child.exitstatus, 0)
+ self.assertEqual(out.rstrip(), b'pexpect test value')
+
+ def test_run_uses_env_path(self):
+ " pexpect.run uses binary from PATH when given in env argument "
+ script_name = 'run_uses_env_path.sh'
+ with example_script(script_name) as script_dir:
+ out = pexpect.run(script_name, env={'PATH': script_dir})
+ self.assertEqual(out.rstrip(), b'success')
+
+ def test_run_uses_env_path_over_path(self):
+ " pexpect.run uses PATH from env over os.environ "
+ script_name = 'run_uses_env_path_over_path.sh'
+ with example_script(script_name, output='failure') as wrong_dir:
+ with example_script(script_name) as right_dir:
+ orig_path = os.environ['PATH']
+ os.environ['PATH'] = wrong_dir
+ try:
+ out = pexpect.run(script_name, env={'PATH': right_dir})
+ finally:
+ os.environ['PATH'] = orig_path
+ self.assertEqual(out.rstrip(), b'success')
+
+
+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_expect.py
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/pexpect-4.2/tests/test_expect.py b/tools/bin/pythonSrc/pexpect-4.2/tests/test_expect.py
new file mode 100755
index 0000000..dcf059b
--- /dev/null
+++ b/tools/bin/pythonSrc/pexpect-4.2/tests/test_expect.py
@@ -0,0 +1,583 @@
+#!/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 <no...@noah.org>
+ 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 multiprocessing
+import unittest
+import subprocess
+import time
+import signal
+import sys
+import os
+
+import pexpect
+from . import PexpectTestCase
+from .utils import no_coverage_env
+
+# Many of these test cases blindly assume that sequential directory
+# listings of the /bin directory will yield the same results.
+# This may not be true, but seems adequate for testing now.
+# I should fix this at some point.
+
+FILTER=''.join([(len(repr(chr(x)))==3) and chr(x) or '.' for x in range(256)])
+def hex_dump(src, length=16):
+ result=[]
+ for i in xrange(0, len(src), length):
+ s = src[i:i+length]
+ hexa = ' '.join(["%02X"%ord(x) for x in s])
+ printable = s.translate(FILTER)
+ result.append("%04X %-*s %s\n" % (i, length*3, hexa, printable))
+ return ''.join(result)
+
+def hex_diff(left, right):
+ diff = ['< %s\n> %s' % (_left, _right,) for _left, _right in zip(
+ hex_dump(left).splitlines(), hex_dump(right).splitlines())
+ if _left != _right]
+ return '\n' + '\n'.join(diff,)
+
+
+class ExpectTestCase (PexpectTestCase.PexpectTestCase):
+
+ def test_expect_basic (self):
+ p = pexpect.spawn('cat', echo=False, timeout=5)
+ p.sendline (b'Hello')
+ p.sendline (b'there')
+ p.sendline (b'Mr. Python')
+ p.expect (b'Hello')
+ p.expect (b'there')
+ p.expect (b'Mr. Python')
+ p.sendeof ()
+ p.expect (pexpect.EOF)
+
+ def test_expect_exact_basic (self):
+ p = pexpect.spawn('cat', echo=False, timeout=5)
+ p.sendline (b'Hello')
+ p.sendline (b'there')
+ p.sendline (b'Mr. Python')
+ p.expect_exact (b'Hello')
+ p.expect_exact (b'there')
+ p.expect_exact (b'Mr. Python')
+ p.sendeof ()
+ p.expect_exact (pexpect.EOF)
+
+ def test_expect_ignore_case(self):
+ '''This test that the ignorecase flag will match patterns
+ even if case is different using the regex (?i) directive.
+ '''
+ p = pexpect.spawn('cat', echo=False, timeout=5)
+ p.sendline (b'HELLO')
+ p.sendline (b'there')
+ p.expect (b'(?i)hello')
+ p.expect (b'(?i)THERE')
+ p.sendeof ()
+ p.expect (pexpect.EOF)
+
+ def test_expect_ignore_case_flag(self):
+ '''This test that the ignorecase flag will match patterns
+ even if case is different using the ignorecase flag.
+ '''
+ p = pexpect.spawn('cat', echo=False, timeout=5)
+ p.ignorecase = True
+ p.sendline (b'HELLO')
+ p.sendline (b'there')
+ p.expect (b'hello')
+ p.expect (b'THERE')
+ p.sendeof ()
+ p.expect (pexpect.EOF)
+
+ def test_expect_order (self):
+ '''This tests that patterns are matched in the same order as given in the pattern_list.
+
+ (Or does it? Doesn't it also pass if expect() always chooses
+ (one of the) the leftmost matches in the input? -- grahn)
+ ... agreed! -jquast, the buffer ptr isn't forwarded on match, see first two test cases
+ '''
+ p = pexpect.spawn('cat', echo=False, timeout=5)
+ self._expect_order(p)
+
+ def test_expect_order_exact (self):
+ '''Like test_expect_order(), but using expect_exact().
+ '''
+ p = pexpect.spawn('cat', echo=False, timeout=5)
+ p.expect = p.expect_exact
+ self._expect_order(p)
+
+ def _expect_order (self, p):
+ p.sendline (b'1234')
+ p.sendline (b'abcd')
+ p.sendline (b'wxyz')
+ p.sendline (b'7890')
+ p.sendeof ()
+ index = p.expect ([
+ b'1234',
+ b'abcd',
+ b'wxyz',
+ pexpect.EOF,
+ b'7890' ])
+ assert index == 0, (index, p.before, p.after)
+ index = p.expect ([
+ b'54321',
+ pexpect.TIMEOUT,
+ b'1234',
+ b'abcd',
+ b'wxyz',
+ pexpect.EOF], timeout=5)
+ assert index == 3, (index, p.before, p.after)
+ index = p.expect ([
+ b'54321',
+ pexpect.TIMEOUT,
+ b'1234',
+ b'abcd',
+ b'wxyz',
+ pexpect.EOF], timeout=5)
+ assert index == 4, (index, p.before, p.after)
+ index = p.expect ([
+ pexpect.EOF,
+ b'abcd',
+ b'wxyz',
+ b'7890' ])
+ assert index == 3, (index, p.before, p.after)
+
+ index = p.expect ([
+ b'abcd',
+ b'wxyz',
+ b'7890',
+ pexpect.EOF])
+ assert index == 3, (index, p.before, p.after)
+
+ def test_expect_setecho_off(self):
+ '''This tests that echo may be toggled off.
+ '''
+ p = pexpect.spawn('cat', echo=True, timeout=5)
+ try:
+ self._expect_echo_toggle(p)
+ except IOError:
+ if sys.platform.lower().startswith('sunos'):
+ if hasattr(unittest, 'SkipTest'):
+ raise unittest.SkipTest("Not supported on this platform.")
+ return 'skip'
+ raise
+
+ def test_expect_setecho_off_exact(self):
+ p = pexpect.spawn('cat', echo=True, timeout=5)
+ p.expect = p.expect_exact
+ try:
+ self._expect_echo_toggle(p)
+ except IOError:
+ if sys.platform.lower().startswith('sunos'):
+ if hasattr(unittest, 'SkipTest'):
+ raise unittest.SkipTest("Not supported on this platform.")
+ return 'skip'
+ raise
+
+ def test_waitnoecho(self):
+ " Tests setecho(False) followed by waitnoecho() "
+ p = pexpect.spawn('cat', echo=False, timeout=5)
+ try:
+ p.setecho(False)
+ p.waitnoecho()
+ except IOError:
+ if sys.platform.lower().startswith('sunos'):
+ if hasattr(unittest, 'SkipTest'):
+ raise unittest.SkipTest("Not supported on this platform.")
+ return 'skip'
+ raise
+
+ def test_waitnoecho_order(self):
+
+ ''' This tests that we can wait on a child process to set echo mode.
+ For example, this tests that we could wait for SSH to set ECHO False
+ when asking of a password. This makes use of an external script
+ echo_wait.py. '''
+
+ p1 = pexpect.spawn('%s echo_wait.py' % self.PYTHONBIN)
+ start = time.time()
+ try:
+ p1.waitnoecho(timeout=10)
+ except IOError:
+ if sys.platform.lower().startswith('sunos'):
+ if hasattr(unittest, 'SkipTest'):
+ raise unittest.SkipTest("Not supported on this platform.")
+ return 'skip'
+ raise
+
+
+ end_time = time.time() - start
+ assert end_time < 10 and end_time > 2, "waitnoecho did not set ECHO off in the expected window of time."
+
+ # test that we actually timeout and return False if ECHO is never set off.
+ p1 = pexpect.spawn('cat')
+ start = time.time()
+ retval = p1.waitnoecho(timeout=4)
+ end_time = time.time() - start
+ assert end_time > 3, "waitnoecho should have waited longer than 2 seconds. retval should be False, retval=%d"%retval
+ assert retval==False, "retval should be False, retval=%d"%retval
+
+ # This one is mainly here to test default timeout for code coverage.
+ p1 = pexpect.spawn('%s echo_wait.py' % self.PYTHONBIN)
+ start = time.time()
+ p1.waitnoecho()
+ end_time = time.time() - start
+ assert end_time < 10, "waitnoecho did not set ECHO off in the expected window of time."
+
+ def test_expect_echo (self):
+ '''This tests that echo is on by default.
+ '''
+ p = pexpect.spawn('cat', echo=True, timeout=5)
+ self._expect_echo(p)
+
+ def test_expect_echo_exact (self):
+ '''Like test_expect_echo(), but using expect_exact().
+ '''
+ p = pexpect.spawn('cat', echo=True, timeout=5)
+ p.expect = p.expect_exact
+ self._expect_echo(p)
+
+ def _expect_echo (self, p):
+ p.sendline (b'1234') # Should see this twice (once from tty echo and again from cat).
+ index = p.expect ([
+ b'1234',
+ b'abcd',
+ b'wxyz',
+ pexpect.EOF,
+ pexpect.TIMEOUT])
+ assert index == 0, "index="+str(index)+"\n"+p.before
+ index = p.expect ([
+ b'1234',
+ b'abcd',
+ b'wxyz',
+ pexpect.EOF])
+ assert index == 0, "index="+str(index)
+
+ def _expect_echo_toggle(self, p):
+ p.sendline (b'1234') # Should see this twice (once from tty echo and again from cat).
+ index = p.expect ([
+ b'1234',
+ b'abcd',
+ b'wxyz',
+ pexpect.EOF,
+ pexpect.TIMEOUT])
+ assert index == 0, "index="+str(index)+"\n"+p.before
+ index = p.expect ([
+ b'1234',
+ b'abcd',
+ b'wxyz',
+ pexpect.EOF])
+ assert index == 0, "index="+str(index)
+ p.setecho(0) # Turn off tty echo
+ p.waitnoecho()
+ p.sendline (b'abcd') # Now, should only see this once.
+ p.sendline (b'wxyz') # Should also be only once.
+ index = p.expect ([
+ pexpect.EOF,
+ pexpect.TIMEOUT,
+ b'abcd',
+ b'wxyz',
+ b'1234'])
+ assert index == 2, "index="+str(index)
+ index = p.expect ([
+ pexpect.EOF,
+ b'abcd',
+ b'wxyz',
+ b'7890'])
+ assert index == 2, "index="+str(index)
+ p.setecho(1) # Turn on tty echo
+ p.sendline (b'7890') # Should see this twice.
+ index = p.expect ([pexpect.EOF,b'abcd',b'wxyz',b'7890'])
+ assert index == 3, "index="+str(index)
+ index = p.expect ([pexpect.EOF,b'abcd',b'wxyz',b'7890'])
+ assert index == 3, "index="+str(index)
+ p.sendeof()
+
+ def test_expect_index (self):
+ '''This tests that mixed list of regex strings, TIMEOUT, and EOF all
+ return the correct index when matched.
+ '''
+ p = pexpect.spawn('cat', echo=False, timeout=5)
+ self._expect_index(p)
+
+ def test_expect_index_exact (self):
+ '''Like test_expect_index(), but using expect_exact().
+ '''
+ p = pexpect.spawn('cat', echo=False, timeout=5)
+ p.expect = p.expect_exact
+ self._expect_index(p)
+
+ def _expect_index (self, p):
+ p.sendline (b'1234')
+ index = p.expect ([b'abcd',b'wxyz',b'1234',pexpect.EOF])
+ assert index == 2, "index="+str(index)
+ p.sendline (b'abcd')
+ index = p.expect ([pexpect.TIMEOUT,b'abcd',b'wxyz',b'1234',pexpect.EOF])
+ assert index == 1, "index="+str(index)+str(p)
+ p.sendline (b'wxyz')
+ index = p.expect ([b'54321',pexpect.TIMEOUT,b'abcd',b'wxyz',b'1234',pexpect.EOF])
+ assert index == 3, "index="+str(index) # Expect 'wxyz'
+ p.sendline (b'$*!@?')
+ index = p.expect ([b'54321',pexpect.TIMEOUT,b'abcd',b'wxyz',b'1234',pexpect.EOF],
+ timeout=1)
+ assert index == 1, "index="+str(index) # Expect TIMEOUT
+ p.sendeof ()
+ index = p.expect ([b'54321',pexpect.TIMEOUT,b'abcd',b'wxyz',b'1234',pexpect.EOF])
+ assert index == 5, "index="+str(index) # Expect EOF
+
+ def test_expect (self):
+ the_old_way = subprocess.Popen(args=['ls', '-l', '/bin'],
+ stdout=subprocess.PIPE).communicate()[0].rstrip()
+ p = pexpect.spawn('ls -l /bin')
+ the_new_way = b''
+ while 1:
+ i = p.expect ([b'\n', pexpect.EOF])
+ the_new_way = the_new_way + p.before
+ if i == 1:
+ break
+ the_new_way = the_new_way.rstrip()
+ the_new_way = the_new_way.replace(b'\r\n', b'\n'
+ ).replace(b'\r', b'\n').replace(b'\n\n', b'\n').rstrip()
+ the_old_way = the_old_way.replace(b'\r\n', b'\n'
+ ).replace(b'\r', b'\n').replace(b'\n\n', b'\n').rstrip()
+ assert the_old_way == the_new_way, hex_diff(the_old_way, the_new_way)
+
+ def test_expect_exact (self):
+ the_old_way = subprocess.Popen(args=['ls', '-l', '/bin'],
+ stdout=subprocess.PIPE).communicate()[0].rstrip()
+ p = pexpect.spawn('ls -l /bin')
+ the_new_way = b''
+ while 1:
+ i = p.expect_exact ([b'\n', pexpect.EOF])
+ the_new_way = the_new_way + p.before
+ if i == 1:
+ break
+ the_new_way = the_new_way.replace(b'\r\n', b'\n'
+ ).replace(b'\r', b'\n').replace(b'\n\n', b'\n').rstrip()
+ the_old_way = the_old_way.replace(b'\r\n', b'\n'
+ ).replace(b'\r', b'\n').replace(b'\n\n', b'\n').rstrip()
+ assert the_old_way == the_new_way, hex_diff(the_old_way, the_new_way)
+ p = pexpect.spawn('echo hello.?world')
+ i = p.expect_exact(b'.?')
+ self.assertEqual(p.before, b'hello')
+ self.assertEqual(p.after, b'.?')
+
+ def test_expect_eof (self):
+ the_old_way = subprocess.Popen(args=['/bin/ls', '-l', '/bin'],
+ stdout=subprocess.PIPE).communicate()[0].rstrip()
+ p = pexpect.spawn('/bin/ls -l /bin')
+ p.expect(pexpect.EOF) # This basically tells it to read everything. Same as pexpect.run() function.
+ the_new_way = p.before
+ the_new_way = the_new_way.replace(b'\r\n', b'\n'
+ ).replace(b'\r', b'\n').replace(b'\n\n', b'\n').rstrip()
+ the_old_way = the_old_way.replace(b'\r\n', b'\n'
+ ).replace(b'\r', b'\n').replace(b'\n\n', b'\n').rstrip()
+ assert the_old_way == the_new_way, hex_diff(the_old_way, the_new_way)
+
+ def test_expect_timeout (self):
+ p = pexpect.spawn('cat', timeout=5)
+ p.expect(pexpect.TIMEOUT) # This tells it to wait for timeout.
+ self.assertEqual(p.after, pexpect.TIMEOUT)
+
+ def test_unexpected_eof (self):
+ p = pexpect.spawn('ls -l /bin')
+ try:
+ p.expect('_Z_XY_XZ') # Probably never see this in ls output.
+ except pexpect.EOF:
+ pass
+ else:
+ self.fail ('Expected an EOF exception.')
+
+ def _before_after(self, p):
+ p.timeout = 5
+
+ p.expect(b'5')
+ self.assertEqual(p.after, b'5')
+ assert p.before.startswith(b'[0, 1, 2'), p.before
+
+ p.expect(b'50')
+ self.assertEqual(p.after, b'50')
+ assert p.before.startswith(b', 6, 7, 8'), p.before[:20]
+ assert p.before.endswith(b'48, 49, '), p.before[-20:]
+
+ p.expect(pexpect.EOF)
+ self.assertEqual(p.after, pexpect.EOF)
+ assert p.before.startswith(b', 51, 52'), p.before[:20]
+ assert p.before.endswith(b', 99]\r\n'), p.before[-20:]
+
+ def test_before_after(self):
+ '''This tests expect() for some simple before/after things.
+ '''
+ p = pexpect.spawn('%s -Wi list100.py' % self.PYTHONBIN, env=no_coverage_env())
+ self._before_after(p)
+
+ def test_before_after_exact(self):
+ '''This tests some simple before/after things, for
+ expect_exact(). (Grahn broke it at one point.)
+ '''
+ p = pexpect.spawn('%s -Wi list100.py' % self.PYTHONBIN, env=no_coverage_env())
+ # mangle the spawn so we test expect_exact() instead
+ p.expect = p.expect_exact
+ self._before_after(p)
+
+ def _ordering(self, p):
+ p.timeout = 20
+ p.expect(b'>>> ')
+
+ p.sendline('list(range(4*3))')
+ self.assertEqual(p.expect([b'5,', b'5,']), 0)
+ p.expect(b'>>> ')
+
+ p.sendline(b'list(range(4*3))')
+ self.assertEqual(p.expect([b'7,', b'5,']), 1)
+ p.expect(b'>>> ')
+
+ p.sendline(b'list(range(4*3))')
+ self.assertEqual(p.expect([b'5,', b'7,']), 0)
+ p.expect(b'>>> ')
+
+ p.sendline(b'list(range(4*5))')
+ self.assertEqual(p.expect([b'2,', b'12,']), 0)
+ p.expect(b'>>> ')
+
+ p.sendline(b'list(range(4*5))')
+ self.assertEqual(p.expect([b'12,', b'2,']), 1)
+
+ def test_ordering(self):
+ '''This tests expect() for which pattern is returned
+ when many may eventually match. I (Grahn) am a bit
+ confused about what should happen, but this test passes
+ with pexpect 2.1.
+ '''
+ p = pexpect.spawn(self.PYTHONBIN)
+ self._ordering(p)
+
+ def test_ordering_exact(self):
+ '''This tests expect_exact() for which pattern is returned
+ when many may eventually match. I (Grahn) am a bit
+ confused about what should happen, but this test passes
+ for the expect() method with pexpect 2.1.
+ '''
+ p = pexpect.spawn(self.PYTHONBIN)
+ # mangle the spawn so we test expect_exact() instead
+ p.expect = p.expect_exact
+ self._ordering(p)
+
+ def _greed(self, expect):
+ # End at the same point: the one with the earliest start should win
+ self.assertEqual(expect([b'3, 4', b'2, 3, 4']), 1)
+
+ # Start at the same point: first pattern passed wins
+ self.assertEqual(expect([b'5,', b'5, 6']), 0)
+
+ # Same pattern passed twice: first instance wins
+ self.assertEqual(expect([b'7, 8', b'7, 8, 9', b'7, 8']), 0)
+
+ def _greed_read1(self, expect):
+ # Here, one has an earlier start and a later end. When processing
+ # one character at a time, the one that finishes first should win,
+ # because we don't know about the other match when it wins.
+ # If maxread > 1, this behaviour is currently undefined, although in
+ # most cases the one that starts first will win.
+ self.assertEqual(expect([b'1, 2, 3', b'2,']), 1)
+
+ def test_greed(self):
+ p = pexpect.spawn(self.PYTHONBIN + ' list100.py')
+ self._greed(p.expect)
+
+ p = pexpect.spawn(self.PYTHONBIN + ' list100.py', maxread=1)
+ self._greed_read1(p.expect)
+
+ def test_greed_exact(self):
+ p = pexpect.spawn(self.PYTHONBIN + ' list100.py')
+ self._greed(p.expect_exact)
+
+ p = pexpect.spawn(self.PYTHONBIN + ' list100.py', maxread=1)
+ self._greed_read1(p.expect_exact)
+
+ def test_bad_arg(self):
+ p = pexpect.spawn('cat')
+ with self.assertRaisesRegexp(TypeError, '.*must be one of'):
+ p.expect(1)
+ with self.assertRaisesRegexp(TypeError, '.*must be one of'):
+ p.expect([1, b'2'])
+ with self.assertRaisesRegexp(TypeError, '.*must be one of'):
+ p.expect_exact(1)
+ with self.assertRaisesRegexp(TypeError, '.*must be one of'):
+ p.expect_exact([1, b'2'])
+
+ def test_timeout_none(self):
+ p = pexpect.spawn('echo abcdef', timeout=None)
+ p.expect('abc')
+ p.expect_exact('def')
+ p.expect(pexpect.EOF)
+
+ def test_signal_handling(self):
+ '''
+ This tests the error handling of a signal interrupt (usually a
+ SIGWINCH generated when a window is resized), but in this test, we
+ are substituting an ALARM signal as this is much easier for testing
+ and is treated the same as a SIGWINCH.
+
+ To ensure that the alarm fires during the expect call, we are
+ setting the signal to alarm after 1 second while the spawned process
+ sleeps for 2 seconds prior to sending the expected output.
+ '''
+ def noop(x, y):
+ pass
+ signal.signal(signal.SIGALRM, noop)
+
+ p1 = pexpect.spawn('%s sleep_for.py 2' % self.PYTHONBIN, timeout=5)
+ p1.expect('READY')
+ signal.alarm(1)
+ p1.expect('END')
+
+ def test_stdin_closed(self):
+ '''
+ Ensure pexpect continues to operate even when stdin is closed
+ '''
+ class Closed_stdin_proc(multiprocessing.Process):
+ def run(self):
+ sys.__stdin__.close()
+ cat = pexpect.spawn('cat')
+ cat.sendeof()
+ cat.expect(pexpect.EOF)
+
+ proc = Closed_stdin_proc()
+ proc.start()
+ proc.join()
+ assert proc.exitcode == 0
+
+ def test_stdin_stdout_closed(self):
+ '''
+ Ensure pexpect continues to operate even when stdin and stdout is closed
+ '''
+ class Closed_stdin_stdout_proc(multiprocessing.Process):
+ def run(self):
+ sys.__stdin__.close()
+ sys.__stdout__.close()
+ cat = pexpect.spawn('cat')
+ cat.sendeof()
+ cat.expect(pexpect.EOF)
+
+ proc = Closed_stdin_stdout_proc()
+ proc.start()
+ proc.join()
+ assert proc.exitcode == 0
+
+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_filedescriptor.py
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/pexpect-4.2/tests/test_filedescriptor.py b/tools/bin/pythonSrc/pexpect-4.2/tests/test_filedescriptor.py
new file mode 100755
index 0000000..d9164e1
--- /dev/null
+++ b/tools/bin/pythonSrc/pexpect-4.2/tests/test_filedescriptor.py
@@ -0,0 +1,72 @@
+#!/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 <no...@noah.org>
+ 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 os
+
+class ExpectTestCase(PexpectTestCase.PexpectTestCase):
+ def setUp(self):
+ print(self.id())
+ PexpectTestCase.PexpectTestCase.setUp(self)
+
+ def test_fd (self):
+ fd = os.open ('TESTDATA.txt', os.O_RDONLY)
+ s = fdpexpect.fdspawn (fd)
+ s.expect(b'This is the end of test data:')
+ s.expect(pexpect.EOF)
+ self.assertEqual(s.before, b' END\n')
+
+ def test_maxread (self):
+ fd = os.open ('TESTDATA.txt', os.O_RDONLY)
+ s = fdpexpect.fdspawn (fd)
+ s.maxread = 100
+ s.expect('2')
+ s.expect ('This is the end of test data:')
+ s.expect (pexpect.EOF)
+ self.assertEqual(s.before, b' END\n')
+
+ def test_fd_isalive (self):
+ fd = os.open ('TESTDATA.txt', os.O_RDONLY)
+ s = fdpexpect.fdspawn(fd)
+ assert s.isalive()
+ os.close(fd)
+ assert not s.isalive(), "Should not be alive after close()"
+
+ def test_fd_isatty (self):
+ fd = os.open ('TESTDATA.txt', os.O_RDONLY)
+ s = fdpexpect.fdspawn (fd)
+ assert not s.isatty()
+ s.close()
+
+ def test_fileobj(self):
+ f = open('TESTDATA.txt', 'r')
+ s = fdpexpect.fdspawn(f) # Should get the fileno from the file handle
+ s.expect('2')
+ s.close()
+ assert not s.isalive()
+ s.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_interact.py
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/pexpect-4.2/tests/test_interact.py b/tools/bin/pythonSrc/pexpect-4.2/tests/test_interact.py
new file mode 100755
index 0000000..865353b
--- /dev/null
+++ b/tools/bin/pythonSrc/pexpect-4.2/tests/test_interact.py
@@ -0,0 +1,101 @@
+#!/usr/bin/env python
+# -*- coding: 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 <no...@noah.org>
+ 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 print_function
+from __future__ import unicode_literals
+
+import os
+import pexpect
+import unittest
+import sys
+from . import PexpectTestCase
+
+
+class InteractTestCase (PexpectTestCase.PexpectTestCase):
+ def setUp(self):
+ super(InteractTestCase, self).setUp()
+ self.env = env = os.environ.copy()
+
+ # Ensure 'import pexpect' works in subprocess interact*.py
+ if 'PYTHONPATH' in env:
+ env['PYTHONPATH'] = os.pathsep.join((self.project_dir,
+ env['PYTHONPATH']))
+ else:
+ env['PYTHONPATH'] = self.project_dir
+
+ self.interact_py = ('{sys.executable} interact.py'.format(sys=sys))
+
+ def test_interact_escape(self):
+ " Ensure `escape_character' value exits interactive mode. "
+ p = pexpect.spawn(self.interact_py, timeout=5, env=self.env)
+ p.expect('READY')
+ p.sendcontrol(']') # chr(29), the default `escape_character'
+ # value of pexpect.interact().
+ p.expect_exact('Escaped interact')
+ p.expect(pexpect.EOF)
+ assert not p.isalive()
+ assert p.exitstatus == 0
+
+ def test_interact_escape_None(self):
+ " Return only after Termination when `escape_character=None'. "
+ p = pexpect.spawn('{self.interact_py} --no-escape'.format(self=self),
+ timeout=5, env=self.env)
+ p.expect('READY')
+ p.sendcontrol(']')
+ p.expect('29<STOP>')
+ p.send('\x00')
+ if not os.environ.get('TRAVIS', None):
+ # on Travis-CI, we sometimes miss trailing stdout from the
+ # chain of child processes, not entirely sure why. So this
+ # is skipped on such systems.
+ p.expect('0<STOP>')
+ p.expect_exact('Escaped interact')
+ p.expect(pexpect.EOF)
+ assert not p.isalive()
+ assert p.exitstatus == 0
+
+ def test_interact_exit_unicode(self):
+ " Ensure subprocess receives utf8. "
+ p = pexpect.spawnu('{self.interact_py} --utf8'.format(self=self),
+ timeout=5, env=self.env)
+ p.expect('READY')
+ p.send('\u0251') # >>> map(ord, u'\u0251'.encode('utf8'))
+ p.expect('201<STOP>') # [201, 145]
+ p.expect('145<STOP>')
+ p.send('\u0392') # >>> map(ord, u'\u0392'.encode('utf8'))
+ p.expect('206<STOP>') # [206, 146]
+ p.expect('146<STOP>')
+ p.send('\x00')
+ if not os.environ.get('TRAVIS', None):
+ # on Travis-CI, we sometimes miss trailing stdout from the
+ # chain of child processes, not entirely sure why. So this
+ # is skipped on such systems.
+ p.expect('0<STOP>')
+ p.expect_exact('Escaped interact')
+ p.expect(pexpect.EOF)
+ assert not p.isalive()
+ assert p.exitstatus == 0
+
+if __name__ == '__main__':
+ unittest.main()
+
+suite = unittest.makeSuite(InteractTestCase, 'test')
+
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/a1a2f2c5/tools/bin/pythonSrc/pexpect-4.2/tests/test_isalive.py
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/pexpect-4.2/tests/test_isalive.py b/tools/bin/pythonSrc/pexpect-4.2/tests/test_isalive.py
new file mode 100755
index 0000000..cd79d09
--- /dev/null
+++ b/tools/bin/pythonSrc/pexpect-4.2/tests/test_isalive.py
@@ -0,0 +1,125 @@
+#!/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 <no...@noah.org>
+ 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 signal
+import sys
+import time
+from . import PexpectTestCase
+
+
+class IsAliveTestCase(PexpectTestCase.PexpectTestCase):
+ """Various tests for the running status of processes."""
+
+ def test_expect_wait(self):
+ """Ensure consistency in wait() and isalive()."""
+ p = pexpect.spawn('sleep 1')
+ assert p.isalive()
+ assert p.wait() == 0
+ assert not p.isalive()
+ # In previous versions of ptyprocess/pexpect, calling wait() a second
+ # time would raise an exception, but not since v4.0
+ assert p.wait() == 0
+
+ def test_expect_wait_after_termination(self):
+ """Ensure wait on a process terminated by kill -9."""
+ p = pexpect.spawn('sleep 3')
+ assert p.isalive()
+ p.kill(9)
+ time.sleep(1)
+
+ # when terminated, the exitstatus is None, but p.signalstatus
+ # and p.terminated reflects that the kill -9 nature.
+ assert p.wait() is None
+ assert p.signalstatus == 9
+ assert p.terminated == True
+ assert not p.isalive()
+
+ def test_signal_wait(self):
+ '''Test calling wait with a process terminated by a signal.'''
+ if not hasattr(signal, 'SIGALRM'):
+ return 'SKIP'
+ p = pexpect.spawn(sys.executable, ['alarm_die.py'])
+ p.wait()
+ assert p.exitstatus is None
+ self.assertEqual(p.signalstatus, signal.SIGALRM)
+
+ def test_expect_isalive_dead_after_normal_termination (self):
+ p = pexpect.spawn('ls', timeout=15)
+ p.expect(pexpect.EOF)
+ assert not p.isalive()
+
+ def test_expect_isalive_dead_after_SIGHUP(self):
+ p = pexpect.spawn('cat', timeout=5, ignore_sighup=False)
+ assert p.isalive()
+ force = False
+ if sys.platform.lower().startswith('sunos'):
+ # On Solaris (SmartOs), and only when executed from cron(1), SIGKILL
+ # is required to end the sub-process. This is done using force=True
+ force = True
+ assert p.terminate(force) == True
+ p.expect(pexpect.EOF)
+ assert not p.isalive()
+
+ def test_expect_isalive_dead_after_SIGINT(self):
+ p = pexpect.spawn('cat', timeout=5)
+ assert p.isalive()
+ force = False
+ if sys.platform.lower().startswith('sunos'):
+ # On Solaris (SmartOs), and only when executed from cron(1), SIGKILL
+ # is required to end the sub-process. This is done using force=True
+ force = True
+ assert p.terminate(force) == True
+ p.expect(pexpect.EOF)
+ assert not p.isalive()
+
+ def test_expect_isalive_dead_after_SIGKILL(self):
+ p = pexpect.spawn('cat', timeout=5)
+ assert p.isalive()
+ p.kill(9)
+ p.expect(pexpect.EOF)
+ assert not p.isalive()
+
+ def test_forced_terminate(self):
+ p = pexpect.spawn(sys.executable, ['needs_kill.py'])
+ p.expect('READY')
+ assert p.terminate(force=True) == True
+ p.expect(pexpect.EOF)
+ assert not p.isalive()
+
+### Some platforms allow this. Some reset status after call to waitpid.
+### probably not necessary, isalive() returns early when terminate is False.
+ def test_expect_isalive_consistent_multiple_calls (self):
+ '''This tests that multiple calls to isalive() return same value.
+ '''
+ p = pexpect.spawn('cat')
+ assert p.isalive()
+ assert p.isalive()
+ p.sendeof()
+ p.expect(pexpect.EOF)
+ assert not p.isalive()
+ assert not p.isalive()
+
+if __name__ == '__main__':
+ unittest.main()
+
+suite = unittest.makeSuite(IsAliveTestCase, 'test')
+
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/a1a2f2c5/tools/bin/pythonSrc/pexpect-4.2/tests/test_log.py
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/pexpect-4.2/tests/test_log.py b/tools/bin/pythonSrc/pexpect-4.2/tests/test_log.py
new file mode 100755
index 0000000..4ad2256
--- /dev/null
+++ b/tools/bin/pythonSrc/pexpect-4.2/tests/test_log.py
@@ -0,0 +1,108 @@
+#!/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 <no...@noah.org>
+ 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 os
+import tempfile
+from . import PexpectTestCase
+
+# the program cat(1) may display ^D\x08\x08 when \x04 (EOF, Ctrl-D) is sent
+_CAT_EOF = b'^D\x08\x08'
+
+class TestCaseLog(PexpectTestCase.PexpectTestCase):
+
+ def test_log (self):
+ log_message = 'This is a test.'
+ filename = tempfile.mktemp()
+ mylog = open(filename, 'wb')
+ p = pexpect.spawn('echo', [log_message])
+ p.logfile = mylog
+ p.expect(pexpect.EOF)
+ p.logfile = None
+ mylog.close()
+ with open(filename, 'rb') as f:
+ lf = f.read()
+ os.unlink(filename)
+ self.assertEqual(lf.rstrip(), log_message.encode('ascii'))
+
+ def test_log_logfile_read (self):
+ log_message = 'This is a test.'
+ filename = tempfile.mktemp()
+ mylog = open(filename, 'wb')
+ p = pexpect.spawn('cat')
+ p.logfile_read = mylog
+ p.sendline(log_message)
+ p.sendeof()
+ p.expect(pexpect.EOF)
+ p.logfile = None
+ mylog.close()
+ with open(filename, 'rb') as f:
+ lf = f.read()
+ os.unlink (filename)
+ lf = lf.replace(_CAT_EOF, b'')
+ self.assertEqual(lf, b'This is a test.\r\nThis is a test.\r\n')
+
+ def test_log_logfile_send (self):
+ log_message = b'This is a test.'
+ filename = tempfile.mktemp()
+ mylog = open (filename, 'wb')
+ p = pexpect.spawn('cat')
+ p.logfile_send = mylog
+ p.sendline(log_message)
+ p.sendeof()
+ p.expect (pexpect.EOF)
+ p.logfile = None
+ mylog.close()
+ with open(filename, 'rb') as f:
+ lf = f.read()
+ os.unlink(filename)
+ lf = lf.replace(b'\x04', b'')
+ self.assertEqual(lf.rstrip(), log_message)
+
+ def test_log_send_and_received (self):
+
+ '''The logfile should have the test message three time -- once for the
+ data we sent. Once for the data that cat echos back as characters are
+ typed. And once for the data that cat prints after we send a linefeed
+ (sent by sendline). '''
+
+ log_message = 'This is a test.'
+ filename = tempfile.mktemp()
+ mylog = open(filename, 'wb')
+ p = pexpect.spawn('cat')
+ p.logfile = mylog
+ p.sendline(log_message)
+ p.sendeof()
+ p.expect (pexpect.EOF)
+ p.logfile = None
+ mylog.close()
+ with open(filename, 'rb') as f:
+ lf = f.read()
+ os.unlink(filename)
+ lf = lf.replace(b'\x04', b'').replace(_CAT_EOF, b'')
+ self.assertEqual(lf,
+ b'This is a test.\nThis is a test.\r\nThis is a test.\r\n')
+
+if __name__ == '__main__':
+ unittest.main()
+
+suite = unittest.makeSuite(TestCaseLog,'test')
+
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/a1a2f2c5/tools/bin/pythonSrc/pexpect-4.2/tests/test_misc.py
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/pexpect-4.2/tests/test_misc.py b/tools/bin/pythonSrc/pexpect-4.2/tests/test_misc.py
new file mode 100755
index 0000000..1fb558c
--- /dev/null
+++ b/tools/bin/pythonSrc/pexpect-4.2/tests/test_misc.py
@@ -0,0 +1,346 @@
+#!/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 <no...@noah.org>
+ 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 unittest
+import sys
+import re
+import signal
+import time
+import tempfile
+import os
+
+import pexpect
+from . import PexpectTestCase
+
+# the program cat(1) may display ^D\x08\x08 when \x04 (EOF, Ctrl-D) is sent
+_CAT_EOF = b'^D\x08\x08'
+
+
+if (sys.version_info[0] >= 3):
+ def _u(s):
+ return s.decode('utf-8')
+else:
+ def _u(s):
+ return s
+
+
+class TestCaseMisc(PexpectTestCase.PexpectTestCase):
+
+ def test_isatty(self):
+ " Test isatty() is True after spawning process on most platforms. "
+ child = pexpect.spawn('cat')
+ if not child.isatty() and sys.platform.lower().startswith('sunos'):
+ if hasattr(unittest, 'SkipTest'):
+ raise unittest.SkipTest("Not supported on this platform.")
+ return 'skip'
+ assert child.isatty()
+
+ def test_read(self):
+ " Test spawn.read by calls of various size. "
+ child = pexpect.spawn('cat')
+ child.sendline("abc")
+ child.sendeof()
+ self.assertEqual(child.read(0), b'')
+ self.assertEqual(child.read(1), b'a')
+ self.assertEqual(child.read(1), b'b')
+ self.assertEqual(child.read(1), b'c')
+ self.assertEqual(child.read(2), b'\r\n')
+ remaining = child.read().replace(_CAT_EOF, b'')
+ self.assertEqual(remaining, b'abc\r\n')
+
+ def test_readline_bin_echo(self):
+ " Test spawn('echo'). "
+ # given,
+ child = pexpect.spawn('echo', ['alpha', 'beta'])
+
+ # exercise,
+ assert child.readline() == b'alpha beta' + child.crlf
+
+ def test_readline(self):
+ " Test spawn.readline(). "
+ # when argument 0 is sent, nothing is returned.
+ # Otherwise the argument value is meaningless.
+ child = pexpect.spawn('cat', echo=False)
+ child.sendline("alpha")
+ child.sendline("beta")
+ child.sendline("gamma")
+ child.sendline("delta")
+ child.sendeof()
+ assert child.readline(0) == b''
+ assert child.readline().rstrip() == b'alpha'
+ assert child.readline(1).rstrip() == b'beta'
+ assert child.readline(2).rstrip() == b'gamma'
+ assert child.readline().rstrip() == b'delta'
+ child.expect(pexpect.EOF)
+ assert not child.isalive()
+ assert child.exitstatus == 0
+
+ def test_iter(self):
+ " iterating over lines of spawn.__iter__(). "
+ child = pexpect.spawn('cat', echo=False)
+ child.sendline("abc")
+ child.sendline("123")
+ child.sendeof()
+ # Don't use ''.join() because we want to test __iter__().
+ page = b''
+ for line in child:
+ page += line
+ page = page.replace(_CAT_EOF, b'')
+ assert page == b'abc\r\n123\r\n'
+
+ def test_readlines(self):
+ " reading all lines of spawn.readlines(). "
+ child = pexpect.spawn('cat', echo=False)
+ child.sendline("abc")
+ child.sendline("123")
+ child.sendeof()
+ page = b''.join(child.readlines()).replace(_CAT_EOF, b'')
+ assert page == b'abc\r\n123\r\n'
+ child.expect(pexpect.EOF)
+ assert not child.isalive()
+ assert child.exitstatus == 0
+
+ def test_write(self):
+ " write a character and return it in return. "
+ child = pexpect.spawn('cat', echo=False)
+ child.write('a')
+ child.write('\r')
+ self.assertEqual(child.readline(), b'a\r\n')
+
+ def test_writelines(self):
+ " spawn.writelines() "
+ child = pexpect.spawn('cat')
+ # notice that much like file.writelines, we do not delimit by newline
+ # -- it is equivalent to calling write(''.join([args,]))
+ child.writelines(['abc', '123', 'xyz', '\r'])
+ child.sendeof()
+ line = child.readline()
+ assert line == b'abc123xyz\r\n'
+
+ def test_eof(self):
+ " call to expect() after EOF is received raises pexpect.EOF "
+ child = pexpect.spawn('cat')
+ child.sendeof()
+ with self.assertRaises(pexpect.EOF):
+ child.expect('the unexpected')
+
+ def test_with(self):
+ "spawn can be used as a context manager"
+ with pexpect.spawn(sys.executable + ' echo_w_prompt.py') as p:
+ p.expect('<in >')
+ p.sendline(b'alpha')
+ p.expect(b'<out>alpha')
+ assert p.isalive()
+
+ assert not p.isalive()
+
+ def test_terminate(self):
+ " test force terminate always succeeds (SIGKILL). "
+ child = pexpect.spawn('cat')
+ child.terminate(force=1)
+ assert child.terminated
+
+ def test_sighup(self):
+ " validate argument `ignore_sighup=True` and `ignore_sighup=False`. "
+ getch = sys.executable + ' getch.py'
+ child = pexpect.spawn(getch, ignore_sighup=True)
+ child.expect('READY')
+ child.kill(signal.SIGHUP)
+ for _ in range(10):
+ if not child.isalive():
+ self.fail('Child process should not have exited.')
+ time.sleep(0.1)
+
+ child = pexpect.spawn(getch, ignore_sighup=False)
+ child.expect('READY')
+ child.kill(signal.SIGHUP)
+ for _ in range(10):
+ if not child.isalive():
+ break
+ time.sleep(0.1)
+ else:
+ self.fail('Child process should have exited.')
+
+ def test_bad_child_pid(self):
+ " assert bad condition error in isalive(). "
+ expect_errmsg = re.escape("isalive() encountered condition where ")
+ child = pexpect.spawn('cat')
+ child.terminate(force=1)
+ # Force an invalid state to test isalive
+ child.ptyproc.terminated = 0
+ try:
+ with self.assertRaisesRegexp(pexpect.ExceptionPexpect,
+ ".*" + expect_errmsg):
+ child.isalive()
+ finally:
+ # Force valid state for child for __del__
+ child.terminated = 1
+
+ def test_bad_arguments_suggest_fdpsawn(self):
+ " assert custom exception for spawn(int). "
+ expect_errmsg = "maybe you want to use fdpexpect.fdspawn"
+ with self.assertRaisesRegexp(pexpect.ExceptionPexpect,
+ ".*" + expect_errmsg):
+ pexpect.spawn(1)
+
+ def test_bad_arguments_second_arg_is_list(self):
+ " Second argument to spawn, if used, must be only a list."
+ with self.assertRaises(TypeError):
+ pexpect.spawn('ls', '-la')
+
+ with self.assertRaises(TypeError):
+ # not even a tuple,
+ pexpect.spawn('ls', ('-la',))
+
+ def test_read_after_close_raises_value_error(self):
+ " Calling read_nonblocking after close raises ValueError. "
+ # as read_nonblocking underlies all other calls to read,
+ # ValueError should be thrown for all forms of read.
+ with self.assertRaises(ValueError):
+ p = pexpect.spawn('cat')
+ p.close()
+ p.read_nonblocking()
+
+ with self.assertRaises(ValueError):
+ p = pexpect.spawn('cat')
+ p.close()
+ p.read()
+
+ with self.assertRaises(ValueError):
+ p = pexpect.spawn('cat')
+ p.close()
+ p.readline()
+
+ with self.assertRaises(ValueError):
+ p = pexpect.spawn('cat')
+ p.close()
+ p.readlines()
+
+ def test_isalive(self):
+ " check isalive() before and after EOF. (True, False) "
+ child = pexpect.spawn('cat')
+ assert child.isalive() is True
+ child.sendeof()
+ child.expect(pexpect.EOF)
+ assert child.isalive() is False
+
+ def test_bad_type_in_expect(self):
+ " expect() does not accept dictionary arguments. "
+ child = pexpect.spawn('cat')
+ with self.assertRaises(TypeError):
+ child.expect({})
+
+ def test_cwd(self):
+ " check keyword argument `cwd=' of pexpect.run() "
+ tmp_dir = os.path.realpath(tempfile.gettempdir())
+ default = pexpect.run('pwd')
+ pwd_tmp = pexpect.run('pwd', cwd=tmp_dir).rstrip()
+ assert default != pwd_tmp
+ assert tmp_dir == _u(pwd_tmp)
+
+ def _test_searcher_as(self, searcher, plus=None):
+ # given,
+ given_words = ['alpha', 'beta', 'gamma', 'delta', ]
+ given_search = given_words
+ if searcher == pexpect.searcher_re:
+ given_search = [re.compile(word) for word in given_words]
+ if plus is not None:
+ given_search = given_search + [plus]
+ search_string = searcher(given_search)
+ basic_fmt = '\n {0}: {1}'
+ fmt = basic_fmt
+ if searcher is pexpect.searcher_re:
+ fmt = '\n {0}: re.compile({1})'
+ expected_output = '{0}:'.format(searcher.__name__)
+ idx = 0
+ for word in given_words:
+ expected_output += fmt.format(idx, '"{0}"'.format(word))
+ idx += 1
+ if plus is not None:
+ if plus == pexpect.EOF:
+ expected_output += basic_fmt.format(idx, 'EOF')
+ elif plus == pexpect.TIMEOUT:
+ expected_output += basic_fmt.format(idx, 'TIMEOUT')
+
+ # exercise,
+ assert search_string.__str__() == expected_output
+
+ def test_searcher_as_string(self):
+ " check searcher_string(..).__str__() "
+ self._test_searcher_as(pexpect.searcher_string)
+
+ def test_searcher_as_string_with_EOF(self):
+ " check searcher_string(..).__str__() that includes EOF "
+ self._test_searcher_as(pexpect.searcher_string, plus=pexpect.EOF)
+
+ def test_searcher_as_string_with_TIMEOUT(self):
+ " check searcher_string(..).__str__() that includes TIMEOUT "
+ self._test_searcher_as(pexpect.searcher_string, plus=pexpect.TIMEOUT)
+
+ def test_searcher_re_as_string(self):
+ " check searcher_re(..).__str__() "
+ self._test_searcher_as(pexpect.searcher_re)
+
+ def test_searcher_re_as_string_with_EOF(self):
+ " check searcher_re(..).__str__() that includes EOF "
+ self._test_searcher_as(pexpect.searcher_re, plus=pexpect.EOF)
+
+ def test_searcher_re_as_string_with_TIMEOUT(self):
+ " check searcher_re(..).__str__() that includes TIMEOUT "
+ self._test_searcher_as(pexpect.searcher_re, plus=pexpect.TIMEOUT)
+
+ def test_nonnative_pty_fork(self):
+ " test forced self.__fork_pty() and __pty_make_controlling_tty "
+ # given,
+ class spawn_ourptyfork(pexpect.spawn):
+ def _spawn(self, command, args=[], preexec_fn=None,
+ dimensions=None):
+ self.use_native_pty_fork = False
+ pexpect.spawn._spawn(self, command, args, preexec_fn,
+ dimensions)
+
+ # exercise,
+ p = spawn_ourptyfork('cat', echo=False)
+ # verify,
+ p.sendline('abc')
+ p.expect('abc')
+ p.sendeof()
+ p.expect(pexpect.EOF)
+ assert not p.isalive()
+
+ def test_exception_tb(self):
+ " test get_trace() filters away pexpect/__init__.py calls. "
+ p = pexpect.spawn('sleep 1')
+ try:
+ p.expect('BLAH')
+ except pexpect.ExceptionPexpect as e:
+ # get_trace should filter out frames in pexpect's own code
+ tb = e.get_trace()
+ # exercise,
+ assert 'raise ' not in tb
+ assert 'pexpect/__init__.py' not in tb
+ else:
+ assert False, "Should have raised an exception."
+
+if __name__ == '__main__':
+ unittest.main()
+
+suite = unittest.makeSuite(TestCaseMisc,'test')
+
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/a1a2f2c5/tools/bin/pythonSrc/pexpect-4.2/tests/test_missing_command.py
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/pexpect-4.2/tests/test_missing_command.py b/tools/bin/pythonSrc/pexpect-4.2/tests/test_missing_command.py
new file mode 100755
index 0000000..92e4733
--- /dev/null
+++ b/tools/bin/pythonSrc/pexpect-4.2/tests/test_missing_command.py
@@ -0,0 +1,38 @@
+#!/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 <no...@noah.org>
+ 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 MissingCommandTestCase (PexpectTestCase.PexpectTestCase):
+ def testMissingCommand(self):
+ try:
+ i = pexpect.spawn ('ZXQYQZX')
+ except Exception:
+ pass
+ else:
+ self.fail('Expected an Exception.')
+
+if __name__ == '__main__':
+ unittest.main()
+
+suite = unittest.makeSuite(MissingCommandTestCase,'test')
+
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/a1a2f2c5/tools/bin/pythonSrc/pexpect-4.2/tests/test_performance.py
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/pexpect-4.2/tests/test_performance.py b/tools/bin/pythonSrc/pexpect-4.2/tests/test_performance.py
new file mode 100755
index 0000000..7be0cf6
--- /dev/null
+++ b/tools/bin/pythonSrc/pexpect-4.2/tests/test_performance.py
@@ -0,0 +1,107 @@
+#!/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 <no...@noah.org>
+ 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 print_function
+
+import unittest, time, sys
+import platform
+import pexpect
+from . import PexpectTestCase
+
+# This isn't exactly a unit test, but it fits in nicely with the rest of the tests.
+
+class PerformanceTestCase (PexpectTestCase.PexpectTestCase):
+
+ '''Testing the performance of expect, with emphasis on wading through long
+ inputs. '''
+
+ if sys.version_info[0] >= 3:
+ @staticmethod
+ def _iter_n(n):
+ s = 'for n in range(1, %d+1): print(n)' % n
+ return s.encode('ascii')
+
+ else:
+ @staticmethod
+ def _iter_n(n):
+ return 'for n in range(1, %d+1): print(n)' % n
+
+ def plain_range(self, n):
+ e = pexpect.spawn('python', timeout=100)
+ self.assertEqual(e.expect(b'>>>'), 0)
+ e.sendline(self._iter_n(n))
+ self.assertEqual(e.expect(br'\.{3}'), 0)
+ e.sendline(b'')
+ self.assertEqual(e.expect([b'inquisition', '%d' % n]), 1)
+
+ def window_range(self, n):
+ e = pexpect.spawn('python', timeout=100)
+ self.assertEqual(e.expect(b'>>>'), 0)
+ e.sendline(self._iter_n(n))
+ self.assertEqual(e.expect(r'\.{3}'), 0)
+ e.sendline(b'')
+ self.assertEqual(e.expect([b'inquisition', '%d' % n], searchwindowsize=20), 1)
+
+ def exact_range(self, n):
+ e = pexpect.spawn('python', timeout=100)
+ self.assertEqual(e.expect_exact([b'>>>']), 0)
+ e.sendline(self._iter_n(n))
+ self.assertEqual(e.expect_exact([b'...']), 0)
+ e.sendline(b'')
+ self.assertEqual(e.expect_exact([b'inquisition', '%d' % n],timeout=520), 1)
+
+ def ewin_range(self, n):
+ e = pexpect.spawn('python', timeout=100)
+ self.assertEqual(e.expect_exact([b'>>>']), 0)
+ e.sendline(self._iter_n(n))
+ self.assertEqual(e.expect_exact([b'...']), 0)
+ e.sendline(b'')
+ self.assertEqual(e.expect_exact([b'inquisition', '%d' % n], searchwindowsize=20), 1)
+
+ def faster_range(self, n):
+ e = pexpect.spawn('python', timeout=100)
+ self.assertEqual(e.expect(b'>>>'), 0)
+ e.sendline(('list(range(1, %d+1))' % n).encode('ascii'))
+ self.assertEqual(e.expect([b'inquisition', '%d' % n]), 1)
+
+ def test_100000(self):
+ if platform.python_implementation() == 'PyPy':
+ raise unittest.SkipTest("This test fails on PyPy because of REPL differences")
+ print()
+ start_time = time.time()
+ self.plain_range (100000)
+ print("100000 calls to plain_range:", (time.time() - start_time))
+ start_time = time.time()
+ self.window_range(100000)
+ print("100000 calls to window_range:", (time.time() - start_time))
+ start_time = time.time()
+ self.exact_range (100000)
+ print("100000 calls to exact_range:", (time.time() - start_time))
+ start_time = time.time()
+ self.ewin_range (100000)
+ print("100000 calls to ewin_range:", (time.time() - start_time))
+ start_time = time.time()
+ self.faster_range(100000)
+ print("100000 calls to faster_range:", (time.time() - start_time))
+
+if __name__ == "__main__":
+ unittest.main()
+
+suite = unittest.makeSuite(PerformanceTestCase,'test')
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/a1a2f2c5/tools/bin/pythonSrc/pexpect-4.2/tests/test_pickling.py
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/pexpect-4.2/tests/test_pickling.py b/tools/bin/pythonSrc/pexpect-4.2/tests/test_pickling.py
new file mode 100644
index 0000000..6538677
--- /dev/null
+++ b/tools/bin/pythonSrc/pexpect-4.2/tests/test_pickling.py
@@ -0,0 +1,14 @@
+#!/usr/bin/env python
+import pickle
+import unittest
+
+from pexpect import ExceptionPexpect
+
+class PickleTest(unittest.TestCase):
+ def test_picking(self):
+ e = ExceptionPexpect('Oh noes!')
+ clone = pickle.loads(pickle.dumps(e))
+ self.assertEqual(e.value, clone.value)
+
+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_popen_spawn.py
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/pexpect-4.2/tests/test_popen_spawn.py b/tools/bin/pythonSrc/pexpect-4.2/tests/test_popen_spawn.py
new file mode 100644
index 0000000..98046ed
--- /dev/null
+++ b/tools/bin/pythonSrc/pexpect-4.2/tests/test_popen_spawn.py
@@ -0,0 +1,131 @@
+#!/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 <no...@noah.org>
+ 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 unittest
+import subprocess
+
+
+import pexpect
+from pexpect.popen_spawn import PopenSpawn
+from . import PexpectTestCase
+
+
+class ExpectTestCase (PexpectTestCase.PexpectTestCase):
+
+ def test_expect_basic(self):
+ p = PopenSpawn('cat', timeout=5)
+ p.sendline(b'Hello')
+ p.sendline(b'there')
+ p.sendline(b'Mr. Python')
+ p.expect(b'Hello')
+ p.expect(b'there')
+ p.expect(b'Mr. Python')
+ p.sendeof()
+ p.expect(pexpect.EOF)
+
+ def test_expect_exact_basic(self):
+ p = PopenSpawn('cat', timeout=5)
+ p.sendline(b'Hello')
+ p.sendline(b'there')
+ p.sendline(b'Mr. Python')
+ p.expect_exact(b'Hello')
+ p.expect_exact(b'there')
+ p.expect_exact(b'Mr. Python')
+ p.sendeof()
+ p.expect_exact(pexpect.EOF)
+
+ def test_expect(self):
+ the_old_way = subprocess.Popen(args=['ls', '-l', '/bin'],
+ stdout=subprocess.PIPE).communicate()[0].rstrip()
+ p = PopenSpawn('ls -l /bin')
+ the_new_way = b''
+ while 1:
+ i = p.expect([b'\n', pexpect.EOF])
+ the_new_way = the_new_way + p.before
+ if i == 1:
+ break
+ the_new_way += b'\n'
+ the_new_way = the_new_way.rstrip()
+ assert the_old_way == the_new_way, len(the_old_way) - len(the_new_way)
+
+ def test_expect_exact(self):
+ the_old_way = subprocess.Popen(args=['ls', '-l', '/bin'],
+ stdout=subprocess.PIPE).communicate()[0].rstrip()
+ p = PopenSpawn('ls -l /bin')
+ the_new_way = b''
+ while 1:
+ i = p.expect_exact([b'\n', pexpect.EOF])
+ the_new_way = the_new_way + p.before
+ if i == 1:
+ break
+ the_new_way += b'\n'
+ the_new_way = the_new_way.rstrip()
+
+ assert the_old_way == the_new_way, len(the_old_way) - len(the_new_way)
+ p = PopenSpawn('echo hello.?world')
+ i = p.expect_exact(b'.?')
+ self.assertEqual(p.before, b'hello')
+ self.assertEqual(p.after, b'.?')
+
+ def test_expect_eof(self):
+ the_old_way = subprocess.Popen(args=['ls', '-l', '/bin'],
+ stdout=subprocess.PIPE).communicate()[0].rstrip()
+ p = PopenSpawn('ls -l /bin')
+ # This basically tells it to read everything. Same as pexpect.run()
+ # function.
+ p.expect(pexpect.EOF)
+ the_new_way = p.before.rstrip()
+ assert the_old_way == the_new_way, len(the_old_way) - len(the_new_way)
+
+ def test_expect_timeout(self):
+ p = PopenSpawn('cat', timeout=5)
+ p.expect(pexpect.TIMEOUT) # This tells it to wait for timeout.
+ self.assertEqual(p.after, pexpect.TIMEOUT)
+
+ def test_unexpected_eof(self):
+ p = PopenSpawn('ls -l /bin')
+ try:
+ p.expect('_Z_XY_XZ') # Probably never see this in ls output.
+ except pexpect.EOF:
+ pass
+ else:
+ self.fail('Expected an EOF exception.')
+
+ def test_bad_arg(self):
+ p = PopenSpawn('cat')
+ with self.assertRaisesRegexp(TypeError, '.*must be one of'):
+ p.expect(1)
+ with self.assertRaisesRegexp(TypeError, '.*must be one of'):
+ p.expect([1, b'2'])
+ with self.assertRaisesRegexp(TypeError, '.*must be one of'):
+ p.expect_exact(1)
+ with self.assertRaisesRegexp(TypeError, '.*must be one of'):
+ p.expect_exact([1, b'2'])
+
+ def test_timeout_none(self):
+ p = PopenSpawn('echo abcdef', timeout=None)
+ p.expect('abc')
+ p.expect_exact('def')
+ p.expect(pexpect.EOF)
+
+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_pxssh.py
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/pexpect-4.2/tests/test_pxssh.py b/tools/bin/pythonSrc/pexpect-4.2/tests/test_pxssh.py
new file mode 100644
index 0000000..0ff092c
--- /dev/null
+++ b/tools/bin/pythonSrc/pexpect-4.2/tests/test_pxssh.py
@@ -0,0 +1,53 @@
+#!/usr/bin/env python
+import os
+
+import unittest
+
+from pexpect import pxssh
+
+class SSHTestBase(unittest.TestCase):
+ def setUp(self):
+ self.orig_path = os.environ.get('PATH')
+ fakessh_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), 'fakessh'))
+ os.environ['PATH'] = fakessh_dir + \
+ ((os.pathsep + self.orig_path) if self.orig_path else '')
+
+ def tearDown(self):
+ if self.orig_path:
+ os.environ['PATH'] = self.orig_path
+ else:
+ del os.environ['PATH']
+
+class PxsshTestCase(SSHTestBase):
+ def test_fake_ssh(self):
+ ssh = pxssh.pxssh()
+ #ssh.logfile_read = sys.stdout # DEBUG
+ ssh.login('server', 'me', password='s3cret')
+ ssh.sendline('ping')
+ ssh.expect('pong', timeout=10)
+ assert ssh.prompt(timeout=10)
+ ssh.logout()
+
+ def test_wrong_pw(self):
+ ssh = pxssh.pxssh()
+ try:
+ ssh.login('server', 'me', password='wr0ng')
+ except pxssh.ExceptionPxssh:
+ pass
+ else:
+ assert False, 'Password should have been refused'
+
+ def test_failed_set_unique_prompt(self):
+ ssh = pxssh.pxssh()
+ ssh.set_unique_prompt = lambda: False
+ try:
+ ssh.login('server', 'me', password='s3cret',
+ auto_prompt_reset=True)
+ except pxssh.ExceptionPxssh:
+ pass
+ else:
+ assert False, 'should have raised exception, pxssh.ExceptionPxssh'
+
+
+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_replwrap.py
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/pexpect-4.2/tests/test_replwrap.py b/tools/bin/pythonSrc/pexpect-4.2/tests/test_replwrap.py
new file mode 100644
index 0000000..26ff53c
--- /dev/null
+++ b/tools/bin/pythonSrc/pexpect-4.2/tests/test_replwrap.py
@@ -0,0 +1,105 @@
+import platform
+import unittest
+import re
+import os
+
+import pexpect
+from pexpect import replwrap
+
+skip_pypy = "This test fails on PyPy because of REPL differences"
+
+
+class REPLWrapTestCase(unittest.TestCase):
+ def setUp(self):
+ super(REPLWrapTestCase, self).setUp()
+ self.save_ps1 = os.getenv('PS1', r'\$')
+ self.save_ps2 = os.getenv('PS2', '>')
+ os.putenv('PS1', r'\$')
+ os.putenv('PS2', '>')
+
+ def tearDown(self):
+ super(REPLWrapTestCase, self).tearDown()
+ os.putenv('PS1', self.save_ps1)
+ os.putenv('PS2', self.save_ps2)
+
+ def test_bash(self):
+ bash = replwrap.bash()
+ res = bash.run_command("time")
+ assert 'real' in res, res
+
+ def test_pager_as_cat(self):
+ " PAGER is set to cat, to prevent timeout in ``man sleep``. "
+ bash = replwrap.bash()
+ res = bash.run_command('man sleep', timeout=5)
+ assert 'SLEEP' in res, res
+
+ def test_long_running_multiline(self):
+ " ensure the default timeout is used for multi-line commands. "
+ bash = replwrap.bash()
+ res = bash.run_command("echo begin\r\nsleep 2\r\necho done")
+ self.assertEqual(res.strip().splitlines(), ['begin', 'done'])
+
+ def test_long_running_continuation(self):
+ " also ensure timeout when used within continuation prompts. "
+ bash = replwrap.bash()
+ # The two extra '\\' in the following expression force a continuation
+ # prompt:
+ # $ echo begin\
+ # + ;
+ # $ sleep 2
+ # $ echo done
+ res = bash.run_command("echo begin\\\n;sleep 2\r\necho done")
+ self.assertEqual(res.strip().splitlines(), ['begin', 'done'])
+
+ def test_multiline(self):
+ bash = replwrap.bash()
+ res = bash.run_command("echo '1 2\n3 4'")
+ self.assertEqual(res.strip().splitlines(), ['1 2', '3 4'])
+
+ # Should raise ValueError if input is incomplete
+ try:
+ bash.run_command("echo '5 6")
+ except ValueError:
+ pass
+ else:
+ assert False, "Didn't raise ValueError for incomplete input"
+
+ # Check that the REPL was reset (SIGINT) after the incomplete input
+ res = bash.run_command("echo '1 2\n3 4'")
+ self.assertEqual(res.strip().splitlines(), ['1 2', '3 4'])
+
+ def test_existing_spawn(self):
+ child = pexpect.spawn("bash", timeout=5, echo=False, encoding='utf-8')
+ repl = replwrap.REPLWrapper(child, re.compile('[$#]'),
+ "PS1='{0}' PS2='{1}' "
+ "PROMPT_COMMAND=''")
+
+ res = repl.run_command("echo $HOME")
+ assert res.startswith('/'), res
+
+ def test_python(self):
+ if platform.python_implementation() == 'PyPy':
+ raise unittest.SkipTest(skip_pypy)
+
+ p = replwrap.python()
+ res = p.run_command('4+7')
+ assert res.strip() == '11'
+
+ res = p.run_command('for a in range(3): print(a)\n')
+ assert res.strip().splitlines() == ['0', '1', '2']
+
+ def test_no_change_prompt(self):
+ if platform.python_implementation() == 'PyPy':
+ raise unittest.SkipTest(skip_pypy)
+
+ child = pexpect.spawn('python', echo=False, timeout=5, encoding='utf-8')
+ # prompt_change=None should mean no prompt change
+ py = replwrap.REPLWrapper(child, u">>> ", prompt_change=None,
+ continuation_prompt=u"... ")
+ assert py.prompt == ">>> "
+
+ res = py.run_command("for a in range(3): print(a)\n")
+ assert res.strip().splitlines() == ['0', '1', '2']
+
+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_repr.py
----------------------------------------------------------------------
diff --git a/tools/bin/pythonSrc/pexpect-4.2/tests/test_repr.py b/tools/bin/pythonSrc/pexpect-4.2/tests/test_repr.py
new file mode 100644
index 0000000..ac33716
--- /dev/null
+++ b/tools/bin/pythonSrc/pexpect-4.2/tests/test_repr.py
@@ -0,0 +1,37 @@
+""" Test __str__ methods. """
+import pexpect
+
+from . import PexpectTestCase
+
+
+class TestCaseMisc(PexpectTestCase.PexpectTestCase):
+
+ def test_str_spawnu(self):
+ """ Exercise spawnu.__str__() """
+ # given,
+ p = pexpect.spawnu('cat')
+ # exercise,
+ value = str(p)
+ # verify
+ assert isinstance(value, str)
+
+ def test_str_spawn(self):
+ """ Exercise spawn.__str__() """
+ # given,
+ p = pexpect.spawn('cat')
+ # exercise,
+ value = str(p)
+ # verify
+ assert isinstance(value, str)
+
+ def test_str_before_spawn(self):
+ """ Exercise derived spawn.__str__() """
+ # given,
+ child = pexpect.spawn(None, None)
+ child.read_nonblocking = lambda size, timeout: b''
+ try:
+ child.expect('alpha', timeout=0.1)
+ except pexpect.TIMEOUT as e:
+ str(e) # Smoketest
+ else:
+ assert False, 'TIMEOUT exception expected. No exception raised.'